Re: How Many Users Are Happy With FindRoot?

• To: mathgroup at smc.vnet.net
• Subject: [mg49169] Re: [mg49150] How Many Users Are Happy With FindRoot?
• From: "Janos D. Pinter" <jdpinter at hfx.eastlink.ca>
• Date: Tue, 6 Jul 2004 03:33:33 -0400 (EDT)
• References: <200407050854.EAA14774@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Colleagues,

as I mentioned in several recent postings, nonlinear equations (even more
so, systems of such equations) can be tricky... In particular, they may
have no solutions, or a multitude of solutions, and anything in between.
Furthermore, we may not always have a good guess to initialize search for
the root(s). (FindRoot, similarly, to FindMinimum, is based on local search
methodology.) If one wishes to search for roots globally on a given
interval (in R^n, n>=1), then e.g. NMinimize or my third party packages
(MathOptimizer and MathOptimizer Professional) can be used to do that.
Consult, e.g., my book 'Global Optimization in Action', Ch. 4.1. for
technical details.

This note is of course, not to contradict to what David says: rather, added
information that some of you may find useful.

Regards,

Janos Pinter
www.pinterconsulting.com

At 05:54 AM 7/5/2004, you wrote:
>Dear MathGroup,
>
>I am continually being frustrated with the usage and performance of
>FindRoot. Consider the problem of finding the roots lying between -3 Pi
>and 3 Pi of the following function.
>
>f[x_] = Tan[x] - (x/2)^2*Tanh[x];
>
>If we plot the function we can see why FindRoot runs into difficulty.
>
>Plot[f[x], {x, -3*Pi, 3*Pi}, Frame -> True,
>    Axes -> {True, False}, PlotRange -> {-15, 15}];
>
>If we pick starting values that are close enough we obtain the actual roots.
>
>FindRoot[f[x], {x, {-7.5, -4, 2, 4, 7.5}}]
>{x -> {-7.78813, -4.51891, 0., 4.51891, 7.78813}}
>
>But I object to having to pick the initial values that closely. This is
>not convenient and should not be necessary. If we pick the starting values
>to just be in the middle of each branch, we only obtain one correct root
>out of five.
>
>FindRoot[f[x], {x, {-2*Pi, -Pi, 0, Pi, 2*Pi}}]
>{x -> {-4.51891, 0., 0., 0., 4.51891}}
>
>With the algorithm that Mathematica uses there is no reason we should
>expect any better. The root searching is jumping from branch to branch. So
>let's confine it to a single branch. We obtain an error message and an
>
>FindRoot[f[x], {x, -2*Pi, -5*(Pi/2), -3*(Pi/2)}]
>{x -> -5.36881}
>
>It appears that in being ambitious enought to handle complex roots and
>multiple equations FindRoot has skimped on finding real roots of real
>equations. Mathematica should use more adaptive methods, perhaps using
>bisection or other methods to locate roots in a fixed region. One should
>not even have to give a starting point. These are probably the most common
>applications of FindRoot and we should expect better performance.
>
>There is a solution. There is a package in MathSource,
>Enhancements`RootSearch`, by Ted Ersek. It is far better at handling roots
>of real expressions.
>
>Needs["Enhancements`RootSearch`"]
>
>RootSearch[f[x] == 0, {x, -3*Pi, 3*Pi}]
>{{x -> -7.78813}, {x -> -4.51891}, {x -> 0.}, {x -> 4.51891}, {x -> 7.78813}}
>
>This shouldn't be buried away in MathSource. It should be part of
>Mathematica proper, on an equal par with FindRoot. It should be the user's
>first choice for finding real roots of real equations. One shouldn't spend
>time fumbling with FindRoot and then searching outside Mathematica proper
>for a solution.
>
>David Park