help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fsolve shows repeated results


From: Fausto Arinos de A. Barbuto
Subject: Re: fsolve shows repeated results
Date: Fri, 16 Oct 2015 20:56:30 +0000 (UTC)


Doug,

Right, but I'm still lost as for how fsolve() goes back to root x = 4.603...
after root x = 7.673... had been found. Notice that the last element in list/
vector xi = [0.1:0.5:5.0] is 4.6. Then it is reasonable that root 4.603... be
found for the 6th and last time right before the for-loop (and the execution
as well) ends. But why 7.673... is found and then 4.603... once again?

Fausto





On Friday, October 16, 2015 5:16 PM, Doug Stewart <address@hidden> wrote:




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 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



_______________________________________________
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
--
DASCertificate for 206392




reply via email to

[Prev in Thread] Current Thread [Next in Thread]