Professional Documents
Culture Documents
ax bxc 0
2
b b2 4 a c
x1
2a
b b2 4 a c
x2
2a
The formulae for the roots of a 3rd degree polynomial are given below
a x bx cx d 0
3
Roots of a Polynomial:
The Matlab program can be used to calculate the roots of an n degree polynomial.
Example: Find the roots of the given polynomial.
5 x3 8 x 2 6 x 6 0
ans =
>>p=[5 8 6 -6]; roots(p)
-1.0604 + 1.0863i
-1.0604 - 1.0863i
0.5207
x 4 x 16 x 20 0
5
ans =
1.0043 + 2.7517i
1.0043 - 2.7517i
-1.4940 + 0.3852i
-1.4940 - 0.3852i
0.9793
f (x i )
f(x i )
x i 1 x i
f (x i )
f(xi)
Slope at this
point is f'(xi)
Tangent line
f(xi)-0
0
Xi+1
xi (nitial value)
x i x i 1
f(x i ) 0
x i x i 1
(error)
f(x i )
x i1 x i
f (x i )
f(x i ) f(x i )
Newton-Raphson Example 1:
4 1
2
f() 0
f 2 4 1
1 1
f 2
2 1
, xn1 xn
(tet + 1)1/2 + tet2 - 4
40
f'
-1.5858
2.3536
0.6738
1.6738
0.4368
3.6534
-0.1196
30
25
f(tet)
35
20
15
10
1.5542
0.0139
3.4213
-0.0041
1.5501
-0.00013
3.4134
3.95e-5
5
0
-5
-1
1.55
3
tet
Newton-Raphson Example 2:
5u cos(3u) 1.6
f(u) 0
f 5u cos(3u) 1.6
f 5 3sin(3u)
, xn1 xn
5 u - cos(3 u) - 8/5
30
f'
20
4.3899
5.4233
-0.8094
10
0.1905
-1.4883
6.6229
0.2247
0.4152
0.1569
7.8429
-0.0200
0.3952
0.00025
7.7801
-3.32e-5
f(u)
-10
-20
-30
-6
-4
-2
MATLAB CODES
The following changes are made in the program (nr1.m) to solve the problems.
Newton-Raphson Example 1:
clc, clear
x=1;xe=0.001*x;
niter=20;
%---------------------------------------------for n=1:niter
%---------------------------------------------f=x^2-4+sqrt(x+1);
df=2*x+0.5/(sqrt(x+1));
%---------------------------------------------x1=x
x=x1-f/df
if abs(x-x1)<xe
kerr=0;break
end
end
kerr,x
x = fzero(@(x)x^2-4+sqrt(x+1),1)
Newton-Raphson Example 2:
clc, clear
x=1;xe=0.001*x;
niter=20;
%---------------------------------------------for n=1:niter
%---------------------------------------------f=5*x-cos(3*x)-1.6;
df=5+3*sin(3*x);
%---------------------------------------------x1=x
x=x1-f/df
if abs(x-x1)<xe
kerr=0;break
end
end
kerr,x
x = fzero(@(x)5*x-cos(3*x)-1.6,1)
Newton-Raphson iteration method is used to solve the nonlinear system of equations. Since
there are more than one equations and unknown variables, partial derivatives of the
equations with respect to each unkown variable are used in the solution procedure.
f1(x1,x2)=0
f f
f2(x1,x2)=0
f1
x
1
f2
x 1
f1
x 2 1 f1
f2 2 f2
x 2
Arbitrary initial values for x1 ve x2 are assigned and the iteration procedure is started by
making the necessary changes in the computer program (newtonrn). The variables are
stated as xb() in the program.
Newton-Raphson Example 3:
x 32 y 22 25
f1 x 32 y 22 25
f2 y x 2
f1
f1
2x 3,
2y 2
x
y
f2
f2
2x ,
1
x
y
The following changes are made in the program (nr.m) to solve the problem.
clc, clear
y
x=[1 4] ; fe=[0.01 0.01];
niter1=5;niter2=50;
9
fe=transpose(abs(fe));kerr=1;
for n=1:niter2
(2.643, 6.987)
x
%Error Equations--------------------------a(1,1)=2*(x(1)-3);a(1,2)=2*(x(2)-2);
4
(-1.82, 3.321)
a(2,1)=-2*x(1);a(2,2)=1;
2
b(1)=-((x(1)-3)^2+(x(2)-2)^2-25);
1
b(2)=-(x(2)-x(1)^2);
%---------------------------------------------1 2 3
x
bb=transpose(b);eps=inv(a)*bb;x=x+transpose(eps);
if n>niter1
if abs(eps)<fe
kerr=0; break
else
display ('Roots are not found')
end
end
As shown in the figure, there are two valid solution sets. The output
end
solution set is determined by the initial values of the unkown variables.