blob: 43c5c261b3e62980518dae658e7a75841d91afe6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
//Example No. 6_07
//Root of the Equation using Newton Raphson Method
//Pg No. 147
clear ; close ; clc ;
//Coefficients of polynomial in increasing order of power of x
A = [ 2 -3 1];
fx = poly(A,'x','c');
dfx = derivat(fx);
x(1) = 0 ;
for i = 1:10
f(i) = horner(fx,x(i));
if f(i)~= 0 then
df(i) = horner(dfx,x(i));
x(i+1) = x(i) - f(i)/df(i) ;
printf('x%i = %f\n',i+1,x(i+1));
else
printf('Since f(%f) = 0, the root closer to the point x = 0 is %f \n',x(i),x(i) );
break
end
end
|