I'm trying to write a program for finding the root of f(x)=e^x+sin(x)-4 by Newton's Method but I'm instructed to not use the built in function and write the code from scratch. I'm pretty new to this and this is what I've come up with so far. I'm curious about what I need to fix to make it better/work.
f[x_]:= Exp[x]+Sin[x]-4 (* This is my starting function *)
g[x_]:= x-(f[x]/f'[x]) (* Formula for Newton's Method *)
count=0;
maxiterations=100; (* Max times function will run *)
TOL=10^(-8); (* Tolerance for stopping condition *)
xprevious=1.0; (* This is my initial guess *)
While[Abs[xcurrent-xprevious] >= TOL && count <= maxiterations,
{count++, xcurrent=g[xcurrent]}]
(* While my current and previous guess are above my tolerance and I haven't gone over
my max iterations program will continue to run, adding one to the count each time and
putting xcurrent into the Newton's Method Equation *)
Obviously I am having some troubles with this code. What do I need to do to fix it?
f(x_)
" is not a function in Mathematica. $\endgroup$