Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. function [ outpoints ] = myNewtonRaphson( )
  2. x = rand(2,1);
  3. G = Grad(x);
  4. points = [];
  5. points = [points,x];
  6. while ( norm(G) >= eps )
  7. G = Grad(x);
  8. H = Hesj(x);
  9. x = x - inv(H)* G;
  10. points = [points, x];
  11. end
  12.  
  13. outpoints = points;
  14.  
  15. function [ res ] = Hesj(x)
  16. res = [2+1200*x(1)^2-400*x(2) -400*x(1); -400*x(1) 200];
  17.  
  18. function [ res ] = Grad(x)
  19. g1 = -2+2*x(1)-400*(x(2)-x(1)^2)*x(1);
  20. g2 = 200*x(2)-200*x(1)^2;
  21. res = [g1 g2]';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement