From: David Wilson on
Hi all,
I'm trying to find the roots of a single variable equation with discontinuites, something like adding a "round()" to a smooth function and getting a staircase trend.

fzero works OK, but fsolve returns the cryptic error:

Optimization stopped.
Unrecognized exitflag input to createExitMsg.

presumably because it has difficulty in constructing the numerical derivatives. I've tried the various algorithmic options in fsolve, but they all return the same sorts of errors.

So two questions:
(1) Can I encourage fsolve to have a go at these sorts of functions, or am I stuck with the cruder fzero.m?

(2) How can I get a better understanding of the error message from fsolve.m?


For those interested, here is a toy problem illustrating the difficulties:
myF = @(x) 10*(cos(x/3) - atan(x)+1) % nice smooth function
myS = @(x) round(myF(x)); % staircased

x = linspace(0,10,1e4)';
plot(x,[myF(x), myS(x)] )

xtrial = [2];
xr = fzero(myF,xtrial) % no problems here of course
xr2 = fzero(myS,xtrial) % OK
xr3 = fsolve(myS,xtrial) % cryptic error

David.
From: John D'Errico on
"David Wilson" <wizwilson(a)gmail.com> wrote in message <htv2n4$bdd$1(a)fred.mathworks.com>...
> Hi all,
> I'm trying to find the roots of a single variable equation with discontinuites, something like adding a "round()" to a smooth function and getting a staircase trend.
>
> fzero works OK, but fsolve returns the cryptic error:
>
> Optimization stopped.
> Unrecognized exitflag input to createExitMsg.
>
> presumably because it has difficulty in constructing the numerical derivatives. I've tried the various algorithmic options in fsolve, but they all return the same sorts of errors.
>
> So two questions:
> (1) Can I encourage fsolve to have a go at these sorts of functions, or am I stuck with the cruder fzero.m?
>
> (2) How can I get a better understanding of the error message from fsolve.m?
>
>
> For those interested, here is a toy problem illustrating the difficulties:
> myF = @(x) 10*(cos(x/3) - atan(x)+1) % nice smooth function
> myS = @(x) round(myF(x)); % staircased
>
> x = linspace(0,10,1e4)';
> plot(x,[myF(x), myS(x)] )
>
> xtrial = [2];
> xr = fzero(myF,xtrial) % no problems here of course
> xr2 = fzero(myS,xtrial) % OK
> xr3 = fsolve(myS,xtrial) % cryptic error
>
> David.

Sigh. fzero is not cruder. In fact, for one variable, fzero
is a more intelligent solver than fsolve, since it understands
more about your function, restricted as it is to one
dimension. fsolve is more general, capable of solving
problem in multiple dimensions, but it will not be as
robust as is fzero.

For problems with one variable, I would ALWAYS
choose fzero over fsolve.

John
 | 
Pages: 1
Prev: modelling binary psk31 system
Next: row operation