Professional Documents
Culture Documents
Question 01
Question 01
Question 01
2
Out[2]=
x
1 2 3 4
-1
In[11]:= a = N[0];
b = N[1];
c = (a + b) / 2;
i = 1;
output = {{a, b, c, f[a], f[b], f[c], f[a] * f[c]}};
While[i ≤ 6, If[f[a] * f[c] < 0, b = c, a = c]; c = (a + b) / 2;
i = i + 1; output = Append[output, {a, b, c, f[a], f[b], f[c], f[a] * f[c]}]];
Print[NumberForm[TableForm[output, TableHeadings →
{Automatic, {"a", "b", "c", "f[a]", "f[b]", "f[c]", "f[a]*f[c]"}}], 8]];
Print["Approximate value of the root=", c];
2
Out[22]=
x
1 2 3 4
-1
In[23]:= 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]}};
While[i ≤ 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]}]];
Print[NumberForm[TableForm[output, TableHeadings →
{Automatic, {"a", "b", "c", "f[a]", "f[b]", "f[c]", "f[a]*f[c]"}}], 8]];
Print["Approximate value of the root=", c];