*To*: mathgroup@smc.vnet.net*Subject*: [mg11181] Re: [mg11131] Possible bug in FindRoot[] in Mathematica 3.0*From*: David Withoff <withoff@wolfram.com>*Date*: Wed, 25 Feb 1998 03:31:51 -0500

> Hi there, > I think I've possibly found a bug in Mathematica 3.0. Consider the > equation: > > 2^x + 3^x = 5^x > > Well, it's obvious that x = 1 is a solution, and you can check with > Plot[] that x = 1 is indeed the only solution. When I try to Solve[] > this with Mathematica, it says: > > Solve::"tdep": > "The equations appear to involve transcendental functions of the \ > variables in an essentially non-algebraic way." > > This is fair enough - I have no idea how to solve this type of equation > without some numerical method either. The problem comes when I try to > use FindRoot: > > In[83]:= FindRoot[2^x+3^x==5^x,{x,0}] Out[83]:= {x -> -21.1781} > > -21? I'm sorry? Obviously, the iterative formula it has created > (presumably by the Newton-Raphson process) for the equation diverges > when the starting point is taken as x = 0. However, if I do something > like this, it handles it correctly: > > In[86]:= FindRoot[2^x+3^x==5^x,{x,-1}] FindRoot::"cvnwt": > "Newton's method failed to converge to the prescribed accuracy after > \ > 15 iterations." > Out[86]:= {x -> -21.0059} > > So, why does Mathematica correctly recognise that the iterative sequence > does not converge in the second case, yet it doesn't recognise this in > the first case and thus returns a totally bogus result without any > error message? > > This looks like a bug to me. Or am I just missing something here? > > Thanks, cheers, > Adrian Cable. Well, no, this isn't a bug, but this behavior should probably be changed anyway. Any purely numerical algorithm, no matter how clever, can always be fooled. On the other hand, since it is possible with a bit of work to change FindRoot so that it is fooled less often, it would be good to make some improvements here regardless of whether or not this is a bug. FindRoot looks for a value of the variable such that the difference between the right-hand side of the equation and the left-hand side of the equation is less than 10^-n, where n is the value of the AccuracyGoal option. With the default WorkingPrecision of 16, the default value of AccuracyGoal is 6. The result from FindRoot in this example is correct in the sense that it satisfies that specification. In[1]:= sol = FindRoot[2^x+3^x==5^x,{x,0}] Out[1]= {x -> -21.1781} In[2]:= 2^x+3^x - 5^x /. sol -7 Out[2]= 4.21538 10 If you raise the value of AccuracyGoal, then FindRoot will generate a warning message, but if the number of iterations is also raised, the message will again go away. In[3]:= FindRoot[2^x+3^x==5^x,{x,0}, AccuracyGoal -> 10] FindRoot::cvnwt: Newton's method failed to converge to the prescribed accuracy after 15 iterations. Out[3]= {x -> -25.5059} In[4]:= FindRoot[2^x+3^x==5^x,{x,0}, AccuracyGoal -> 10, MaxIterations -> 100] Out[4]= {x -> -34.162} It is good to be careful about this sort of thing with any root-finding algorithm. It is always possible for a purely numerical algorithm to return bogus results without warning. There are, however, several ways of reducing the chances of getting a bogus result that will probably be incorporated into future versions of the FindRoot function. Dave Withoff Wolfram Research