Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function p=Bisection(a, b, TOL, N)
- if sign(f(a))*sign(f(b))>0
- disp('Error:f(a) and f(b) have the same sign')
- return
- end
- i=1;
- while i<=N
- p=a+(b-a)/2;
- if abs(f(p))<=eps || (b-a)/2<TOL
- disp(['The error is less than the given tolerance after ' num2str(i) ' iterations'])
- return
- end
- if sign(f(a))*sign(f(p))>0
- a=p;
- else
- b=p;
- end
- disp(p)
- i=i+1;
- end
- disp(['The method failed after ' num2str(N) ' iterations'])
- function y =f(x)
- y = 2.7*(1+x)^(-361)-1;
- function y=f(x)
- y=x^(4)-2*x^(3)-12*x^(2)+16*x-40;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement