Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [k, approximate_error] = bisection()
- cn=[1,-1,-2];
- a = 1.5;
- b = 5;
- x0 = (a+b)/2;
- k = 0;
- while(x0~= 2)
- if(polyval(cn,x0)*polyval(cn,a)<0)
- x0 = (a+x0)/2;
- end
- if(polyval(cn,x0)*polyval(cn,b)<0)
- x0=(b+x0)/2;
- end
- k = k + 1,
- approximate_error(k) = abs(x0 - 2) /2,
- end
- x0,
- x = -1.5:0.01:5;
- y = polyval(cn,x);
- figure(1)
- plot(x,y)
- grid on;
- hold on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement