fsolve shows repeated results

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

fsolve shows repeated results

fbarbuto

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
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

Doug Stewart-4


On Fri, Oct 16, 2015 at 3:54 PM, Fausto Arinos de A. Barbuto <[hidden email]> 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
[hidden email]
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


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

stevedave0454
Fausto,

I'm just picking up Octave after having used Matlab years ago, so I'm not really an expert, you'll want to check this for yourself.

The lines:

xi = [0.1:0.5:5.0];
    
    for xguess = xi

Tell Octave to make an array xi that is [0.1,0.6,1.1,1.6,2.1,2.6,3.1,3.6,4.1,4.6] and then run a for-loop for each of those values.  Since you are giving it 10 different starting points, it is naturally going to return different values for a periodic function like x*tan(x).

Steven 

On Fri, Oct 16, 2015 at 3:16 PM, Doug Stewart <[hidden email]> wrote:


On Fri, Oct 16, 2015 at 3:54 PM, Fausto Arinos de A. Barbuto <[hidden email]> 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
[hidden email]
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


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

fbarbuto
In reply to this post by Doug Stewart-4

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 <[hidden email]> wrote:




On Fri, Oct 16, 2015 at 3:54 PM, Fausto Arinos de A. Barbuto <[hidden email]> 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
[hidden email]
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




_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

RE: fsolve shows repeated results

John Guin

You could write your loop like this:

function raizes3

    format long;
    options =  optimset('TolX',1.0e-15,'TolFun',1.0e-15);

          [x,fval] = fsolve(@f, 0.10000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 0.60000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 1.10000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 1.60000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 2.10000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 2.60000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 3.10000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 3.60000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 4.10000,options)

fprintf('\n');

[x,fval] = fsolve(@f, 4.60000,options)
       
end

function y = f(x)
    y = x*tan(x) - 42.0;
end

 

 

So your code computes the roots for 0.1 and prints the results, then 0.6, then 1.1, etc… until all 10 calls are made.  It’s just odd looking in that the roots have the same values for different inputs.  Each time the y function is called, it has no “memory” of the previous call – it computes the roots using the new value passed to it each time.

 

These 2 lines in your original code start a loop:

    xi = [0.1:0.5:5.0];
   
    for xguess = xi

 

And then the code just computes the new root for each new loop variable.

 

Does this make a little more sense now?

 

John

 

 

From: help-octave-bounces+johnguin=[hidden email] [mailto:help-octave-bounces+johnguin=[hidden email]] On Behalf Of Fausto Arinos de A. Barbuto
Sent: Friday, October 16, 2015 1:57 PM
To: Doug Stewart <[hidden email]>
Cc: [hidden email]
Subject: Re: fsolve shows repeated results

 

 

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 <[hidden email]> wrote:

 

 

 

On Fri, Oct 16, 2015 at 3:54 PM, Fausto Arinos de A. Barbuto <[hidden email]> 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
[hidden email]
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

 

 


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

nrjank
In reply to this post by fbarbuto


On Fri, Oct 16, 2015 at 4:56 PM, Fausto Arinos de A. Barbuto <[hidden email]> wrote:

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


So, you understand how your code is calling the functions, but the question is why does fsolve lock onto that particular root given that particular initial guess?

I don't know exactly what's going on inside fsolve, rootfinding can be a nontrivial process. throwing darts in the dark, and hoping you hear the sound of cork and not breaking glass...

but assuming it's similar to functions like fzero, the performance of the function will change depending on how close you are to a root. in zero-finding techniques that require an interval, you're usually fairly certain to find the minimum or zero within that interval. but given just one starting point, the algorithm has to guess at a direction and trajectory for its next guess. if the local slope of the curve is low, it may take a very large jump to try and get closer to zero. this may cause it to skip over one zero and latch onto another one.

Plot the curve and mark the points you were starting from. look at the tangent lines at each of those points. It may provide a clue as to why it's doing what it's doing. 

I just went through a nonlinear zero-finding exercise myself, and wound up going with complex-domain solutions so I could guarantee finding all the zeros.

Nick J.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

nrjank
On Fri, Oct 16, 2015 at 5:38 PM, Nicholas Jankowski <[hidden email]> wrote:


On Fri, Oct 16, 2015 at 4:56 PM, Fausto Arinos de A. Barbuto <[hidden email]> wrote:

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


So, you understand how your code is calling the functions, but the question is why does fsolve lock onto that particular root given that particular initial guess?

I don't know exactly what's going on inside fsolve, rootfinding can be a nontrivial process. throwing darts in the dark, and hoping you hear the sound of cork and not breaking glass...

but assuming it's similar to functions like fzero, the performance of the function will change depending on how close you are to a root. in zero-finding techniques that require an interval, you're usually fairly certain to find the minimum or zero within that interval. but given just one starting point, the algorithm has to guess at a direction and trajectory for its next guess. if the local slope of the curve is low, it may take a very large jump to try and get closer to zero. this may cause it to skip over one zero and latch onto another one.

Plot the curve and mark the points you were starting from. look at the tangent lines at each of those points. It may provide a clue as to why it's doing what it's doing. 

I just went through a nonlinear zero-finding exercise myself, and wound up going with complex-domain solutions so I could guarantee finding all the zeros.

Nick J.


ok, I was curious:


>> xf = [0.1:0.5:5];
>> yf = xf.*tan(xf) - 42;
>> x = linspace(0,10,1000);
>> plot(x,x.*tan(x) - 42.0,xf,yf,'r*')

seems to make sense now why one skipped over to the 7.6 value.  it's on a very low slope section of the graph. something in the algorithm made it jump far to the right, and it found itself on a new section to find a new zero. 

Nick J.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

fbarbuto
In reply to this post by stevedave0454
On 16-10-2015 17:47, Steven Davis wrote:

> Fausto,
>
> I'm just picking up Octave after having used Matlab years ago, so I'm not really an expert,
> you'll want to check this for yourself.
>
> The lines:
>
> xi = [0.1:0.5:5.0];
>
>      for xguess = xi
>
> Tell Octave to make an array xi that is [0.1,0.6,1.1,1.6,2.1,2.6,3.1,3.6,4.1,4.6] and then run a
> for-loop for each of those values.  Since you are giving it 10 different starting points, it is
> naturally going to return different values for a periodic function like x*tan(x).
>
> Steven
>

Steven,

As Doug Stewart keenly pointed out, my original code is not at all too clever. I'm
working on a better scheme, now that I figured out what the flaw was. You're right
too -- array values such as 1.6, 2.1, 2.6 etc are all starting values that end up
producing the same root, 4.603... I should've seen this /before/ writing to this
list. My bad.

Thanks for your help.

Fausto




_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

fbarbuto
In reply to this post by John Guin
On 16-10-2015 18:07, John Guin wrote:

> You could write your loop like this:
>
> function raizes3
>
>      format long;
>      options =  optimset('TolX',1.0e-15,'TolFun',1.0e-15);
>
> [x,fval] = fsolve(@f, 0.10000,options)
> fprintf('\n');
> [x,fval] = fsolve(@f, 0.60000,options)
> fprintf('\n');
> [x,fval] = fsolve(@f, 1.10000,options)
> fprintf('\n');
> [x,fval] = fsolve(@f, 1.60000,options)
> fprintf('\n');
> [x,fval] = fsolve(@f, 2.10000,options)
> fprintf('\n');

[...]

> It’s just odd looking in that the roots have the same values for different inputs.

That's because (I reckon) I passed a very small tolerance to fsolve(). Had I used a
tolerance of, say, 1.0e-06 and things would be quite different (and I tried that).

> Does this make a little more sense now?

Yes it does, John. Thanks a lot.

Fausto




_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

fbarbuto
In reply to this post by nrjank
On 16-10-2015 19:04, Nicholas Jankowski wrote:

> ok, I was curious:
>
>
>  >> xf = [0.1:0.5:5];
>  >> yf = xf.*tan(xf) - 42;
>  >> x = linspace(0,10,1000);
>  >> plot(x,x.*tan(x) - 42.0,xf,yf,'r*')
>
> seems to make sense now why one skipped over to the 7.6 value.  it's on a very low slope section
> of the graph. something in the algorithm made it jump far to the right, and it found itself on a
> new section to find a new zero.
>

Like the Newton-Raphson formula, whose 1st derivative f'(x) might intercept f(x) at
a point far away from the actual root, right? Makes total sense. Examining your plot
I observed though that there are other points on the same low-slope section of f(x).
And none 'misbehaved'. There's more in this case than meets the eye, I guess.

Fausto




_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

nrjank

On Oct 16, 2015 7:29 PM, "Fausto Arinos de A. Barbuto" <[hidden email]> wrote:
>
> On 16-10-2015 19:04, Nicholas Jankowski wrote:
>>
>> ok, I was curious:
>>
>>
>>  >> xf = [0.1:0.5:5];
>>  >> yf = xf.*tan(xf) - 42;
>>  >> x = linspace(0,10,1000);
>>  >> plot(x,x.*tan(x) - 42.0,xf,yf,'r*')
>>
>> seems to make sense now why one skipped over to the 7.6 value.  it's on a very low slope section
>> of the graph. something in the algorithm made it jump far to the right, and it found itself on a
>> new section to find a new zero.
>>
>
> Like the Newton-Raphson formula, whose 1st derivative f'(x) might intercept f(x) at
> a point far away from the actual root, right? Makes total sense. Examining your plot
> I observed though that there are other points on the same low-slope section of f(x).
> And none 'misbehaved'. There's more in this case than meets the eye, I guess.
>
>
> Fausto
>

Don't have the help in front of me, but i thought Most of these solvers had an option that would make convergence progression  information available.

Whether it overshoots will be a combination of the local tangent , distance to the zero, size of the step chosen by the algorithm, etc. Since the zero is sitting on the upward slope of that narrow spike, not too surprising that one shoots past.

Bounded methods are usually easier to control if you can Cone up with a good estimate around the root(s)

Nick j.


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fsolve shows repeated results

nrjank


On Oct 16, 2015 7:50 PM, "Nicholas Jankowski" <[hidden email]> wrote:
>
> On Oct 16, 2015 7:29 PM, "Fausto Arinos de A. Barbuto" <[hidden email]> wrote:
> >
> > On 16-10-2015 19:04, Nicholas Jankowski wrote:
> >>
> >> ok, I was curious:
> >>
> >>
> >>  >> xf = [0.1:0.5:5];
> >>  >> yf = xf.*tan(xf) - 42;
> >>  >> x = linspace(0,10,1000);
> >>  >> plot(x,x.*tan(x) - 42.0,xf,yf,'r*')
> >>
> >> seems to make sense now why one skipped over to the 7.6 value.  it's on a very low slope section
> >> of the graph. something in the algorithm made it jump far to the right, and it found itself on a
> >> new section to find a new zero.
> >>
> >
> > Like the Newton-Raphson formula, whose 1st derivative f'(x) might intercept f(x) at
> > a point far away from the actual root, right? Makes total sense. Examining your plot
> > I observed though that there are other points on the same low-slope section of f(x).
> > And none 'misbehaved'. There's more in this case than meets the eye, I guess.
> >
> >
> > Fausto
> >
>
> Don't have the help in front of me, but i thought Most of these solvers had an option that would make convergence progression  information available.
>
> Whether it overshoots will be a combination of the local tangent , distance to the zero, size of the step chosen by the algorithm, etc. Since the zero is sitting on the upward slope of that narrow spike, not too surprising that one shoots past.
>
> Bounded methods are usually easier to control if you can Cone up with a good estimate around the root(s)
>
> Nick j.

Also, I doubt it's misbehaved. It gave you what you asked for, within the bounds provided. If you require more control you'll need to get more hands on in finding the root you want.

Nick J.


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

RE: fsolve shows repeated results

Allen.Windhorn-2
In reply to this post by fbarbuto
Fausto,

> -----Original Message-----
> From: help-octave-bounces
> Like the Newton-Raphson formula, whose 1st derivative f'(x) might
> intercept f(x) at a point far away from the actual root, right? Makes total
> sense. Examining your plot I observed though that there are other points
> on the same low-slope section of f(x).
> And none 'misbehaved'. There's more in this case than meets the eye, I
> guess.

Looking at the graph, I am guessing that this equation was selected as a
pathological case to test the ability of the root finder.  Meaning you, in
this case, not the algorithm :-)  It has an interval near each root where the
value changes sign, even though it does not enclose a root.  This will give
simplistic root-finding algorithms fits, though it apparently doesn't fool
fsolve.

I think the point of the problem is that you should think about what is
happening before blindly feeding the problem into the computer.
Can you change the equation into one that has the same roots, but is
well-behaved?  Hint: tan(x) = sin(x)/cos(x), and cos(x) will never be zero
AT a root (though it always will nearby).

I highly recommend "Numerical Methods that (Usually) Work", by Forman
S. Acton, as a guide to solving this kind of problem.

Regards,
Allen

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave