Cannot find Multiple Roots using Bisection
조회 수: 2 (최근 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
답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!