Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.47 KB | None | 0 0
  1. function [root] = bisect(func,Xlow,Xup,XTol)
  2.  
  3. Flow = feval(func, Xlow);
  4. Fup = feval(func, Xup);
  5.  
  6. if Flow*Fup > 0
  7.     disp('oops');
  8.     return
  9. end
  10.  
  11. Xguess = ((Xup + Xlow)/2);
  12. Fguess = feval(func, (Xguess));
  13.  
  14. while abs((Xup-Xlow)/Xup) > XTol
  15.     if Flow*Fguess > 0
  16.         Xlow = (Xguess);
  17.         Flow = Fguess;
  18.     else
  19.         Xup  = (Xguess);
  20.         Fup = Fguess;
  21.     end
  22.     Xguess = ((Xup + Xlow)/2);
  23.     Fguess = feval(func, Xguess);
  24. end
  25. root = (Xguess);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement