0% found this document useful (0 votes)
56 views

Practical 4 (A) : Bisection Method

The document describes the bisection method for finding roots of functions. It provides 4 examples of applying the bisection method to find roots of different functions f(x) over intervals [a0, b0] with a specified number of iterations n. For each example, it shows the iterative bisection process and resulting table of values, and reports the estimated root after n iterations.

Uploaded by

Prakriti Saxena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Practical 4 (A) : Bisection Method

The document describes the bisection method for finding roots of functions. It provides 4 examples of applying the bisection method to find roots of different functions f(x) over intervals [a0, b0] with a specified number of iterations n. For each example, it shows the iterative bisection process and resulting table of values, and reports the estimated root after n iterations.

Uploaded by

Prakriti Saxena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PRACTICAL 4(A)

BISECTION METHOD

BISECTION METHOD WITH STOPPING CONDITION AS NUMBER OF ITTERATIONS.


In[ ]:= BM[a0_, b0_, n_, f_] :=
a+b
Module{}, a = N[a0]; b = N[b0]; c = ;
2
i = 0;
If[f[a] * f[b] > 0,
Print["we cannot find the roots in the given interval"];
Return[]];
OutputDetails = {{i, a, b, c, f[c]}};
Whilei < n,
If[f[a] * f[c] < 0, b = c, a = c];
(a + b)
c= ;
2
i++;
OutputDetails = Append[OutputDetails, {i, a, b, c, f[c]}];;
Print[NumberForm[TableForm[OutputDetails,
TableHeadings → {None, {"i", "ai", "bi", "ci", "f[ci]"}}], 7]];
Print["root after", n, "itteration is ", NumberForm[c, 6]];;

QUES 1:F[x]= cos x-x

In[ ]:= f[x_] = Cos[x] - x;


BM[0, 1, 17, f]
2 practical 4(a).nb

i ai bi ci f[ci]
0 0. 1. 0.5 0.3775826
1 0.5 1. 0.75 -0.01831113
2 0.5 0.75 0.625 0.1859631
3 0.625 0.75 0.6875 0.08533495
4 0.6875 0.75 0.71875 0.03387937
5 0.71875 0.75 0.734375 0.007874725
6 0.734375 0.75 0.7421875 -0.005195712
7 0.734375 0.7421875 0.7382813 0.00134515
8 0.7382813 0.7421875 0.7402344 -0.001923873
9 0.7382813 0.7402344 0.7392578 -0.0002890091
10 0.7382813 0.7392578 0.7387695 0.0005281584
11 0.7387695 0.7392578 0.7390137 0.0001195967
12 0.7390137 0.7392578 0.7391357 -0.00008470073
13 0.7390137 0.7391357 0.7390747 0.00001744935
14 0.7390747 0.7391357 0.7391052 -0.00003362535
15 0.7390747 0.7391052 0.73909 -8.087915 × 10-6
16 0.7390747 0.73909 0.7390823 4.680737 × 10-6
17 0.7390823 0.73909 0.7390862 -1.703583 × 10-6
root after17itteration is 0.739086

Ques 2: f(x)=x3 -17

In[ ]:= f[x_] = x ^ 3 - 17;


BM[2, 3, 20, f]
i ai bi ci f[ci]
0 2. 3. 2.5 -1.375
1 2.5 3. 2.75 3.796875
2 2.5 2.75 2.625 1.087891
3 2.5 2.625 2.5625 -0.173584
4 2.5625 2.625 2.59375 0.4495544
5 2.5625 2.59375 2.578125 0.136097
6 2.5625 2.578125 2.570313 -0.01921415
7 2.570313 2.578125 2.574219 0.05832356
8 2.570313 2.574219 2.572266 0.01952527
9 2.570313 2.572266 2.571289 0.0001482004
10 2.570313 2.571289 2.570801 -0.009534815
11 2.570801 2.571289 2.571045 -0.004693767
12 2.571045 2.571289 2.571167 -0.002272898
13 2.571167 2.571289 2.571228 -0.001062378
14 2.571228 2.571289 2.571259 -0.0004570958
15 2.571259 2.571289 2.571274 -0.0001544495
16 2.571274 2.571289 2.571281 -3.124975 × 10-6
17 2.571281 2.571289 2.571285 0.00007253762
18 2.571281 2.571285 2.571283 0.00003470629
19 2.571281 2.571283 2.571282 0.00001579065
20 2.571281 2.571282 2.571282 6.332837 × 10-6
root after20itteration is 2.57128

Ques 3: f(x)= x5 +2x-1

In[ ]:= f[x_] = x5 + 2 x - 1;


BM[0, 1, 20, f]
practical 4(a).nb 3

i ai bi ci f[ci]
0 0. 1. 0.5 0.03125
1 0. 0.5 0.25 -0.4990234
2 0.25 0.5 0.375 -0.2425842
3 0.375 0.5 0.4375 -0.1089716
4 0.4375 0.5 0.46875 -0.03986886
5 0.46875 0.5 0.484375 -0.004587025
6 0.484375 0.5 0.4921875 0.0132587
7 0.484375 0.4921875 0.4882813 0.004318076
8 0.484375 0.4882813 0.4863281 -0.0001388627
9 0.4863281 0.4882813 0.4873047 0.002088503
10 0.4863281 0.4873047 0.4868164 0.000974545
11 0.4863281 0.4868164 0.4865723 0.0004177725
12 0.4863281 0.4865723 0.4864502 0.0001394377
13 0.4863281 0.4864502 0.4863892 2.832053 × 10 -7
14 0.4863281 0.4863892 0.4863586 -0.00006929084
15 0.4863586 0.4863892 0.4863739 -0.00003450408
16 0.4863739 0.4863892 0.4863815 -0.00001711051
17 0.4863815 0.4863892 0.4863853 -8.413667 × 10 -6
18 0.4863853 0.4863892 0.4863873 -4.065235 × 10 -6
19 0.4863873 0.4863892 0.4863882 -1.891016 × 10 -6
20 0.4863882 0.4863892 0.4863887 -8.039056 × 10 -7
root after20itteration is 0.486389

Ques 4: f(x)=log(1+x)-cos x

In[ ]:= f[x_] := Log[1 + x] - Cos[x];


BM[0, 1, 20, f]
i ai bi ci f[ci]
0 0. 1. 0.5 -0.4721175
1 0.5 1. 0.75 -0.1720731
2 0.75 1. 0.875 -0.0123882
3 0.875 1. 0.9375 0.06959341
4 0.875 0.9375 0.90625 0.0284359
5 0.875 0.90625 0.890625 0.007981228
6 0.875 0.890625 0.8828125 -0.002214254
7 0.8828125 0.890625 0.8867188 0.002880809
8 0.8828125 0.8867188 0.8847656 0.0003326059
9 0.8828125 0.8847656 0.8837891 -0.0009409923
10 0.8837891 0.8847656 0.8842773 -0.0003042352
11 0.8842773 0.8847656 0.8845215 0.00001417485
12 0.8842773 0.8845215 0.8843994 -0.0001450328
13 0.8843994 0.8845215 0.8844604 -0.00006542963
14 0.8844604 0.8845215 0.884491 -0.00002562756
15 0.884491 0.8845215 0.8845062 -5.726396 × 10 -6
16 0.8845062 0.8845215 0.8845139 4.224215 × 10 -6
17 0.8845062 0.8845139 0.88451 -7.51093 × 10-7
18 0.88451 0.8845139 0.8845119 1.73656 × 10-6
19 0.88451 0.8845119 0.884511 4.927336 × 10-7
20 0.88451 0.884511 0.8845105 -1.291798 × 10-7
root after20itteration is 0.884511

You might also like