Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function xc = bisect(f, a, b, tol)
- fa=f(a);
- fb=f(b);
- if sign(fa)*sign(fb) >= 0
- error('f(a)f(b) not satisfied!')
- end
- while (b - a) / 2 > tol
- c = (a+b)/2;
- fc = f(c);
- if fc == 0
- break
- end
- if sign(fc) * sign(fa) < 0
- b = c;
- else
- a = c;
- fa = fc;
- end
- end
- xc = (a + b) / 2;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement