cubic solver
|
07-04-2024, 08:37 PM
(This post was last modified: 07-06-2024 03:20 PM by Albert Chan.)
Post: #10
|
|||
|
|||
Quarter Solver
We can use same trick (post #8) to depress quartic, a*x^4 + b*x^3 + c*x^2 + d*x + e = 0
{a, b, c, d, e} = {(A = 4a), 4b, 4c, 4d, 4e} = {1, 4b, 4Ac, 4A²d, 4A³e} / A Synthetic Division to force coefficient 4b to 0 Code: -b> 1 4b 4Ac 4A²d 4A³e {a, b, c, d, e} = ({1, 0, C, D, E} - b) / A y^4 + C*y^2 + D*y + E = 0 (y^2+s)^2 = (2s-C)*y^2 - D*y + (s^2-E) // Add an offset s, making LHS perfect square Let k² = 2s-C ≠ 0, and force RHS as perfect square too. {(k² = 2s-C), -D, (s²-E)} = {1, -D, (D²/4 = (s²-E)*k²)} / k² D² = 4*(s²-E)*k² = ((k²+C)² - 4E) * k² (k²)^3 + 2*C*(k²)^2 + (C²-4E)*(k²) - D² = 0 The reason we solve for k² instead of s is to easily check k²≠0 k² roots all zero ⇒ {C,D,E} all zeroes ⇒ y roots all zero too. (y²+s)² = k² * (y-(D/2)/k²)² // let t = D/2/k (y²+s) = ±(k*y - t) (y^2 - ky + s+t) * (y^2 + ky + s-t) = 0 (s±t), one of them may cause huge cancellation, we only use the good one. The other can be derived by product of all roots = (s+t) * (s-t) = E Last step is simply map y back to x: (x roots) = ((y roots) - b) / A Code: function quartic(a,b,c,d,e) -- a*x^4 + b*x^3 + c*x^2 + d*x + e = 0 lua> quartic(1,2,3,4,5) (0.28781547955764775+1.4160930801719083*I) (-1.287815479557648+0.8578967583284901*I) (0.2878154795576481-1.4160930801719085*I) (-1.287815479557648-0.8578967583284899*I) |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
cubic solver - Albert Chan - 09-08-2023, 02:26 PM
RE: cubic solver - Albert Chan - 09-08-2023, 02:44 PM
RE: cubic solver - parisse - 09-08-2023, 06:56 PM
RE: cubic solver - Albert Chan - 06-29-2024, 02:46 PM
RE: cubic solver - Albert Chan - 06-29-2024, 03:29 PM
RE: cubic solver - Albert Chan - 07-02-2024, 02:34 PM
RE: cubic solver - Albert Chan - 07-02-2024, 05:12 PM
RE: cubic solver - Albert Chan - 07-03-2024, 10:17 PM
RE: cubic solver - Albert Chan - 07-03-2024, 11:48 PM
Quarter Solver - Albert Chan - 07-04-2024 08:37 PM
|
User(s) browsing this thread: 6 Guest(s)