Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function p = Newton(p0,TOL,N)
- i=1;
- while i <= N
- p=p0-(f(p0)/d(p0));
- if abs(p-p0)<=TOL
- disp(['The error is less than the given tolerance after ' num2str(i) ' iterations'])
- return
- end
- disp(p)
- i=i+1;
- p0=p;
- end
- disp(['The method failed after' num2str(N) ' iterations'])
- end
- function y = f(x)
- y = 2.7*(1+x)^(-361)-1;
- end
- function g = d(x)
- g = 2.7*(-361)*(1+x)^(-362);
- end
- function p=fixedpoint(p0, TOL, N)
- n=1;
- while n<=N
- p=g(p0);
- if norm(p-p0,inf)<TOL
- n;
- disp(['The error is less than the given tolerance after ' num2str(n) ' iterations'])
- return
- end
- n=n+1;
- p0=p;
- end
- disp(['The method failed after ' num2str(N) ' iterations'])
- function y=g(x)
- y=(3^(-x));
Add Comment
Please, Sign In to add comment