Regula-Falsi Method Practical Codes Wolfram
Regula-Falsi Method Practical Codes Wolfram
Regula-Falsi Method
22/CS/43
In[1]:= f[x_] = x ^ 3 - 5 x + 1;
Plotf[x], {x, 0, 1}, PlotStyle → Thick, Green, AxesLabel → {x, y}
y
x
0.2 0.4 0.6 0.8 1.0
Out[2]=
-1
-2
-3
In[19]:= a = N[0];
b = N[1];
c = a * f[b] - b * f[a] f[b] - f[a]
i = 1;
output = {{a, b, c, f[a], f[b], f[c], f[a] * f[c]}};
Whilei ≤ 6,
If[f[c] ≠ 0, If[f[a] * f[c] < 0, b = c, a = c], Break[]];
c = a * f[b] - b * f[a] f[b] - f[a];
i = i + 1;
output = Append[output, {a, b, c, f[a], f[b], f[c], f[a] * f[c]}];
PrintNumberFormTableFormoutput,
TableHeadings → Automatic, "a", "b", "c", "f[a]", "f[b]", "f[c]", "Sign[f[a]*f[c]]", 8;
Print"Aprroximate value of the root is : ", c;
Out[21]=
0.25
2
In[27]:= f[x_] := 3 * x ^ 3 + 10 * x ^ 2 + 10 * x + 7;
Plotf[x], {x, - 3, - 2}, PlotStyle → Thick, Blue, AxesLabel → {x, y}
Out[28]=
y
x
-3.0 -2.8 -2.6 -2.4 -2.2
-5
-10
40
30
20
10
x
2.2 2.4 2.6 2.8 3.0
In[39]:= a = N[2];
b = N[3];
c = a * f[b] - b * f[a] f[b] - f[a]
i = 1;
output = {{a, b, c, f[a], f[b], f[c], f[a] * f[c]}};
Whilei ≤ 6,
If[f[c] ≠ 0, If[f[a] * f[c] < 0, b = c, a = c], Break[]];
c = a * f[b] - b * f[a] f[b] - f[a];
i = i + 1;
output = Append[output, {a, b, c, f[a], f[b], f[c], f[a] * f[c]}];
PrintNumberFormTableFormoutput,
TableHeadings → Automatic, "a", "b", "c", "f[a]", "f[b]", "f[c]", "Sign[f[a]*f[c]]", 8;
Print"Aprroximate value of the root is : ", c;
Out[41]=
2.07843
4
x
0.2 0.4 0.6 0.8 1.0
-0.2
-0.4
-0.6
-0.8
-1.0
In[49]:= a = N[0];
b = N[1];
c = a * f[b] - b * f[a] f[b] - f[a]
i = 1;
output = {{a, b, c, f[a], f[b], f[c], f[a] * f[c]}};
Whilei ≤ 6,
If[f[c] ≠ 0, If[f[a] * f[c] < 0, b = c, a = c], Break[]];
c = a * f[b] - b * f[a] f[b] - f[a];
i = i + 1;
output = Append[output, {a, b, c, f[a], f[b], f[c], f[a] * f[c]}];
PrintNumberFormTableFormoutput,
TableHeadings → Automatic, "a", "b", "c", "f[a]", "f[b]", "f[c]", "Sign[f[a]*f[c]]", 8;
Print"Aprroximate value of the root is : ", c;
Out[51]=
0.867419
5
1.0
0.5
x
0.2 0.4 0.6 0.8 1.0
-0.5
In[59]:= a = N[0];
b = N[1];
c = a * f[b] - b * f[a] f[b] - f[a]
i = 1;
output = {{a, b, c, f[a], f[b], f[c], f[a] * f[c]}};
Whilei ≤ 6,
If[f[c] ≠ 0, If[f[a] * f[c] < 0, b = c, a = c], Break[]];
c = a * f[b] - b * f[a] f[b] - f[a];
i = i + 1;
output = Append[output, {a, b, c, f[a], f[b], f[c], f[a] * f[c]}];
PrintNumberFormTableFormoutput,
TableHeadings → Automatic, "a", "b", "c", "f[a]", "f[b]", "f[c]", "Sign[f[a]*f[c]]", 8;
Print"Aprroximate value of the root is : ", c;
Out[61]=
0.685073
6
Out[68]=
y
0.5
x
0.2 0.4 0.6 0.8 1.0
-0.5
-1.0
In[69]:= a = N[0];
b = N[1];
c = a * f[b] - b * f[a] f[b] - f[a]
i = 1;
output = {{a, b, c, f[a], f[b], f[c], f[a] * f[c]}};
Whilei ≤ 6,
If[f[c] ≠ 0, If[f[a] * f[c] < 0, b = c, a = c], Break[]];
c = a * f[b] - b * f[a] f[b] - f[a];
i = i + 1;
output = Append[output, {a, b, c, f[a], f[b], f[c], f[a] * f[c]}];
PrintNumberFormTableFormoutput,
TableHeadings → Automatic, "a", "b", "c", "f[a]", "f[b]", "f[c]", "Sign[f[a]*f[c]]", 8;
Print"Aprroximate value of the root is : ", c;
Out[71]=
0.6127
7
Secant Method
In[1]:= f[x_] = x ^ 3 - 5 * x + 1;
Plotf[x], {x, 0, 1}, PlotStyle → Thick, Green, AxesLabel → {x, y}
a = N[0];
b = N[1];
c = Nb - (b - a) f[b] - f[a] * f[b];
i = 1;
output = {{a, b, c, f[a], f[b]}};
Whilei ≤ 6, If[f[b] ≠ f[a], b = c, a = c];
c = Nb - (b - a) f[b] - f[a] * f[b];
i = i + 1;
output = Append[output, {a, b, c, f[a], f[b]}];
PrintNumberForm
TableFormoutput, TableHeadings → Automatic, {"a", "b", "c", "f[a]", "f[b]"}, 0;
Print"Approx val of the root = " , c;
y
x
0.2 0.4 0.6 0.8 1.0
Out[2]=
-1
-2
-3
8
a b c f[a] f[b]
1 0. 1. 0.25 1. -3.
2 0. 0.25 0.202532 1. -0.234375
3 0. 0.202532 0.201654 1. -0.00435057
4 0. 0.201654 0.20164 1. -0.000071506
5 0. 0.20164 0.20164 1. -1.17251 × 10-6
6 0. 0.20164 0.20164 1. -1.92254 × 10-8
7 0. 0.20164 0.20164 1. -3.15235 × 10-10
x
-3.0 -2.8 -2.6 -2.4 -2.2
-5
-10
9
In[263]:=
f[x_] = x ^ 4 - 3 x ^ 2 + x - 10;
Plotf[x], {x, 2, 3}, PlotStyle → Thick, Blue, AxesLabel → {x, y}
a = N[2];
b = N[3];
c = Nb - (b - a) f[b] - f[a] * f[b];
i = 1;
output = {{a, b, c, f[a], f[b], f[c], f[a] * f[c]}};
Whilei ≤ 6,
c = Nb - (b - a) f[b] - f[a] * f[b];
a = b;
b = c;
i = i + 1;
output = Append[output, {a, b, c, f[a], f[b], f[c], f[a] * f[c]}];
PrintNumberFormTableFormoutput,
TableHeadings → Automatic, {"a", "b", "c", "f[a]", "f[b]", "f[c]", "f[a]*f[c]"}, 0;
Print"Approx val of the root = " , c;
Out[264]=
y
40
30
20
10
x
2.2 2.4 2.6 2.8 3.0
10
x
0.2 0.4 0.6 0.8 1.0
-0.2
-0.4
-0.6
-0.8
-1.0
11
1.0
0.5
x
0.2 0.4 0.6 0.8 1.0
-0.5
12
0.5
x
0.2 0.4 0.6 0.8 1.0
-0.5
-1.0
13