Cannot find Multiple Roots using Bisection

3 次查看(过去 30 天)
Function 1:
function f = example1( x, oldroots)
Bi = 0.5;
f = 1-x*cot(x)-Bi;;
if length( oldroots ) > 0 ,
f = f / polyval( poly ( oldroots ), x );
end
Function 2:
function x = findallzeros( fhandle, xguess, maxroots)
x = [ ] ;
if nargin==1
xguess =0;
maxroots = 1;
end
if nargin==2
maxroots = 1;
end
nroots = 0;
while nroots<maxroots
if abs(feval(fhandle,xguess,[ ]))<=1e-16,
xroot=xguess;
else
[xroot,val,flag] = fzero(fhandle,xguess,[ ],x);
if flag <= 0
return
end
end
x=[x,xroot];
nroots=nroots+1;
xguess=xguess+0.01;
end
Problem:
Cannot seem to adapt this code to finding all the roots in a given region (0 < x =< 15) for my defined function, f.
It will only display one root in that interval, or two if I manually change the initial "guess". Any thoughts?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by