From: Ivan Werning on
I need to find the zero of a function, many times, actually, within a loop, in my code. I am looking to improve the performance.

Is there any reason that minimizing the square of a function (using fminbnd say) could ever perform better than the search for a zero (using fzero say).

-Ivan
From: Matt J on
"Ivan Werning" <iwerningl(a)yahoo.com> wrote in message <hnqr5h$gl7$1(a)fred.mathworks.com>...
> I need to find the zero of a function, many times, actually, within a loop, in my code. I am looking to improve the performance.
>
> Is there any reason that minimizing the square of a function (using fminbnd say) could ever perform better than the search for a zero (using fzero say).
==============

Off the top of my head, fminbnd doesn't require that f(x1) and f(x2) be of opposite sign, where [x1,x2] is the search interval.

fzero does require this and therefore may require extra computational effort.
From: John D'Errico on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hnqrtd$sth$1(a)fred.mathworks.com>...
> "Ivan Werning" <iwerningl(a)yahoo.com> wrote in message <hnqr5h$gl7$1(a)fred.mathworks.com>...
> > I need to find the zero of a function, many times, actually, within a loop, in my code. I am looking to improve the performance.
> >
> > Is there any reason that minimizing the square of a function (using fminbnd say) could ever perform better than the search for a zero (using fzero say).
> ==============
>
> Off the top of my head, fminbnd doesn't require that f(x1) and f(x2) be of opposite sign, where [x1,x2] is the search interval.
>
> fzero does require this and therefore may require extra computational effort.

NO! NO. NO. This advice is completely wrong.

Fzero does NOT require a bracket around the root.

Fzero works better if you give it a bracket, since
this assures a solution as long as your function is
continuous.

fzero(@sin,2)
ans =
3.14159265358979

On the other hand, fminbnd DOES require a
bracket, i.e., a pair of points that define the search
interval. So effectively, fminbnd is the routine that
needs a bracket!

There are other reasons to avoid the use of fminbnd
here. By squaring the objective, you may limit the
accuracy you can ever achieve in the root.

John
From: Matt J on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hnqtjq$s0v$1(a)fred.mathworks.com>...
> "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hnqrtd$sth$1(a)fred.mathworks.com>...
> > "Ivan Werning" <iwerningl(a)yahoo.com> wrote in message <hnqr5h$gl7$1(a)fred.mathworks.com>...
> > > I need to find the zero of a function, many times, actually, within a loop, in my code. I am looking to improve the performance.
> > >
> > > Is there any reason that minimizing the square of a function (using fminbnd say) could ever perform better than the search for a zero (using fzero say).
> > ==============
> >
> > Off the top of my head, fminbnd doesn't require that f(x1) and f(x2) be of opposite sign, where [x1,x2] is the search interval.
> >
> > fzero does require this and therefore may require extra computational effort.
>
> NO! NO. NO. This advice is completely wrong.
>
> Fzero does NOT require a bracket around the root.


It doesn't require it, but what if you are only interested in solutions in a particular interval?

Additionally, suppose you are interested in finding a root in a particular interval where you know the function doesn't change sign? fminbnd may be your only option (admittedly, though, you wouldn't have to square the function in that case).
From: John D'Errico on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hnqufr$dvv$1(a)fred.mathworks.com>...

> > Fzero does NOT require a bracket around the root.
>
>
> It doesn't require it, but what if you are only interested in solutions in a particular interval?

This is not an argument for fminbnd, but really an
argument for fzero in this situation.

fzero can happily work in either mode. fminbnd
REQUIRES a bracket. So fzero is more flexible here.

And given that fminbnd will potentially be less
accurate, there are few reasons why one might
choose that option.


> Additionally, suppose you are interested in finding a root in a particular interval where you know the function doesn't change sign? fminbnd may be your only option (admittedly, though, you wouldn't have to square the function in that case).

If there is a zero at a point where the function
does not change sign, then squaring it is a very
bad move. This point is a multiple root already,
so squaring it will cause a further loss of precision
in the root finding operation.

IF you are confident that the function truly has a
multiple root at a point (a root of specifically even
multiplicity), then use of fminbnd WITHOUT
squaring the function makes some sense, but only
in that fairly limited scenario.

Understand your problem, as well as the tools that
you use to solve it.

John