Re: Help on FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg5798] Re: [mg5786] Help on FindRoot
- From: seanross at worldnet.att.net
- Date: Wed, 22 Jan 1997 00:44:09 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Hossein Kazemi wrote:
>
> I have the following lines:
>
> h[0]=1;
> x[t_]:=2^h[t] - 3*h[t-1];
> Table[h[t]=h[t]/.FindRoot[x[t]==t,{h[t],2}],{t,1,5}]
>
> As you can see, I am trying to solve for different values of h[t], which
> is recursively depends on h[t-1].
>
> MMA (3.0) gives a bunch of errors such as
> Unset:: norep: Assignment on h for h[1] not found.
> and so on.
>
> However, it also gives the correct answers at the end.
>
> What is going on? Am I doing something wrong?
>
> **********************************************************
> Hossein Kazemi
> University of Massachusetts
Your function definition is not truly recursive. You define h[0], so
when I call x[1], I need to know h[1] and h[0]. I would try re-defining
the problem so that you used something like:
h[t]=z/.FindRoot[2^z -3 h[t-1]==t,{z,2}]. I have tested this code, but
it seems like you are asking for a result before calculating it. I
would try and avoid doing root searches on the symbol h[t].