Professional Documents
Culture Documents
Newton Raphson
Newton Raphson
wxmx 1 / 6
Practical-4
Newton Raphson method
kill(all);
done
2 f(x)=cos(x)
f(x):= cos(x);
a:1;
b:2;
if(f(a)*f(b)<0)
then
(
define(g(x),diff(f(x),x)),
for i:1 thru 10 do
(
if (is(notequal(float(g(a)),0)))
then(
a:a-(f(a)/g(a)),
print("Approx. root after",i,"th iteration",float(a))
)
else
(
return()
)
)
)
else
(
print("Take a different interval!")
);
wxplot2d(f(x),[x,0,2]);
print("Using find_root=",find_root(f,0,2))$
f ( x ) := cos ( x )
1
2
Approx. root after 1 th iteration 1.642092615934331
Approx. root after 2 th iteration 1.570675277161251
Approx. root after 3 th iteration 1.570796326795488
Approx. root after 4 th iteration 1.570796326794897
Approx. root after 5 th iteration 1.570796326794897
Approx. root after 6 th iteration 1.570796326794897
Approx. root after 7 th iteration 1.570796326794897
Approx. root after 8 th iteration 1.570796326794897
Approx. root after 9 th iteration 1.570796326794897
Approx. root after 10 th iteration 1.570796326794897
done
Newton Raphson.wxmx 3 / 6
3 f(x)=log(1+x) - cos x
f(x):= log(1+x) - cos(x);
a:0;
b:2;
if(f(a)*f(b)<0)
then
(
i:0,
define(g(x),diff(f(x),x)),
while(is(notequal(float(g(a)),0))) do
(
i:i+1,
a:a-(f(a)/g(a)),
print("Approx. root after",i,"th iteration",float(a)),
if(abs(f(a)/g(a))<10^(-6))
then return("Tolerance met.")
)
)
else
(
print("Take a different interval!")
);
wxplot2d(f(x),[x,0,2]);
print("Using find_root=",find_root(f,0,2))$
f ( x ) := log ( 1 + x ) − cos ( x )
0
2
Approx. root after 1 th iteration 1.0
Approx. root after 2 th iteration 0.8860617363903003
Approx. root after 3 th iteration 0.8845109403287758
Tolerance met.
Newton Raphson.wxmx 4 / 6
kill(all)$
f(x):= (1/x) - 37;
a:1/100;
b:1/10;
if(f(a)*f(b)<0)
then
(
define(g(x),diff(f(x),x)),
for i:1 thru 10 do
(
if (is(notequal(float(g(a)),0)))
then(
a:a-(f(a)/g(a)),
print("Approx. root after",i,"th iteration",float(a))
)
else
(
return()
)
)
)
else
(
print("Take a different interval!")
);
wxplot2d(f(x),[x,0.001,0.1]);
print("Using find_root=",find_root(f,0,2))$
1
f ( x ) := − 37
x
1
100
1
10
Approx. root after 1 th iteration 0.0163
Approx. root after 2 th iteration 0.02276947
Approx. root after 3 th iteration 0.0263563357290067
Approx. root after 4 th iteration 0.02701038343478914
Approx. root after 5 th iteration 0.02702701677768801
Approx. root after 6 th iteration 0.02702702702702314
Approx. root after 7 th iteration 0.02702702702702703
Approx. root after 8 th iteration 0.02702702702702703
Approx. root after 9 th iteration 0.02702702702702703
Approx. root after 10 th iteration 0.02702702702702703
done