Re: Better Root Finder [message #53390] |
Sun, 15 April 2007 17:01  |
wlandsman@jhu.edu
Messages: 12 Registered: September 2006
|
Junior Member |
|
|
<jschwab@gmail.com> wrote in message
news:1176669683.157908.311410@b75g2000hsg.googlegroups.com.. .
> On Apr 15, 12:55 am, "Max Watson" <max...@gmail.com> wrote:
>> IDL's fx_root seems very limited; when I want to find the root of say
>> x^3 - 8 with the initial guess vector [-1,-100,100], IDL returns a
>> complex number: ( -1.00000, 1.73205). Is there a way that
>> fx_root can be easily modified so that it can find the right answer
>> with a bad initial guess?
I think that the previous suggestion of using FZ_ROOTS if you have a
polynomial, or is the way to go, but in the off-chance that you are only
interested in cubic polynomial equations, as in your example, *and* you are
only interested in the (one or three) real roots, then this can be solved
analytically, e.g.
http://idlastro.gsfc.nasa.gov/ftp/contrib/freudenreich/cuber oot.pro
IDL> print, (cuberoot([-8,0,0,1]))(0)
2.0000000
If you don't have any type of polynomial, but you know that a real root
exists, then you can also find the zero using zbrent.pro in
http://idlastro.gsfc.nasa.gov/ftp/pro/math/zbrent.pro to find the root
numerically to within a specified tolerance.
--Wayne
|
|
|