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
|
|
|
Re: Better Root Finder [message #53392 is a reply to message #53390] |
Sun, 15 April 2007 13:41   |
jschwab@gmail.com
Messages: 30 Registered: December 2006
|
Member |
|
|
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 wouldn't say that fx_root is limited from that example; it is
finding (one of) the correct (complex) solutions.
If you are only solving polynomial equations and need to get all the
real solutions, you could try fz_roots, which gives you all of the
solutions to a given polynomial. Then pick off the real solutions, or
whatever your desired "right answer" is.
I wouldn't say that's necessarily the best solution, but it's
certainly one of the easiest.
|
|
|
Re: Better Root Finder [message #53522 is a reply to message #53390] |
Mon, 16 April 2007 12:17  |
mmeron
Messages: 44 Registered: October 2003
|
Member |
|
|
In article <31zUh.663$0S1.610@trnddc01>, "Wayne Landsman" <wlandsman@jhu.edu> writes:
>
> <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.
>
Or, if you think you may have more than one real root, you can use my
ROOT routine and try to get them all.
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
|
|
|