UF6

Newton\Fixed Point

UF6
Oct 6th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.83 KB | None | 0 0
  1. function p = Newton(p0,TOL,N)
  2. i=1;
  3. while i <= N
  4.     p=p0-(f(p0)/d(p0));
  5.     if abs(p-p0)<=TOL
  6.         disp(['The error is less than the given tolerance after ' num2str(i) ' iterations'])
  7.         return
  8.     end
  9.     disp(p)
  10.     i=i+1;
  11.     p0=p;
  12. end    
  13. disp(['The method failed after' num2str(N) ' iterations'])
  14. end
  15. function y = f(x)        
  16.         y = 2.7*(1+x)^(-361)-1;
  17. end
  18. function g = d(x)
  19.         g = 2.7*(-361)*(1+x)^(-362);
  20. end
  21.        
  22.  
  23. function p=fixedpoint(p0, TOL, N)
  24.   n=1;
  25.   while n<=N
  26.       p=g(p0);
  27.       if norm(p-p0,inf)<TOL
  28.           n;
  29.           disp(['The error is less than the given tolerance after ' num2str(n) ' iterations'])
  30.           return
  31.       end
  32.       n=n+1;
  33.       p0=p;
  34.   end
  35.   disp(['The method failed after ' num2str(N) ' iterations'])
  36.     function y=g(x)
  37.         y=(3^(-x));
Add Comment
Please, Sign In to add comment