Hello,
When run on Octave 4.0.0 on a W7 machine the following piece of
code:
%--------------------------------------------------------
function raizes3
format long;
options = optimset('TolX',1.0e-15,'TolFun',1.0e-15);
xi = [0.1:0.5:5.0];
for xguess = xi
[x,fval] = fsolve(@f,xguess,options)
fprintf('\n');
end
end
function y = f(x)
y = x*tan(x) - 42.0;
end
%--------------------------------------------------------
produces the results shown below:
x = 1.53428203880513
fval = 2.04636307898909e-012
x = 1.53428203880513
fval = 2.04636307898909e-012
x = 1.53428203880513
fval = -4.97379915032070e-014
x = 4.60322412114047
fval = -7.38964445190504e-013
x = 4.60322412114047
fval = -7.38964445190504e-013
x = 4.60322412114047
fval = -3.55271367880050e-014
x = 4.60322412114047
fval = -3.55271367880050e-014
x = 7.67327748954486
fval = 2.27373675443232e-013
x = 4.60322412114047
fval = -3.55271367880050e-014
x = 4.60322412114047
fval = -3.55271367880050e-014
As one can see the two existing roots of y = x*tan(x) - 42 in the interval
0.1 <= x <= 5.0 were found more than once: 1.534... was found thrice while
4.603... was found _six_ times -- as if fsolve were iterating back & forth
around a particular root so that it was found several times.
But the most curious part of the whole process comes right after fsolve()
finds the root x = 7.673... (at this point root x = 4.603... had already
been found four times): fsolve() identifies x = 4.603 as a root another two
extra times when I for one would have expected the root-finding process to
have stopped at x = 7.673...
I wonder why this happens. y = x*tan(x) - C certainly isn't the most well-
behaved of the functions as it shows sharp, up-and-down spikes too often.
But the strange behaviour described in the paragraph right above has no
clear explanation (to me at least).
What's your take on this?
Regards,
Fausto