Question
in matlab

sthat this n is hardly different from the scalar version in Section 4.3 . The root estimates are stored as columns in an arra
Suppose one wants to findthe points on the ellipsoid x2/25+y2/16+-2/9= 1 that are closest to and farthest from the point (5,4
multipliers implies that any such point satisfes gran 25 16 Az 25 16 9 for an unknown value of X (a) Write out this system in
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab code for system of equations clear all close all All initial guess for x1 %solution using newton systems x = newtonsys%function for jacobian and residual function ty,j1- f(xl) Y (2,1) - x1(2)-4-(x1(4)*x1 (2))/16, y(3,1x1(3)-3-(x1 (4)x1 (3))/9Let 丁

%Matlab code for system of equations
clear all
close all

%All initial guess for x1

x1=[5;4;3;1];
%solution using newton systems
x = newtonsys(@(x1) f(x1),x1);
fprintf('For initial guess x=%2.2f , y=%2.2f ,z= %2.2f and lambda=%2.2f\n',...
    x1(1),x1(2),x1(3),x1(4))

fprintf('\nroot of the equation is x=%2.2f , y=%2.2f ,z= %2.2f and lambda=%2.2f\n',...
    x(1,end),x(2,end),x(3,end),x(4,end))


x1=[50;40;30;100];
%solution using newton systems
x = newtonsys(@(x1) f(x1),x1);
fprintf('\n\nFor initial guess x=%2.2f , y=%2.2f ,z= %2.2f and lambda=%2.2f\n',...
    x1(1),x1(2),x1(3),x1(4))

fprintf('\nroot of the equation is x=%2.2f , y=%2.2f ,z= %2.2f and lambda=%2.2f\n',...
    x(1,end),x(2,end),x(3,end),x(4,end))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Matlab function for Newton system
function x = newtonsys(f,x1)

    funtol = 1000*eps; xtol = 1000*eps; maxitr=40;
    x =x1(:);
    [y,j]=f(x1);
    dx=Inf;
    k=1;
    while (norm(dx) > xtol) && (norm(y)> funtol) && (k< maxitr)
      
        dx= -(j\y);
        x(:,k+1) = x(:,k) + dx;
        k=k+1;
      
        [y, j]= f(x(:,k));
    end
    if k==maxitr
        warning('Maximum number of iterations reached.')
    end
  
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function for jacobian and residual
function [y,j]= f(x1)

    y(1,1) = x1(1)-5-(x1(4)*x1(1))/25;
    y(2,1) = x1(2)-4-(x1(4)*x1(2))/16;
    y(3,1) = x1(3)-3-(x1(4)*x1(3))/9;
    y(4,1) = (((x1(1)).^2)/25)+(((x1(2)).^2)/16)+(((x1(3)).^2)/9)-1;
  
    j=[1-((x1(4))/25) 0 0 (-x1(1))/25;...
        0 1-((x1(4))/16) 0 (-x1(2))/16;...
        0 0 1-((x1(4))/9) (-x1(3))/9;...
        (2*x1(1))/25 (2*x1(2))/16 (2*x1(3))/9 0];
end

  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   

Add a comment
Know the answer?
Add Answer to:
in matlab sthat this n is hardly different from the scalar version in Section 4.3 . The root estimates are stored as columns in an array . The Newton step is calculated using a backslash. The fu...
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