フィルターのクリア

Cannot find Multiple Roots using Bisection

1 回表示 (過去 30 日間)
James
James 2012 年 3 月 7 日
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by