In: Advanced Math
Using Matlab
1. Solve the following equations set
f1 (x1,x2) = sin (sin (x1)) +x2
f2 (x1,x2) = x1+ e^(x2)
a) Can this equation set be solved by the fixed - point method with the following expressions? And why? Show your analysis with a 2D graph.
g1 (x1,x2) = -e^(x2)
g2 (x1,x2) = -sin(x1)
b) Use Newton Raphson Method with initial values x1 = -2, x2 = 1.5. (8 significant figures. Please submit the code and results.)
%Matlab code for solving nonliear equations using Newton
method
clear all
close all
%function for fixed point iterations
g1=@(x1,x2) -exp(x2);
g2=@(x1,x2) -sin(x1);
%plotting both functions
xx1=linspace(-3,3);
yy1=linspace(0,3);
[X,Y]=meshgrid(xx1,yy1);
G1=g1(X,Y);
G2=g2(X,Y);
hold on
surf(X,Y,G1)
surf(X,Y,G2)
shading interp
xlabel('X1')
ylabel('X2')
zlabel('g')
view(3)
box on
fprintf('As the two plots never touch each other, hence fixed point
is not possibel.\n')
%Newton method
syms x y
%functions for which intersection have to find
f(x,y)=sin(x)+y;
g(x,y)=x+exp(y);
%Displaying the equation
fprintf('The equations are\n')
disp(f)
disp(vpa(g,2))
%creating Jacobian matrix
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);
%Jacobian matrix
jac1=[f_x f_y; g_x g_y];
%displaying the Jacobian Matrix
fprintf('\tThe Jacobian Matrix is \n\n')
disp(vpa(jac1,2))
x1=-2;y1=1.5;
conv=10^-10;
%loop for Newton iterations
err=1;k=0;
fprintf('For initial condition x=%f and y=%f
\n',x1,y1)
cnt=0;
while err>conv
cnt=cnt+1;
jac=[f_x(x1,y1)
f_y(x1,y1);g_x(x1,y1) g_y(x1,y1)];
ijac=inv(jac);
uu=double([x1;y1]-ijac*[f(x1,y1);g(x1,y1)]);
%uu=double([x1;y1]-0.5*jac*[f(x1,y1);g(x1,y1)]);
err=norm(uu-[x1;y1]);
x1=double(uu(1));
y1=double(uu(2));
fprintf('After %d
iteration \n',cnt)
fprintf('\tX=%.8f and
Y=%.8f \n',x1,y1)
end
fprintf('\n\n Convergence for order =%.2e
occured after %d iteration\n',conv,cnt)
fprintf('\tThe root occured at x=%f,
y=%f\n\n',x1,y1)
%%%%%%%%%%%%%%%%%%%%%%end of code %%%%%%%%%%%%%%%%%%%%%%%%%%%