(6) (6)
>
>
>
>
>
>
>
>
>
>
>
>
(1) (1)
>
>
(3) (3)
>
>
>
>
(2) (2)
>
>
>
>
>
>
(5) (5) (4) (4) Bisection method
Bisection method restart:
a[0]:=1:b[0]:=2:P[0]:=(a[0]+b[0])/2;e:=10^(-1):
P0 3 2
f := unapply(x^3+4*x^2-10,x);
f x x3 4 x2 10
for i from 1 to 100 do
if f(a[i-1])*f(P[i-1])<0 then
b[i]:=P[i-1];a[i]:=a[i-1]:P[i]:=(a[i]+b[i])/2:
else
a[i]:=P[i-1]:b[i]:=b[i-1]:P[i]:=(a[i]+b[i])/2:
if abs(P[i-1]-P[i])<e then break fi end if
end do;
printf(" n | a[n]| |b[n] | P[n] \n");
for n from 0 to 100 do printf("%2.1f| %1.11f |%1.11f
|%1.11f|%1.11f \n",n,a[n],b[n], P[n],abs(P[i-1]-P[i])) end do;
n | a[n]| |b[n] | P[n]
0.0| 1.00000000000 |2.00000000000 |1.50000000000|0.03125000000 1.0| 1.00000000000 |1.50000000000 |1.25000000000|0.03125000000 2.0| 1.25000000000 |1.50000000000 |1.37500000000|0.03125000000 3.0| 1.25000000000 |1.37500000000 |1.31250000000|0.03125000000 4.0| 1.31250000000 |1.37500000000 |1.34375000000|0.03125000000 5.0|
Error, (in fprintf) number expected for floating point format Fixed point
Fixed point restart:
a[0]:=1:b[0]:=2:P[0]:=(a[0]+b[0])/2;
P0 3 2 g := unapply(cos(x),x);
g x cos x
e:=10^(-4):
for i from 1 to 400 do P[i]:=evalf(g(P[i-1]));
if abs(P[i-1]-P[i])<e then break fi
>
>
(7) (7)
(11) (11)
>
>
>
>
(12) (12) (8) (8)
>
>
>
>
>
>
(9) (9)
>
>
>
>
>
>
>
>
(10) (10) od:
printf(" n | P[n] \n");
for n from 0 to 10 do printf("%2.1f| %1.11f \n",n, P[n]) end do;
n | P[n]
0.0| 1.50000000000 1.0| 0.07073720167 2.0| 0.99749916720 3.0| 0.54240499230 4.0| 0.85646970900 5.0| 0.65510880170 6.0| 0.79298164580 7.0| 0.70172416830 8.0| 0.76373031130 9.0| 0.72226108210 10.0| 0.75031288570 Newton method
Newton method restart:
a[0]:=1:b[0]:=2:P[0]:=(a[0]+b[0])/2;e:=10^(-4):
P0 3 2
f := unapply(x^3+4*x^2-10,x);fd:= unapply(diff(f(x),x),x);fd(1);
f x x3 4 x2 10 fd x 3 x2 8 x
11 for i from 1 to 4 do
P[i]:=P[i-1]-f(P[i-1])/fd(P[i-1]):
if abs(P[i-1]-P[i])<e then break fi od:
printf(" n | P[n] \n");
for n from 0 to 10 do printf("%2.1f| %1.11f \n",n, P[n]) end do;
n | P[n]
0.0| 1.50000000000 1.0| 1.37333333300 2.0| 1.36526201500 3.0| 1.36523001400 4.0|
Error, (in fprintf) number expected for floating point format Secant method
Secant method restart:
f := unapply(cos(x)-x,x);
f x cos x x
a[0]:=0:b[0]:=Pi/2:P[1]:=(a[0]+b[0])/2;e:=10^(-3):evalf(f(Pi/6)*f (Pi/4));
(12) (12)
>
>
>
>
>
>
(13) (13)
>
>
P1 4 0.02680905413
P[0]:=Pi/6;
P0 6 for i from 2 to 4 do
P[i]:=P[i-1]-f(P[i-1])*(P[i-2]-P[i-1])/(f(P[i-2])-f(P[i-1])):
if abs(P[i-1]-P[i-2])<e then break fi
Error, cannot determine if this expression is true or false: od:
(1/12)*Pi < 1/1000
printf(" n | P[n] \n");
for n from 0 to 10 do printf("%2.1f| %1.11f \n",n, P[n]) end do;
n | P[n]
0.0| 0.52359877580 1.0| 0.78539816350 2.0| 0.73667993540 3.0|
Error, (in fprintf) number expected for floating point format