Re: How Many Users Are Happy With FindRoot?
- To: mathgroup at smc.vnet.net
- Subject: [mg49170] Re: [mg49150] How Many Users Are Happy With FindRoot?
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Tue, 6 Jul 2004 03:33:35 -0400 (EDT)
- References: <200407050854.EAA14774@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 5 Jul 2004, at 17:54, David Park wrote: > *This message was transferred with a trial version of CommuniGate(tm) > Pro* > 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 incorrect answer. > > 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 > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > > I agree that Ted's package is nice, but Mathematica already included means of solving this sort of problem, e.g. << "NumericalMath`IntervalRoots`" f[x_] = Tan[x] - (x/2)^2*Tanh[x]; IntervalBisection[f[x], x, Interval[{-3*N[Pi], 3*N[Pi]}], 0.1, MaxRecursion -> 10] Interval[{-7.8048942487621495, -7.7312631709436355}, {-4.565126824747676, -4.491495746929162}, {-0.07363107781851091, 0.07363107781851091}, {4.491495746929162, 4.565126824747676}, {7.7312631709436355, 7.8048942487621495}] Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/
- References:
- How Many Users Are Happy With FindRoot?
- From: "David Park" <djmp@earthlink.net>
- How Many Users Are Happy With FindRoot?