Q.1 Bisection Method.
Sol.
In[8]:= f@x_D := x3 - 5 * x + 1
Plot@f@xD, 8x, -3, 4<,
PlotStyle ® 8Thick<, AxesLabel ® 8x, y<D
15
10
Out[9]= 5
x
-3 -2 -1 1 2 3 4
-5
-10
2 Bisection Methods.nb
In[10]:= a = N@0D;
b = N@1D;
c = Ha + bL • 2;
i = 1;
output = 88a, b, c, f@aD, f@bD, f@cD, Sign@f@aD * f@cDD<<;
While@i £ 6, If@Sign@f@aD * f@cDD < 0, b = c, a = cD;
c = Ha + bL • 2;
i = i + 1;
output = Append@output,
8a, b, c, f@aD, f@bD, f@cD, Sign@f@aD * f@cDD<DD;
Print@NumberForm@TableForm@output,
TableHeadings ® 8Automatic, 8"a", "b", "c", "f@aD",
"f@bD", "f@cD", "Sign@f@aD*f@cDD"<<D, 8DD;
a b c f@aD f@bD
1 0. 1. 0.5 1. -3.
2 0. 0.5 0.25 1. -1.375
3 0. 0.25 0.125 1. -0.234375
4 0.125 0.25 0.1875 0.37695313 -0.234375
5 0.1875 0.25 0.21875 0.069091797 -0.234375
6 0.1875 0.21875 0.203125 0.069091797 -0.083282471
7 0.1875 0.203125 0.1953125 0.069091797 -0.0072441101