Here's an implementation of the bisection method in MATLAB:
main.m1491 chars59 linesYou can call this function with your desired function, lower bound xl, upper bound xu, desired relative error es, and maximum number of iterations maxiter. For example, to find the root of the function f(x) = x^2 - 2 within the bracket [1, 2] with a relative error of 0.1%, you can call the function like this:
main.m119 chars7 lines
which will return the estimated root root, the function value fx at the root, the approximate relative error ea, and the number of iterations iter.
gistlibby LogSnag