In: Advanced Math
Formulate Newton’s method for the system
x^3 = y
y^3 = x
Note that this system has three real roots (−1, −1), (0, 0) and (1, 1). By taking various initial points in the square −2 < x, y < 2, try to obtain the attraction regions of these three roots.
P.S. An attraction region of a root is defined as the set of all initial points which will eventually converge to the root.
%Matlab code for Multivariate Newton Raphson method
clear all
close all
syms x y
%steady state equation
f(x,y)=x^3-y;
g(x,y)=y^3-x;
%Newton Raphson algorithm
f_x(x,y)=diff(f,x);
f_y(x,y)=diff(f,y);
g_x(x,y)=diff(g,x);
g_y(x,y)=diff(g,y);
%initial guess for Newton Raphson
x0=-2;y0=-2;
fprintf('For initial guess x=%f and y=%f.\n',x0,y0)
err=1; c=0;
%loop for Newton Raphson Algorithm
while err>10^-12
c=c+1;
%Jacobian of equation of
2 variable
jac=[f_x(x0,y0)
f_y(x0,y0);g_x(x0,y0) g_y(x0,y0)];
ijac=inv(jac);
xx=double([x0;y0]-ijac*[f(x0,y0);g(x0,y0)]);
%error in each
loop
err(c)=norm(xx-[x0;y0]);
%iteration count
it(c)=c;
x0=double(xx(1));
y0=double(xx(2));
fprintf('After %d
iteration\n',c)
fprintf('\t
x=%.12f\ty=%.12f\n',x0,y0)
end
fprintf('\nNR solution for solution of equation is x=%.12f
y=%.12f.\n',xx(1),xx(2))
fprintf('------------------------------------------------------------\n\n')
%initial guess for Newton Raphson
x0=2;y0=2;
fprintf('For initial guess x=%f and y=%f.\n',x0,y0)
err=1; c=0;
%loop for Newton Raphson Algorithm
while err>10^-12
c=c+1;
%Jacobian of equation of
2 variable
jac=[f_x(x0,y0)
f_y(x0,y0);g_x(x0,y0) g_y(x0,y0)];
ijac=inv(jac);
xx=double([x0;y0]-ijac*[f(x0,y0);g(x0,y0)]);
%error in each
loop
err(c)=norm(xx-[x0;y0]);
%iteration count
it(c)=c;
x0=double(xx(1));
y0=double(xx(2));
fprintf('After %d
iteration\n',c)
fprintf('\t
x=%.12f\ty=%.12f\n',x0,y0)
end
fprintf('\nNR solution for solution of equation is x=%.12f
y=%.12f.\n',xx(1),xx(2))
fprintf('------------------------------------------------------------\n\n')
%initial guess for Newton Raphson
x0=0.5;y0=-0.5;
fprintf('For initial guess x=%f and y=%f.\n',x0,y0)
err=1; c=0;
%loop for Newton Raphson Algorithm
while err>10^-12
c=c+1;
%Jacobian of equation of
2 variable
jac=[f_x(x0,y0)
f_y(x0,y0);g_x(x0,y0) g_y(x0,y0)];
ijac=inv(jac);
xx=double([x0;y0]-ijac*[f(x0,y0);g(x0,y0)]);
%error in each
loop
err(c)=norm(xx-[x0;y0]);
%iteration count
it(c)=c;
x0=double(xx(1));
y0=double(xx(2));
fprintf('After %d
iteration\n',c)
fprintf('\t
x=%.12f\ty=%.12f\n',x0,y0)
end
fprintf('\nNR solution for solution of equation is x=%.12f
y=%.12f.\n',xx(1),xx(2))
fprintf('------------------------------------------------------------\n\n')
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%