Advertisement
ruhan008

Newton Raphson

Aug 22nd, 2024
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.26 KB | None | 0 0
  1. function x = newtonRaphson(x0, n)
  2.    
  3.     if g(x0) == 0
  4.         error('The function has derivative  zero at x0')
  5.     end
  6.  
  7.     x = x0;
  8.  
  9.     for i = 1 : n
  10.  
  11.         if g(x) == 0
  12.             break;
  13.         end
  14.  
  15.         x = x - (f(x) / g(x));
  16.     end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement