Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Newton Raphson.

wxmx 1 / 6

Practical-4
Newton Raphson method

1 Perform 10 iterations to find the approximate


root for f(x)=x^3+x^2+3*x-3
f(x):=x^3+x^2-3*x-3;
3 2
f ( x ) := x + x + ( − 3 ) x − 3
a:1;
1
print("Exact root is",find_root(f,1,2))$
for i:1 thru 10 do
(
define (g(x),diff(f(x),x)),
m:a-(f(a)/g(a)),
print("The value after",i,"the iteration is",float(m)),
a:m
);
wxplot2d(f(x),[x,-5,5]);
Exact root is 1.732050807568877
The value after 1 the iteration is 3.0
The value after 2 the iteration is 2.2
The value after 3 the iteration is 1.830150753768844
The value after 4 the iteration is 1.737795453142821
The value after 5 the iteration is 1.732072291544954
The value after 6 the iteration is 1.732050807871055
The value after 7 the iteration is 1.732050807568877
The value after 8 the iteration is 1.732050807568877
The value after 9 the iteration is 1.732050807568877
The value after 10 the iteration is 1.732050807568877
done
Newton Raphson.wxmx 2 / 6

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

Using find_root= 1.570796326794897


kill(all);
done

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

Using find_root= 0.8845106161658525


kill(all);
done

4 Find an approx. value of 19^(1/4)


f(x):= x^4 -19;
a:1;
b:3;
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,1,3]);
print("Using find_root=",find_root(f,1,3))$
4
f ( x ) := x − 19
1
3
Approx. root after 1 th iteration 5.5
Newton Raphson.wxmx 5 / 6

Approx. root after 2 th iteration 4.15354996243426


Approx. root after 3 th iteration 3.181450529365836
Approx. root after 4 th iteration 2.533596750084436
Approx. root after 5 th iteration 2.192263647951237
Approx. root after 6 th iteration 2.095030283660412
Approx. root after 7 th iteration 2.087834997638896
Approx. root after 8 th iteration 2.087797630933033
Approx. root after 9 th iteration 2.087797629929844
Approx. root after 10 th iteration 2.087797629929844
done

Using find_root= 2.087797629929844


kill(all);
done

5 Find the approx. value of 1/37


Newton Raphson.wxmx 6 / 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

You might also like