Mads Jeppe Tarp-Johansen
2010-Jan-05 15:11 UTC
[R] solving cubic/quartic equations non-iteratively
To R-helpers, R offers the polyroot function for solving mentioned equations iteratively. However, Dr Math and Mathworld (and other places) show in detail how to solve mentioned equations non-iteratively. Do implementations for R that are non-iterative and that solve mentioned equations exists? Regards, Mads Jeppe
Stavros Macrakis
2010-Jan-05 16:16 UTC
[R] solving cubic/quartic equations non-iteratively
There are certainly formulas for solving polynomials numerically up to 4th degree non-iteratively, but you will almost certainly get better results using iterative methods. Even the much more trivial formula for the 2nd degree (quadratic) is tricky to implement correctly and accurately, see: * George Forsythe, How do you solve a quadratic equation? * Yves Nievergelt, How (Not) to Solve Quadratic Equations Hope this helps. -s On Tue, Jan 5, 2010 at 10:11 AM, Mads Jeppe Tarp-Johansen < s02mjtj@math.ku.dk> wrote:> To R-helpers, > > R offers the polyroot function for solving mentioned equations iteratively. > > However, Dr Math and Mathworld (and other places) show in detail how to > solve mentioned equations non-iteratively. > > Do implementations for R that are non-iterative and that solve mentioned > equations exists? > > Regards, Mads Jeppe > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Mads Jeppe Tarp-Johansen wrote:> To R-helpers, > > R offers the polyroot function for solving mentioned equations iteratively. > > However, Dr Math and Mathworld (and other places) show in detail how to > solve mentioned equations non-iteratively. > > Do implementations for R that are non-iterative and that solve mentioned > equations exists?As far as I know, we don't even have the quadratic... They can't be hard to implement, though. However, you may need to take care that non-iterative solutions are not necessarily more precise or even faster than iterative ones. There may be cancellation issues and the closed-form expressions can be complicated and involve slow function calls. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
quote: There are certainly formulas for solving polynomials numerically up to 4th degree non-iteratively, but you will almost certainly get better results using iterative methods. endquote I must be missing something here. Why not use the analytic formulas for polynomials below 5th degree? Once you do so, your answer is as precise as the level of precision you enter for the coefficients.