Newton-Raphson Iteration method of finding root. We will find root by this method in mathematica here. For this method we need to choose any point near root and then try to find out the absolute root according to this method.
By this method if we choose a root
x0 = x0
then the closer root will be
x1 = x0 - f(x0) / f '(x0) and so on...
Now we directly write the following code in mathematica.
When we will run it by hitting SHIFT + ENTER we will see the following graph.
Here we can see the root is near 1.
So we will input
x0 = 1
tol = .001
n = 25
Thus the method is done.
By this method if we choose a root
x0 = x0
then the closer root will be
x1 = x0 - f(x0) / f '(x0) and so on...
Now we directly write the following code in mathematica.
Clear["`*"]; f[x_] := x^3 + x^2 - 1; Plot[f[x],{x,-5,5}]; x0 = Input["Enter x0"]; tol = Input["Enter tolerance"]; n = Input["Enter total iteration"]; x1 = x0; Do[ x2 = x1 - f[x1]/f'[x1] //N; Print[i,PaddedForm[x2,{15,8}]]; If[Abs[x1-x2]<tol, {Print["The root is: ",x2], Exit[]}]; x1 = x2 ,{i,1,n}]; Print["Maximum iteration failed"];
When we will run it by hitting SHIFT + ENTER we will see the following graph.
Here we can see the root is near 1.
So we will input
x0 = 1
tol = .001
n = 25
Thus the method is done.