in reply to solve cubic equations
import math def cubic(a,b,c): q = a*a/9 - b/3 r = (a*a/27 - b/6)*a + c/2 s = a/-3 d = r*r - q*q*q if d > 0: t = (math.sqrt(d) + abs(r)) ** (1/3) u = (t + q/t) return s - u if r > 0 else s + u else: t = math.atan2(math.sqrt(-d), r) / 3 u = 2 * math.sqrt(q) return ( s - u * math.cos(t), s - u * math.cos(t + 2/3*math.pi), s - u * math.cos(t - 2/3*math.pi) ) print( cubic(10,10,-10) )
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: solve cubic equations (Python)
by no_slogan (Deacon) on May 03, 2017 at 16:40 UTC | |
by vrk (Chaplain) on May 04, 2017 at 07:57 UTC | |
by no_slogan (Deacon) on May 04, 2017 at 13:37 UTC | |
by choroba (Cardinal) on May 04, 2017 at 15:59 UTC | |
by no_slogan (Deacon) on May 05, 2017 at 06:49 UTC | |
| |
by no_slogan (Deacon) on May 04, 2017 at 17:04 UTC | |
| |
by Anonymous Monk on May 03, 2017 at 16:43 UTC | |
by LanX (Saint) on May 04, 2017 at 23:16 UTC | |
| |
Re^2: solve cubic equations (Python)
by Anonymous Monk on May 05, 2017 at 15:59 UTC | |
by LanX (Saint) on May 05, 2017 at 17:56 UTC | |
by no_slogan (Deacon) on May 05, 2017 at 18:43 UTC | |
by LanX (Saint) on May 05, 2017 at 18:47 UTC | |
by no_slogan (Deacon) on May 05, 2017 at 18:54 UTC | |
| |
by Anonymous Monk on May 05, 2017 at 18:31 UTC | |
by Anonymous Monk on May 05, 2017 at 16:03 UTC |