image thumbnail

Find real roots (or zeros) of a continuous function

version 1.0.0 (2.96 KB) by Lawrence Agbezuge
This program finds the real roots (or zeros) of a continuous function.

20 Downloads

Updated 10 Jan 2020

View License

This program finds the real roots (or zeros) of continuous functions.
This is useful for finding the roots of polynomials, or of transcendental equations.
When too many roots are found in a specified domain, the domain may be shrunk so that the roots are found in a piecemeal fashion.
There should not be extraneous roots, but should they occur, they may be identified from the plot of the function.

Example 1:
f(x) = sin(x*cos(x)), in the domain x = [-20 20].
The domain is specified as -20:20.
Because 93 roots are found, in a piecemeal fashion, use these domains: -20:-15; -15:-10; -10:0; 0:10; 10:15; and 15:20.

Example 2:
f(x) = sin(x)/x (the sinc function), in the domain -20:20.
All roots in the specified domain are displayed.

Example 3:
f(x) = besselj(1,x) (the Bessel function of the first kind, order 1), in the domain -40:40.
All roots in the specified domain are displayed.

Example 4:
f(x) = x^5 – x^4 – 3*x^3 + 7*x^2 – 2*x – 5 in the domain -2.5:2.
All 3 real roots are displayed.
According to Descartes’ rule of signs, we should have 3 or 1 positive roots, and 2 or 0 negative roots.

Cite As

Lawrence Agbezuge (2021). Find real roots (or zeros) of a continuous function (https://www.mathworks.com/matlabcentral/fileexchange/73880-find-real-roots-or-zeros-of-a-continuous-function), MATLAB Central File Exchange. Retrieved .

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!