Azzera filtri
Azzera filtri

Cannot find Multiple Roots using Bisection

1 visualizzazione (ultimi 30 giorni)
James
James il 7 Mar 2012
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?

Risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by