Solving cubic polynomials: Difference between revisions
No edit summary |
No edit summary |
||
| Line 31: | Line 31: | ||
(cubic2.subs(y,z-p/(3*z)) * z**3).expand() | (cubic2.subs(y,z-p/(3*z)) * z**3).expand() | ||
solve((cubic2.subs(y,z-p/3/z) * z**3).expand().subs(z**3,Z),Z) | solve((cubic2.subs(y,z-p/3/z) * z**3).expand().subs(z**3,Z),Z) | ||
P,Q = symbols('P,Q') | |||
solve((cubic2.subs(y,z-p/3/z) * z**3).expand().subs(z**3,Z),Z)[0].subs(p,3*P).subs(q,2*Q).factor() | |||
solve((cubic2.subs(y,z-p/3/z) * z**3).expand().subs(z**3,Z),Z)[1].subs(p,3*P).subs(q,2*Q).factor() | |||
</source> | </source> | ||
[[Category:Miscellany]] | [[Category:Miscellany]] | ||
Revision as of 02:57, 30 June 2022
There are many sources for how to solve cubic polynomials, but a summary is helpful when implementing a new code. This page is an attempt to record that.
We will consider the polynomial
- <math> x^3 + a x^2 + b x + c = 0 </math>
First, calculate the coefficients of the 'depressed cubic' <math>y^3 + p y - q = 0</math> obtained by the substitution <math>x = y - a/3</math>:
- <math>p = b - \frac{a^2}{3}</math>
- <math>q = \frac{2}{27} a^3 - \frac{1}{3} ab + c</math>
This can then be converted into a quadratic in <math>z^3</math> via the 'magic' Vieta substitution <math>y = z - \frac{p}{3 z}</math>,
- <math>\left(z^3\right)^2 - q \left(z^3\right) - \left(\frac{p}{3}\right)^3 = 0</math>
for which the solution is
- <math>z^3 = +\frac{q}{2} \pm \sqrt{\left(\frac{q}{2}\right)^2 + \left(\frac{p}{3}\right)^3}</math>
Firstly, it is possible that <math>p</math> and <math>q</math> equal zero, implying that <math>z^3 = 0</math> hence <math>y = p</math>
Invalid language.
You need to specify a language like this: <source lang="html">...</source>
Supported languages for syntax highlighting:
a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn