In[1]:= Print["f(x)= ", f[x_] = Input["Enter the function :"]];
Print["Graph of the fuction in the interval[-4,4]"];
Plot[f[x], {x, -4, 4}]
a = Input["Enter the value of a:"];
b = Input["Enter the value of b:"];
If[f[a] * f[b] > 0, Print["THe given interval doesn't contain the root"];
Exit[]];
ϵ = Input["Enter the prescribed tolerance error:"];
k = Input["Enter the maximum number of iterations:"];
Print["Graph of the function in the interval [", a, "," b, "]"]
Plot[f[x], {x, a, b}]
x0 = N[(a + b) / 2];
For[i = 1, i ≤ k, i ++,
{
If[f '[x0] 0, Break[]],
x1 = N[x0 - f[x0] / f '[x0]],
Print["The Root after iteration", i, "is", x1],
If[Abs[f[x1]] < ϵ, Break[]],
x0 = x1
}
]
f(x)= -5 - 17 x + 5 x2 + x3
Graph of the fuction in the interval[-4,4]
80
60
40
Out[3]=
20
-4 -2 2 4
-20
Graph of the function in the interval [13 ,]
2 Newton [Link]
Out[10]=
15
10
1.5 2.0 2.5 3.0
-5
-10
-15
The Root after iteration1is2.73333
The Root after iteration2is2.54064
The Root after iteration3is2.52325
The Root after iteration4is2.52311