In: Advanced Math
Using matlab
Find x and y that solve the following system: ln(x 2 + y) = 1 − y , xy = − √ x
%Matlab code for Newton method
clear all
close all
syms x y
%functions for which intersection have to find
f(x,y) = log(x^2+y)+y-1;
g(x,y) = x*y+sqrt(x);
fprintf('Here we will going to use Newton method to find
roots\n\n')
%Displaying the equation
fprintf('The equations are\n')
fprintf('\n\tf(x,y) = ')
disp(f)
fprintf('\n\tg(x,y) = ')
disp(g)
%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=5;y1=5;
fprintf('Newton method for initial guess x=%f and y=%f
\n\n',x1,y1)
fprintf(' for x=%2.2f and y=%2.2f Jacobian matrix is
\n',x1,y1)
disp([f_x(x1,y1) f_y(x1,y1);g_x(x1,y1) g_y(x1,y1)])
%loop for Newton iterations
err=1;k=0;
fprintf('For initial condition x=%f and y=%f
\n',x1,y1)
while err>10^-6
k=k+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)]);
err=norm(uu-[x1;y1]);
x1=double(uu(1));
y1=double(uu(2));
fprintf('\nAfter %d
iterations\n',k)
fprintf('Value of x=%f\t
Value for y=%f\n',x1,y1)
end
fprintf('\n\tThe root of equations using Newton
method occured at x=%f, y=%f\n\n',x1,y1)
%%%%%%%%%%%%%%%%%%%%%%End of Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%