Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: solve cubic equations

by vrk (Chaplain)
on May 03, 2017 at 08:02 UTC ( #1189392=note: print w/replies, xml ) Need Help??

in reply to solve cubic equations

It's always fun to implement numerical algorithms, especially when a closed form solution exists. You're missing some roots, though... The fundamental theorem of algebra shows that a polynomial of degree n has exactly n roots, although some (or all) of them can be complex. Your cubic solver finds only the real roots.

By the way, for finding the roots of polynomials of higher degree, there's an iterative solver on CPAN (Math::Polynomial::Solve). You'll need it if you go higher than degree 5.

Replies are listed 'Best First'.
Re^2: solve cubic equations
by no_slogan (Deacon) on May 03, 2017 at 13:43 UTC
    Quite so. If you want the complex roots, use $t multiplied by the three cube roots of unity (1 and -1/2 ± i*sqrt(3)/2) in the first if branch.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1189392]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2023-01-29 19:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found