Cannot find Multiple Roots using Bisection
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!