Advertisement
STANAANDREY

mac lab2 bis impl

Feb 26th, 2023 (edited)
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.42 KB | None | 0 0
  1. function xc = bisect(f, a, b, tol)
  2.     fa=f(a);
  3.     fb=f(b);
  4.     if sign(fa)*sign(fb) >= 0
  5.         error('f(a)f(b) not satisfied!')
  6.     end
  7.     while (b - a) / 2 > tol
  8.         c = (a+b)/2;
  9.         fc = f(c);
  10.         if fc == 0
  11.             break
  12.         end
  13.         if sign(fc) * sign(fa) < 0
  14.             b = c;
  15.         else
  16.             a = c;
  17.             fa = fc;
  18.         end
  19.     end
  20.     xc = (a + b) / 2;
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement