I’m writing a process that simulates the findRoot built-in perform utilizing the identical code that seems at chapter 6 of $textit{Programming in mathematica}$ by Paul Wellin. The code is the next.
findRoot[expr_, {var_, init_}, [Epsilon]_] :=
Module[{xi = init, fun = Function[fvar, expr]},
Whereas[Abs[fun[xi]] > [Epsilon],
xi = N[xi - fun[xi]/enjoyable'[xi]]];
{var -> xi}]
Within the textual content, the code is examined with success, however after I check it it would not works. For instance,
In[5]:= findRoot[x^2 - 2, {x, 2.0}, 0.0001]
Out[5]= {x -> 2.}
I attempted to vary the variable fvar by var, and this system works, however it is a reuse of names that makes mathematica shade the variable var in purple.
findRoot[expr_ == val_, {var_, init_}, [Epsilon]_] :=
Module[{xi = init, fun = Function[var, expr - val]},
Whereas[Abs[fun[xi]] > [Epsilon],
xi = N[xi - fun[xi]/enjoyable'[xi]]];
{var -> xi}]
I would like some suggestion to clear this challenge.