| TUsolveCubic | TCL UTILITIES USER MANUAL | TUsolveCubic |
|---|
| set |
[TUsolveCubic  |
| A | - | The coefficient of the cubic term in the equation. |
| B | - | The coefficient of the quadratic term in the equation. |
| C | - | The coefficient of the linear term in the equation. |
| D | - | The constant term in the equation. |
| rV | - | Solutions of the equation as a list. If the list length is 3 there are three real solutions. If the list length is 5 then there is one real solution and 2 imaginary solutions. Imaginary solutions are stored as the two real components followed by the two imaginary components. The single real solution is always the first in the list. |
Ax3 + Bx2 + Cx + D = 0
The roots are returned through the list variable rV. When the roots
are real rV has the form:
set rV [list R1 R2 R3]
with R1 being the minumum root value and R3 the maximum root value.
When there are imaginary roots rV has the form:
set rV [list R1 R2 R3 I2 I3]
set A 5.0
set B 2.0
set C 10.0
set D -1.0
set rV [TUsolveCubic $A $B $C $D]
if { [llength $rV] == 3 } {
puts stderr "REAL SOLUTIONS"
puts stderr " S1 = [lindex $rV 0]"
puts stderr " S2 = [lindex $rV 1]"
puts stderr " S3 = [lindex $rV 2]"
} else {
puts stderr "REAL SOLUTION"
puts stderr " S1 = [lindex $rV 0]"
puts stderr "IMAGINARY SOLUTIONS"
if { [lindex $rV 3] < 0.0 } { set SgN - } else { set SgN + }
puts stderr " S2 = [lindex $rV 1] $SgN i[expr abs([lindex $rV 3])]"
if { [lindex $rV 4] < 0.0 } { set SgN - } else { set SgN + }
puts stderr " S3 = [lindex $rV 2] $SgN i[expr abs([lindex $rV 4])]"
}
> REAL SOLUTION
> S1 = 0.0976284722457
> IMAGINARY SOLUTIONS
> S2 = -0.248814236123 + i1.40949430059
> S3 = -0.248814236123 - i1.40949430059
Setting C to -10.0 gives the result:
> REAL SOLUTIONS
> S1 = -1.58336053902
> S2 = -0.0985364793555
> S3 = 1.28189701838
| Apr 17, 2003 |
|---|