Code covered by the BSD License  

Highlights from
Real roots on interval

4.5

4.5 | 2 ratings Rate this file 13 Downloads (last 30 days) File Size: 2.78 KB File ID: #15122

Real roots on interval

by Stephen Morris

 

26 May 2007 (Updated 29 May 2007)

Find all real roots of an arbitrary function over an arbitrary interval

| Watch this File

File Information
Description

This routine uses an analytical method to find all the real roots of an arbitrary function over an arbitrary interval. The approach used is to approximate the function by a series of Chebyshev polynomials, and then to find the roots of the approximation using a very efficient analytical method due to J.P. Boyd [see Appl. Num. Math. 56 pp.1077-1091 (2006)].

In the form given here, the function for which roots must be found is supplied as a MATLAB anonymous function. For example:

 FindRealRoots(@(x) besselj(1,x),a,b,n)

...will find all the real roots of the function besselj(1,x) over the interval [a,b] based on an n-element Chebyshev expansion. At the end of the routine, as well as the calculated roots, the routine gives the time taken plus a plot of the original function and its approximation over the required interval: if the two do not coincide then the user should try again with a larger value of 'n'.

Acknowledgements

Real Roots On Interval inspired this file.

This file inspired Real Roots On Interval.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
analytical, approximation, chebyshev, interpolation, real, roots
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
02 Jun 2011 Slobodan Milovanovic

@ Nicholas: You probably didn't put the function file in the same folder as your .m file from which you are calling the function...

@Stephen: Do you know any other algorithms for finding all of the roots on the interval?

25 Nov 2010 Nicholas Tan

Hi, i used this program to solve my equations but i couldn't get the roots. Could you please help me to identify any mistakes that i have made? Thank you in advance.

JRa= @(y) besselj(1,y);
JR1a= @(y) besselj(0, y) - besselj(1, y)./y;

JRb= @(y) besselj(1,z);
JR1b= @(y) besselj(0, z) - besselj(1, z)./z;

Yb= @(y) bessely(1,z);
Y1b= @(y) bessely(0, z) - bessely(1, z)./z;

Ya= @(y) bessely(1,y);
Y1a= @(y) bessely(0, y) - bessely(1, y)./y;

r=@(y) y.*((JR1a.*Y1b-JR1b.*Y1a)./(JRa.*Y1b-JR1b.*Ya));
u=FindRealRoots(r,0,10,10)

The errors are as follows:
??? Undefined function or method 'times' for input arguments of type 'function_handle'.

Error in ==> @(y)y.*((JR1a.*Y1b-JR1b.*Y1a)./(JRa.*Y1b-JR1b.*Ya))

Error in ==> FindRealRoots>chebft at 73
f(k)=funhandle((y*bma)+bpa); % depend on funhandle being a

Error in ==> FindRealRoots at 14
c=chebft(funhandle,a,b,n);

Contact us