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: [mg89666] Re: [mg89641] Problems with FindRoot and recursive functions
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 17 Jun 2008 00:37:36 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200806161039.GAA09440@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

You will see what is wrong if you just evaluate your function x1 a 
couple of times, beginning with the initial guess you used in the FindRoot.

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

    x1[0.5]
{0., 1.5}
   (* so far, as expected *)

    x1[%]
If[{0., 1.5} < 0, {{0., 1.5}, 1}, 0.5+ x1[{0., 1.5} - 1]]
   (* NOT as expected! *)

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
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Making Transparent Legend Backgrounds
  • Next by Date: Power Tower and Carmichael Lambda Function
  • Previous by thread: Problems with FindRoot and recursive functions
  • Next by thread: Re: Problems with FindRoot and recursive functions