Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Problems with FindRoot and recursive functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89672] Re: Problems with FindRoot and recursive functions
  • From: dh <dh at metrohm.ch>
  • Date: Tue, 17 Jun 2008 00:38:44 -0400 (EDT)
  • References: <g35g0m$9bv$1@smc.vnet.net>


Hi Daniel,

this is a very common mistake. For speed, Mathematica tries first to 

simpify your expression symbolically. Therefore, you should take care 

not to evaluate your function  with a symbolic argument. This can be 

done e.g. by:

x1[t_?NumericalQ]:=...

hope this helps, Daniel



Daniel Kuang Chen Liu wrote:

> Hello,

> 

> I have a recursive function of the form

> 

>>> x1[t_] := If[t < 0, {t, 1}, 0.5 + x1[t - 1]]

> 

> which returns a list of length 2, and the first element has a root at t=0.5

>>> In[3]:= x1[0.5]

>>> Out[3]= {0., 1.5}

> 

> I want to use FindRoot to determine t0 such that x1[t0][[1]] == 0, so I use

> the following code

> 

>>> FindRoot[x1[t][[1]] == 0, {t, 0.5}]

> 

> to which Mathematica complains

> 

> During evaluation of In[6]:= FindRoot::nlnum: The function value

> {False} is not a list of numbers with dimensions {1} at {t} = {0.5}.

> 

> It would much appreciated if someone could tell me what is wrong with the

> code.

> 

> Daniel Liu

> 

> 





-- 



Daniel Huber

Metrohm Ltd.

Oberdorfstr. 68

CH-9100 Herisau

Tel. +41 71 353 8585, Fax +41 71 353 8907

E-Mail:<mailto:dh at metrohm.com>

Internet:<http://www.metrohm.com>




  • Prev by Date: Re: citing mathematica
  • Next by Date: Re: 6.0.3
  • Previous by thread: Re: Problems with FindRoot and recursive functions
  • Next by thread: Re: Problems with FindRoot and recursive functions