File Exchange

image thumbnail

Bisection Method Root Finding

version 1.15 (3.74 KB) by Sky Sartorius
Very simple to use and robust method that takes array inputs, so it even has advantages over fzero.

150 Downloads

Updated 20 Feb 2019

View License

BISECTION is a fast, simple-to-use, and robust root-finding method that handles n-dimensional arrays.

Additional optional inputs and outputs for more control and capabilities that don't exist in other implementations of the bisection method or other root finding functions like fzero.
This function really shines in cases where fzero would have to be implemented in a loop to solve multiple cases, in which case this will be much faster.

It can find zero or non-zero roots.

This code can be a bit cryptic. This is for the sake of speed and increased capability. See the many acknowledged other submissions for simpler, easier-to-follow implementations to understand the basics of the bisection method.

Cite As

Sky Sartorius (2019). Bisection Method Root Finding (https://www.mathworks.com/matlabcentral/fileexchange/28150-bisection-method-root-finding), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (20)

tbaracu: The function requires at least three inputs, e.g. bisection(@cos,-3,3).

tbaracu

It doesn't work:

>> bisection
Not enough input arguments.

Error in bisection (line 115)
ub_in = ub; lb_in = lb;

robert

Tim DeWolf

Great Function!!!

Thomas

praydz 96

MK

Herbert

Ole

If there are several root in the interval does it find the first closes to LB only ?

Chi-Fu

great program, saved me a lot of time, thank you!

The vectorization feature is really really helpful. I was vexed with having to put fzero into for loops.

Works brilliantly in my case. Replaces a loop with ~1 million iterations, brings down execution time by several orders of magnitude.
Plus it is well-written and well-documented and a numerically robust method.

Fabian

Excellent file. Much faster than using fzero in a long loop!

Siegmar W

Thanks! Had a similar file of my own, but yours is better!

I am so glad I found this submission and I'm very grateful to the author for providing an excellent, well-documented code. I had my custom Newton-Raphson algorithm (with provided analytical gradient) invoked thousands of times inside a for loop. I substituted the loop with a single invocation to bisection.m and achieved a 15x acceleration! Awesome.

I just uploaded an entirely new function with almost all new code and documentation and a lot of added features. With so much new code, please let me know if you find a bug.

This is about as far as I'll take this function. I would love to see MathWorks or someone in the community develop a vectorized implementation of Brent's method, i.e. make FZERO vectorized to be able handle array problems. A vectorized FZERO (with a TolFun feature) would be superior to this in every way.

Yoshiaki

There seems to be a typo on line 80:
jnk = f(UB+LB)/2; % test if f returns multiple outputs

It should be
f((UB+LB)/2)

Matthew

Excellent documentation with example. Simple function that works as advertised.

Updates

1.15

Initialization of variables in parent function to avoid warnings in newer versions of Matlab.

1.14.0.0

Description.

1.13.0.0

Small changes to help.

1.12.0.0

minor speed and formatting improvements

1.11.0.0

New tagline

1.9.0.0

Practically all new code and documentation with added features. A good deal of testing done, but with so much new code, please let me know if you find errors.

1.8.0.0

fixed bug that sometimes caused premature convergence; redid funcntion halding to get rid of one of the input checks and simplify the code and make it more understandable; changed some of the help documentation

1.7.0.0

fixed a bug that was very rarely throwing out some valid results

1.6.0.0

made it possible to handle a function that returns array results for scalar input; changed help a bit and added an example for new awesome feature

1.5.0.0

better example, fixed some help typos, tested in 2012b

1.2.0.0

Vectorized; fixed bug for decreasing functions; some check

1.1.0.0

Vectorized

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux