In: Advanced Math
Use Matlab to solve the system x2+xy3=9 , 3x2y-y3 =4 using Newton's method for nonlinear system. use each of initial guesses (x0,y0)=(1.2,2.5), (-2,2.5), (-1.2,-2.5), (2,-2.5) observe which root to which the method converges, the number of iterates required and the speed of convergence.
Write the system in the form f(u) = 0, and report for each case the number of iterations needed for ||f(u)||2≤ 10-12−.
clc;
clear all;
%intial condition
x=1.2;
y=2.5;
%tolerence
tol=1e-12;
err=0.5;
%%%Initial points save in x1and x2 for print purpose
x1(1)=x;
x2(1)=y;
n=2;
while(err>tol)
%functio F
f1= x.^2+x.*y.^3-9;
f2=3*x.^2.*y-y.^3-4 ;
%%% partial derivatives of F (linearization)
f11=2*x+y.^3;
f12=3*y.^2.*x;
f21=6*x.*y;
f22=3*x.^2-3*y.^2;
J=[f11 f12 ; f21 f22 ]; %jacobian matrix
J1=inv(J);
Z=[x ;y]-J1*[f1; f2]; % newton formula
err=norm([f1; f2],2);
x=Z(1);
y=Z(2);
% %%% Every iteration values save in x1 and x2 for print
x1(n)=x;
x2(n)=y;
n=n+1;
end
n
disp('____________________________________________________________________')
disp('iteration x1 x2 ')
disp('____________________________________________________________________')
for i=1:n-1
fprintf('%d\t %15f \t %15f \n',i,x1(i),x2(i))
end
disp( 'Intersection point')
[x,y]
disp('Number of iterations with initial condition (1.2,
2.5)')
n-1
clc;
clear all;
%intial condition
x=-2;
y=2.5;
%tolerence
tol=1e-12;
err=0.5;
%%%Initial points save in x1and x2 for print purpose
x1(1)=x;
x2(1)=y;
n=2;
while(err>tol)
%functio F
f1= x.^2+x.*y.^3-9;
f2=3*x.^2.*y-y.^3-4 ;
%%% partial derivatives of F (linearization)
f11=2*x+y.^3;
f12=3*y.^2.*x;
f21=6*x.*y;
f22=3*x.^2-3*y.^2;
J=[f11 f12 ; f21 f22 ]; %jacobian matrix
J1=inv(J);
Z=[x ;y]-J1*[f1; f2]; % newton formula
err=norm([f1; f2],2);
x=Z(1);
y=Z(2);
% %%% Every iteration values save in x1 and x2 for print
x1(n)=x;
x2(n)=y;
n=n+1;
end
disp('____________________________________________________________________')
disp('iteration x y ')
disp('____________________________________________________________________')
for i=1:n-1
fprintf('%d\t %15f \t %15f \n',i,x1(i),x2(i))
end
disp( 'Intersection point')
[x,y]
disp('Number of iterations with initial condition (-2, 2.5)')
n-1
%%%%%%%%%%%%%%%%%%%% Answer
____________________________________________________________________
iteration x y
____________________________________________________________________
1 -2.000000 2.500000
2 -1.473397 1.696580
3 -1.179337 0.639062
4 -3.195436 -1.913207
5 -1.742641 -1.795509
6 -0.971947 -1.974885
7 -0.895735 -2.089564
8 -0.901263 -2.086579
9 -0.901266 -2.086588
10 -0.901266 -2.086588
11 -0.901266 -2.086588
Intersection point
ans =
-0.9013 -2.0866
Number of iterations with initial condition (-2, 2.5)
ans =
11
>>
clc;
clear all;
%intial condition
x=-1.2;
y=-2.5;
%tolerence
tol=1e-12;
err=0.5;
%%%Initial points save in x1and x2 for print purpose
x1(1)=x;
x2(1)=y;
n=2;
while(err>tol)
%functio F
f1= x.^2+x.*y.^3-9;
f2=3*x.^2.*y-y.^3-4 ;
%%% partial derivatives of F (linearization)
f11=2*x+y.^3;
f12=3*y.^2.*x;
f21=6*x.*y;
f22=3*x.^2-3*y.^2;
J=[f11 f12 ; f21 f22 ]; %jacobian matrix
J1=inv(J);
Z=[x ;y]-J1*[f1; f2]; % newton formula
err=norm([f1; f2],2);
x=Z(1);
y=Z(2);
% %%% Every iteration values save in x1 and x2 for print
x1(n)=x;
x2(n)=y;
n=n+1;
end
disp('____________________________________________________________________')
disp('iteration x y ')
disp('____________________________________________________________________')
for i=1:n-1
fprintf('%d\t %15f \t %15f \n',i,x1(i),x2(i))
end
disp( 'Intersection point')
[x,y]
disp('Number of iterations with initial condition (-1.2,
-2.5)')
n-1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Answer
____________________________________________________________________
iteration x y
____________________________________________________________________
1 -1.200000 -2.500000
2 -0.985132 -2.174800
3 -0.908497 -2.091489
4 -0.901311 -2.086601
5 -0.901266 -2.086588
6 -0.901266 -2.086588
7 -0.901266 -2.086588
Intersection point
ans =
-0.9013 -2.0866
Number of iterations with initial condition (-1.2, -2.5)
ans =
7
>>
clc;
clear all;
%intial condition
x=2;
y=-2.5;
%tolerence
tol=1e-12;
err=0.5;
%%%Initial points save in x1and x2 for print purpose
x1(1)=x;
x2(1)=y;
n=2;
while(err>tol)
%functio F
f1= x.^2+x.*y.^3-9;
f2=3*x.^2.*y-y.^3-4 ;
%%% partial derivatives of F (linearization)
f11=2*x+y.^3;
f12=3*y.^2.*x;
f21=6*x.*y;
f22=3*x.^2-3*y.^2;
J=[f11 f12 ; f21 f22 ]; %jacobian matrix
J1=inv(J);
Z=[x ;y]-J1*[f1; f2]; % newton formula
err=norm([f1; f2],2);
x=Z(1);
y=Z(2);
% %%% Every iteration values save in x1 and x2 for print
x1(n)=x;
x2(n)=y;
n=n+1;
end
disp('____________________________________________________________________')
disp('iteration x y ')
disp('____________________________________________________________________')
for i=1:n-1
fprintf('%d\t %15f \t %15f \n',i,x1(i),x2(i))
end
disp( 'Intersection point')
[x,y]
disp('Number of iterations with initial condition (2, -2.5)')
n-1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
____________________________________________________________________
iteration x y
____________________________________________________________________
1 2.000000 -2.500000
2 1.224118 -1.773857
3 0.352397 -0.769761
4 -22.175315 22.599350
5 -14.832213 17.565361
6 -10.202207 13.543333
7 -7.190606 10.367504
8 -5.168467 7.889394
9 -3.772849 5.973114
10 -2.789209 4.495752
11 -2.085083 3.345040
12 -1.572499 2.407123
13 -1.186599 1.518463
14 -0.939118 0.121361
15 -5.272400 0.397125
16 -3.491379 0.316557
17 -3.029761 0.192941
18 -3.001248 0.148966
19 -3.001625 0.148108
20 -3.001625 0.148108
21 -3.001625 0.148108
Intersection point
ans =
-3.0016 0.1481
Number of iterations with initial condition (2, -2.5)
ans =
21
>>