Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I solve a fifth degree polynomial in C++ [closed]

I have a quintic function (5th degree polynomial) and I would like to solve it in C++. Is there an implementation or a math library I can use in order to proceed?

like image 630
topless Avatar asked Sep 30 '12 10:09

topless


3 Answers

Boost has this. Have a look here:

http://www.boost.org/doc/libs/1_51_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals1/roots2.html http://www.boost.org/doc/libs/1_51_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/polynomials.html

Description

These functions solve the root of some function f(x) without the need for the derivatives of f(x). The functions here that use TOMS Algorithm 748 are asymptotically the most efficient known, and have been shown to be optimal for a certain classes of smooth functions.

Alternatively, there is a simple bisection routine which can be useful in its own right in some situations, or alternatively for narrowing down the range containing the root, prior to calling a more advanced algorithm.

Unfortunately these libraries are not beginner friendly, and I could not yet find an example on how to use them. Answer delivered as-is for now. For now, have a look here http://programmingexamples.net/wiki/CPP/Boost/Math/Tools/TOMS748

You should be able to plug in a boost polynomial instead of t.

like image 173
Johan Lundberg Avatar answered Oct 14 '22 20:10

Johan Lundberg


I have a quintic function (5th degree polyonimial) and I would like to solve it in C++.

There's a problem here, a rather famous one. There's a simple solution to quadratic equations. Cubic equations are a bit tougher. One way to solve them analytically is via Cardano's method. Quartic equations are tougher yet, but still can be solved analytically.

And that's where it ends. There is no formula for the roots of a fifth degree polynomial equation (or higher) that can be written in terms of the coefficients of the polynomial and only uses the standard algebraic operations. An entire branch of mathematics, Galois theory, resulted from one of the proofs that a general purpose analytic solution for quintics does not exist.

What that means is that you will have to resort to numerical root finding techniques.

like image 42
David Hammen Avatar answered Oct 14 '22 21:10

David Hammen


Maybe this can solve your problem: http://www.gnu.org/software/gsl/manual/html_node/General-Polynomial-Equations.html

like image 3
user711413 Avatar answered Oct 14 '22 20:10

user711413