Re: FindROot and substitutions

*To*: mathgroup at smc.vnet.net*Subject*: [mg89846] Re: [mg89811] FindROot and substitutions*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Sun, 22 Jun 2008 03:25:15 -0400 (EDT)*References*: <200806210930.FAA15731@smc.vnet.net>

On 21 Jun 2008, at 18:30, 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; > bad[z_] := FindRoot[ g == 5, {x, -10, 10 }]; > bad[5] > good[k_] := FindRoot[ g == 5 /. z -> k, {x, -10, 10 }]; > good[6] > > Thanks! > > Aaron > This has little to do with FindRoot but a lot to do with how := (SetDelayed) works. When you evaluate bad[5], Mathematica tries to substitute 5 for z in the RHS without evaluating it, but as there is no z there, nothing is substituted. You then end up with FindRoot[x z ==5, {x,-10,10}], which clearly is not going to work. In your second exmple, the right hand side of the definition of good involves k, so 6 is substituted for k and you end up with FindRoot[x z == 5 /. z -> 6, {x, -10, 10}], which is fine. Andrzej Kozlowski

**References**:**FindROot and substitutions***From:*Aaron Fude <aaronfude@gmail.com>