Re: Problems with FindRoot and recursive functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg89694] Re: [mg89641] Problems with FindRoot and recursive functions*From*: "Daniel Kuang Chen Liu" <dkliu1 at gmail.com>*Date*: Wed, 18 Jun 2008 04:24:52 -0400 (EDT)*References*: <200806161039.GAA09440@smc.vnet.net>

I have weird function. It doesn't work the way you think it does. x1[0.5] = 0.5 + x1[-0.5] = 0.5 + {-0.5,1} = {0,1.5} It only takes a scalar has input, and is only called recursively with scalar input t-1. The function works when you plot it. Additionally, my own roots finding function based on the secant method works fine ... NSecant[f_, int_, k_: 0, plevel_: defplevel] := Module[{old = int[[1]], est, new = int[[2]]}, i = k; i++; est = old - (new - old)/(f[new] - f[old]) f[old]; If[Abs[N[f[est], 100]] < plevel, {est, N[Abs[est - new]], N[f[est], 5], i, plevel}, NSecant[f, {new, est}, i, plevel] ] ]; In[183]:= NSecant[x1[#][[1]] &, {0.4, 0.6}, 0, 10^-10] Out[183]= {0.5, 0.1, 0., 1, 1/10000000000} So I really can't see why FindRoot should have any problem with it. Daniel On Tue, Jun 17, 2008 at 1:39 AM, Murray Eisenberg <murray at math.umass.edu> wrote: > 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 >

**References**:**Problems with FindRoot and recursive functions***From:*"Daniel Kuang Chen Liu" <dkliu1@student.monash.edu.au>