How can I solve two non linear equation with Newton_Raphson method?

1 view (last 30 days)
Hello,
I am very new user of Matlab. I am facing problem to solve the following equation.
F(x,y) = x^2+2y^2-4=0 G(x,y) = xy-1=0
the code I have written,
%% Input initial value
x=2;
y=0;
Tolerance = 0.00001;
Error_max = 100 ;
%% Iteration
count = 0; while Error_max > Tolerance count = count + 1;
f1=x^2+2*y^2-4; f2=x*y-1; % Jacobian matrix J(1,1)= 2*x; J(2,1)= y ; J(1,2)= 4*y; J(2,2)= x;
f(x,y)=[x^2+2*y^2-4;x*y-1]; %% format long %
xnyn = [x;y]- J(x,y)\f(x,y) ;
xn=xnyn(1); yn=xnyn(2);
Error = abs((xnyn -[x;y])/[x;y] ) ;
Error_max= Error;
Result(count,1)=x; Result(count,2)=y; x=xnyn(1); y=xnyn(2);
Result(count,4)=Jd;
Result(count,5)=xn;
Result(count,6)=yn;
end
%%Print Results
xn=num2str(xn);
yn=num2str(yn);
disp (count)
disp (xn)
disp (yn)
--------------------------------------------------------------------------------------- when I run the code, it gives me this message : >> newton_raphson_2eq Subscript indices must either be real positive integers or logicals.
Error in newton_raphson_2eq (line 30) f(x,y)=[x^2+2*y^2-4;x*y-1];
Can anyone please help me to solve this problem?
Thanks in advance.
Tanjina

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!