|
From: | Fausto Arinos de A. Barbuto |
Subject: | Re: fsolve shows repeated results |
Date: | Fri, 16 Oct 2015 20:56:30 +0000 (UTC) |
On Fri, Oct 16, 2015 at 3:54 PM, Fausto Arinos de A. Barbuto <address@hidden> wrote:Hello,When run on Octave 4.0.0 on a W7 machine the following piece ofcode:%--------------------------------------------------------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-014As one can see the two existing roots of y = x*tan(x) - 42 in the interval0.1 <= x <= 5.0 were found more than once: 1.534... was found thrice while4.603... was found _six_ times -- as if fsolve were iterating back & fortharound 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 alreadybeen found four times): fsolve() identifies x = 4.603 as a root another twoextra times when I for one would have expected the root-finding process tohave 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 noclear explanation (to me at least).What's your take on this?Regards,Fausto
_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave
You ask it to find a root 10 different times and then it did that and gave you 10 answers.Why are you surprised?Doug--
[Prev in Thread] | Current Thread | [Next in Thread] |