adria_junyent

Example code Netwon-Raphson MATLAB

Oct 18th, 2019
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.44 KB | None | 0 0
  1. clear;
  2. f=@(x1,x2) [2*x1^2+x2^2-8;x1^2-x2^2+x1*x2-4];
  3. Delta=@(x1,x2) -([4*x1,2*x2;2*x1+x2,x1-2*x2]^(-1))*f(x1,x2);
  4.  
  5. x=zeros(10,2);
  6. x(1,:)=[1,1];
  7.  
  8. clc
  9. disp(['sol.: x1=' num2str(x(1,1)) ', x2=' num2str(x(1,2)) ' error left: ' num2str(norm(f(x(1,1),x(1,2))))]);
  10.  
  11. for n=2:length(x)
  12.     x(n,:)=x(n-1,:)+Delta(x(n-1,1),x(n-1,2))';
  13.     disp(['sol.: x1=' num2str(x(n,1)) ', x2=' num2str(x(n,2)) ' error left: ' num2str(norm(f(x(n,1),x(n,2))))]);
  14. end
Advertisement
Add Comment
Please, Sign In to add comment