A Python module for the exact solutions of a cubic equation
Project description
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)
Commandline
python -m cubicequation
- Help: python -m cubicequation -h
- Cubic solution: python -m cubicequation 1 2 3 4
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cubicequation-0.0.1.tar.gz.
File metadata
- Download URL: cubicequation-0.0.1.tar.gz
- Upload date:
- Size: 26.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e01cdb600d6b0f7a6e34f06940d4a815776e06d1eadfdc2aa729acc16890e76
|
|
| MD5 |
2f0a436ce88fb91ccb29b3e869fef378
|
|
| BLAKE2b-256 |
4f067da8bc39b3d74bd8e0ff13814565fef5e642137c06b985e4f244005f1459
|
File details
Details for the file cubicequation-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cubicequation-0.0.1-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26d10d34c7e06d9f31ef6fe13347ce0b680fb7bcf9adac1a93391270acf5a8fc
|
|
| MD5 |
4e106da2b7991b6fa0e6e8ad011469fa
|
|
| BLAKE2b-256 |
56f6b5ee2a62b126aca8e6f89d99f840a969f119a8e2945140bc5477510bcd3b
|