Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function [k, approximate_error] = bisection()
  2. cn=[1,-1,-2];
  3. a = 1.5;
  4. b = 5;
  5. x0 = (a+b)/2;
  6. k = 0;
  7.  
  8. while(x0~= 2)
  9. if(polyval(cn,x0)*polyval(cn,a)<0)
  10. x0 = (a+x0)/2;
  11. end
  12. if(polyval(cn,x0)*polyval(cn,b)<0)
  13. x0=(b+x0)/2;
  14. end
  15. k = k + 1,
  16. approximate_error(k) = abs(x0 - 2) /2,
  17. end
  18. x0,
  19.  
  20. x = -1.5:0.01:5;
  21. y = polyval(cn,x);
  22. figure(1)
  23.  
  24. plot(x,y)
  25. grid on;
  26. hold on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement