Re: FindROot and substitutions
- To: mathgroup at smc.vnet.net
- Subject: [mg89831] Re: FindROot and substitutions
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Sun, 22 Jun 2008 03:22:23 -0400 (EDT)
- References: <g3ihp3$fd5$1@smc.vnet.net>
Aaron Fude 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;
----------^
You used a semicolon here, so I suppose that you do not understand the
difference between SetDelayed and Set. Please read about that:
tutorial/ImmediateAndDelayedDefinitions
Later also read these:
tutorial/TheStandardEvaluationProcedure
tutorial/Evaluation
> bad[z_] := FindRoot[ g == 5, {x, -10, 10 }];
> bad[5]
There is not "z" in "FindRoot[ g == 5, {x, -10, 10 }]" so bad[5]
evaluates to FindRoot[ g == 5, {x, -10, 10 }] in the first step. Use
the function Trace to see this.
> good[k_] := FindRoot[ g == 5 /. z -> k, {x, -10, 10 }];
> good[6]
good[6] evaluates to FindRoot[ g == 5 /. z -> 6, {x, -10, 10 }] in the
first step because it does contain k.