Question
Show it in Matlab. thx!
5. Formulate Newtons method for the system x = y v = Note that this system has three real roots (-1,-1), (0,0) and (1,1). By
0 0
Add a comment Improve this question Transcribed image text
Answer #1


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 ijac=inv(jac); xx-double([x0;yo ]-ijac*[ f(x0,70);9(x0, y0)]); $error in each loop err(c)=norm(xx-[x0;y0]); literation countx=-1.000908451943 y=-1.000908451943 After 5 iteration x=-1.000001235309 y=-1.000001235309 After 6 iteration x=-1.000000000002

%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 %%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Show it in Matlab. thx! 5. Formulate Newton's method for the system x = y v...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT