Professional Documents
Culture Documents
BISECTION METHOD
0.5
Out[7]=
-1 1 2 3
-0.5
-1.0
Prac2(Bisection Method).nb 3
x0 = 0;
x1 = 1.0;
Nmax = 20;
eps = 0.0001;
f[x_] := x ^ 3 - 5 x + 1;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
1th iteration value is:0.5
1.0
0.5
-1 1 2 3
-0.5
-1.0
In[15]:= x0 = 0;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := Cos[x] - x Exp[x];
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
Prac2(Bisection Method).nb 5
0.5
Out[21]=
-1 1 2 3
-0.5
-1.0
6 Prac2(Bisection Method).nb
x0 = - 1;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := 8 x ^ 3 - 12 x ^ 2 - 2 x + 3;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
1th iteration value is:0.5
1.0
0.5
-1 1 2 3
-0.5
-1.0
x0 = - 3;
x1 = - 2;
Nmax = 20;
eps = 0.0001;
f[x_] := 3 x ^ 3 + 10 x ^ 2 + 10 x + 7;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 5, 3}, PlotRange → {- 1, 1}]
8 Prac2(Bisection Method).nb
5
1th iteration value is:-
2
1
Estimated error in1th iteration is:
2
9
2th iteration value is:-
4
1
Estimated error in2th iteration is:
4
19
3th iteration value is:-
8
1
Estimated error in3th iteration is:
8
37
4th iteration value is:-
16
1
Estimated error in4th iteration is:
16
75
5th iteration value is:-
32
1
Estimated error in5th iteration is:
32
149
6th iteration value is:-
64
1
Estimated error in6th iteration is:
64
299
7th iteration value is:-
128
1
Estimated error in7th iteration is:
128
597
8th iteration value is:-
256
1
Estimated error in8th iteration is:
256
1195
9th iteration value is:-
512
1
Estimated error in9th iteration is:
512
2389
10th iteration value is:-
1024
1
Estimated error in10th iteration is:
1024
4779
11th iteration value is:-
2048
1
Estimated error in11th iteration is:
2048
9557
12th iteration value is:-
4096
1
Estimated error in12th iteration is:
4096
19 115
13th iteration value is:-
8192
1
Estimated error in13th iteration is:
8192
Return- 38 229
16 384
Prac2(Bisection Method).nb 9
1.0
0.5
-4 -2 2
-0.5
-1.0
x0 = 0;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := Cos[x] - x;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
10 Prac2(Bisection Method).nb
0.5
-1 1 2 3
-0.5
-1.0
Prac2(Bisection Method).nb 11
x0 = 0;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := Sin[x];
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
1th iteration value is:1.
1.0
0.5
-1 1 2 3
-0.5
-1.0
x0 = 0;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := x3 + 2 x2 - 3 x - 1;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
Prac2(Bisection Method).nb 13
0.5
-1 1 2 3
-0.5
-1.0
14 Prac2(Bisection Method).nb
x0 = 0.42;
x1 = 0.48;
Nmax = 20;
eps = 0.0001;
f[x_] := Tan[π x] - x - 6;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
1th iteration value is:0.45
0.5
-1 1 2 3
-0.5
-1.0
Prac2(Bisection Method).nb 15
x0 = 2;
x1 = 3;
Nmax = 20;
eps = 0.0001;
f[x_] := 1 - Log[x];
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
16 Prac2(Bisection Method).nb
5
1th iteration value is:
2
1
Estimated error in1th iteration is:
2
11
2th iteration value is:
4
1
Estimated error in2th iteration is:
4
21
3th iteration value is:
8
1
Estimated error in3th iteration is:
8
43
4th iteration value is:
16
1
Estimated error in4th iteration is:
16
87
5th iteration value is:
32
1
Estimated error in5th iteration is:
32
173
6th iteration value is:
64
1
Estimated error in6th iteration is:
64
347
7th iteration value is:
128
1
Estimated error in7th iteration is:
128
695
8th iteration value is:
256
1
Estimated error in8th iteration is:
256
1391
9th iteration value is:
512
1
Estimated error in9th iteration is:
512
2783
10th iteration value is:
1024
1
Estimated error in10th iteration is:
1024
5567
11th iteration value is:
2048
1
Estimated error in11th iteration is:
2048
11 135
12th iteration value is:
4096
1
Estimated error in12th iteration is:
4096
22 269
13th iteration value is:
8192
1
Estimated error in13th iteration is:
8192
Return 44 537
16 384
Prac2(Bisection Method).nb 17
1.0
0.5
-0.5
-1.0
x0 = 1;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := x6 - 3;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
18 Prac2(Bisection Method).nb
0.5
-1 1 2 3
-0.5
-1.0
Prac2(Bisection Method).nb 19
x0 = 0;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := x * Sin[x];
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 2}]
1th iteration value is:1.
2.0
1.5
1.0
0.5
-1 1 2 3
-0.5
-1.0
x0 = 0.5;
x1 = 2.0;
Nmax = 20;
eps = 0.0001;
f[x_] := x Cos1 x;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 2}]
Prac2(Bisection Method).nb 21
1.5
1.0
0.5
-1 1 2 3
-0.5
-1.0
22 Prac2(Bisection Method).nb
x0 = 0.2;
x1 = 0.4;
Nmax = 20;
eps = 0.0001;
f[x_] := x * Sin1 x;
IfN[f[x0] * f[x1]] > 0,
Print["These values do not satisfy the IVP so change the values."],
Fori = 1, i ≤ Nmax, i ++, a = x0 + x1 2;
IfAbsx1 - x0 2 < eps, Return[a], Print[i, "th iteration value is:", a];
Print"Estimated error in", i, "th iteration is:", x1 - x0 2;
If[f[a] * f[x1] > 0, x1 = a, x0 = a];
Print["Root is:", a]
Plot[f[x], {x, - 1, 3}, PlotRange → {- 1, 1}]
1th iteration value is:0.3
1.0
0.5
-1 1 2 3
-0.5
-1.0