MathGroup Archive 2008

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

Search the Archive

Re: FindROot and substitutions


On Jun 21, 11:31 am, Aaron Fude <aaronf... at gmail.com> wrote:
> Hi,
>
> I have found a workaround for this problem, but I would like to
> understand how Mathematica wants you to think so I'm asking the
> question anyway.
>
> Why does "bad" not work, while "good" works?
>
> g := x z;
> bad[z_] := FindRoot[ g == 5, {x, -10, 10 }];
> bad[5]
> good[k_] := FindRoot[ g == 5 /. z -> k, {x, -10, 10 }];
> good[6]
>
> Thanks!
>
> Aaron

If you execute

On[]
bad[5]
Off[]

you can solve the arcane.
You get a lengthy output, but from the very first lines you can
clearly see that g gets replaced by x z, but z never gets replaced by
5.
So FindRoot starts looking for solutions of x z == 5, which is a
symbolic equation (z is a symbol) and cannot be "Findroot-ed".

This is a working code:

gg[z_] := x z
notsobad[z_] := FindRoot[gg[z] == 5, {x, -10, 10}]

and now...

notsobad[5]

works as desired
In other words: you should make explicit in g (or gg)  the z
dependence.


  • Prev by Date: Re: FindROot and substitutions
  • Next by Date: Re: FindROot and substitutions
  • Previous by thread: Re: FindROot and substitutions
  • Next by thread: Re: FindROot and substitutions