Skip to main content

Python cubic equation solver for exact values

A Python module for the exact solutions of a cubic equation: a x^3 + b x^2 + c x + d = 0

Usage

Calculate cubic solution

The solutions are three symexpress3 objects: x1Optimized, x2Optimized, x3Optimized

>>> import cubicequation
>>> objCubic = cubicequation.CubicEquation()
>>> objCubic.a = "1"
>>> objCubic.b = "2"
>>> objCubic.c = "3"
>>> objCubic.d = "4"
>>> objCubic.calcSolutions()
>>> print( f"x1: {objCubic.x1Optimized}\nx2: {objCubic.x2Optimized}\nx3: {objCubic.x3Optimized}\n" )
x1: (-2/3) + (15 * 6^^(1/2) + 35)^^(1/3) * (-1/3) + (1/3) * (15 * 6^^(1/2) + (-35))^^(1/3)
x2: (-2/3) + (1/6) * (15 * 6^^(1/2) + 35)^^(1/3) + (-1/6) * (15 * 6^^(1/2) + 35)^^(1/3) * i * 3^^(1/2) + (-1/6) * i * 3^^(1/2) * (15 * 6^^(1/2) + (-35))^^(1/3) + (-1/6) * (15 * 6^^(1/2) + (-35))^^(1/3)
x3: (-2/3) + (15 * 6^^(1/2) + 35)^^(1/3) * (1/6) + (15 * 6^^(1/2) + 35)^^(1/3) * i * 3^^(1/2) * (1/6) + (1/6) * i * 3^^(1/2) * (15 * 6^^(1/2) + (-35))^^(1/3) + (-1/6) * (15 * 6^^(1/2) + (-35))^^(1/3)

Numeric input values

The parameters may be real numbers or symexpress3 strings

>>> import cubicequation
>>> objCubic = cubicequation.CubicEquation()
>>> objCubic.a = 1.10
>>> objCubic.b = 2.25
>>> objCubic.c = "2 + 1 + 3"
>>> objCubic.d = "4/2"
>>> objCubic.calcSolutions()
>>> print( f"x1: {objCubic.x1Optimized}\nx2: {objCubic.x2Optimized}\nx3: {objCubic.x3Optimized}\n" )
x1: (-15/22) + (-5/11) * ((11/25) * (3373/2)^^(1/2) + (-1349/200))^^(1/3) + (5/11) * ((11/25) * (3373/2)^^(1/2) + (1349/200))^^(1/3)
x2: (-15/22) + (5/22) * ((11/25) * (3373/2)^^(1/2) + (-1349/200))^^(1/3) + (-5/22) * i * 3^^(1/2) * ((11/25) * (3373/2)^^(1/2) + (-1349/200))^^(1/3) + (-5/22) * i * 3^^(1/2) * ((11/25) * (3373/2)^^(1/2) + (1349/200))^^(1/3) + (-5/22) * ((11/25) * (3373/2)^^(1/2) + (1349/200))^^(1/3)
x3: (-15/22) + (5/22) * ((11/25) * (3373/2)^^(1/2) + (-1349/200))^^(1/3) + (5/22) * i * 3^^(1/2) * ((11/25) * (3373/2)^^(1/2) + (-1349/200))^^(1/3) + (5/22) * i * 3^^(1/2) * ((11/25) * (3373/2)^^(1/2) + (1349/200))^^(1/3) + (-5/22) * ((11/25) * (3373/2)^^(1/2) + (1349/200))^^(1/3)

Calculate real values

>>> import cubicequation
>>> objCubic = cubicequation.CubicEquation()
>>> objCubic.a = 1.10
>>> objCubic.b = 2.25
>>> objCubic.c = "2 + 1 + 3"
>>> objCubic.d = "4/2"
>>> objCubic.calcSolutions()
>>> print( f"x1: {objCubic.x1Value}\nx2: {objCubic.x2Value}\nx3: {objCubic.x3Value}\n" )
x1: -0.3767589142748171
x2: (-0.8343478155898642-2.0321695851742962j)
x3: (-0.8343478155898642+2.0321695851742962j)

Example optimized exact values

>>> import cubicequation
>>> objCubic = cubicequation.CubicEquation()
>>> objCubic.a = 1
>>> objCubic.b = 6
>>> objCubic.c = 11
>>> objCubic.d = 6
>>> objCubic.calcSolutions()
>>> print( f"x1: {objCubic.x1Optimized}\nx2: {objCubic.x2Optimized}\nx3: {objCubic.x3Optimized}\n" )
x1: (-3)
x2: (-1)
x3: (-2)

Command line

python -m cubicequation

  • Help: python -m cubicequation -h
  • Cubic solution: python -m cubicequation 1 2 3 4

Graphical user interface

https://github.com/SWVandenEnden/websym3

Metadata

Release files for cubicequation 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cubicequation 0.0.5
File Size Uploaded Provenance Actions
cubicequation-0.0.5.tar.gz 27.2 kB Without provenance Details for cubicequation-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cubicequation 0.0.5
File Interpreter ABI Platform Actions
cubicequation-0.0.5-py3-none-any.whl Python 3 none any Details for cubicequation-0.0.5-py3-none-any.whl

Total release size: 47.7 kB

Release files / cubicequation-0.0.5.tar.gz

Download URL cubicequation-0.0.5.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
decc8c60aff66e874b2988f992bf50340c3ed9f921d9e8d13b5706210c529fa9
BLAKE2b-256 checksum
How to use checksums
98050b6b1bfe34da2a6c7a42fbcbd881b43884d6bb532c7f00bd598a1108ffef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / cubicequation-0.0.5-py3-none-any.whl

Download URL cubicequation-0.0.5-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7579acb4e7a9c5bec9c1a7bd5aed83c0b64f3bd8fc4fc15be4d15f6071259caa
BLAKE2b-256 checksum
How to use checksums
a0220937c7b3da2d68159955e509f24f5d5698ef0594ddac013993cd454fd547
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for cubicequation 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page