TUsolveQuadratic TCL UTILITIES USER MANUAL TUsolveQuadratic
SYNOPSIS
Solve a quadratic equation of the form: Ax2 + Bx + C = 0
PACKAGE
TCLUTILS
NAME
TUsolveQuadratic
USAGE
set rV  [TUsolveQuadratic  A B C]
INPUT DEFINITIONS
A - The coefficient of the quadratic term in the equation.
B - The coefficient of the linear term in the equation.
C - The constant term in the equation.
RETURN DEFINITION
rV - Solutions of the equation as a list. If the list length is 2 there are two real solutions. If the list length is 4 then there are 2 imaginary solutions. Imaginary solutions are stored as the two real components followed by the two imaginary components.
DESCRIPTION
TUsolveQuadratic solves for the two roots of the equation:
            Ax2 + Bx + C = 0
      
The roots are returned through the list variable rV. When the roots are real rV has the form:
            set rV [list R1 R2]
      
with R1 being the minumum root value. When the roots are imaginary rV has the form:
            set rV [list R1 R2 I1 I2]
      
ERRORS
None Generated
C BACKING
No
EXAMPLE(S)
set A 5.0
set B 2.0
set C 10.0
set rV [TUsolveQuadratic $A $B $C]
if { [llength $rV] == 2 } {
   puts stderr "REAL SOLUTIONS"
   puts stderr "  S1 = [lindex $rV 0]"
   puts stderr "  S2 = [lindex $rV 1]"
} else {
   puts stderr "IMAGINARY SOLUTIONS"
   if { [lindex $rV 2] < 0.0 } { set SgN - } else { set SgN + }
   puts stderr "  S1 = [lindex $rV 0] $SgN i[expr abs([lindex $rV 2])]"
   if { [lindex $rV 3] < 0.0 } { set SgN - } else { set SgN + }
   puts stderr "  S2 = [lindex $rV 1] $SgN i[expr abs([lindex $rV 3])]"
}

> IMAGINARY SOLUTIONS
>   S1 = -0.2 + i1.4
>   S2 = -0.2 - i1.4

      
Setting C to -10.0 gives the result:

> REAL SOLUTIONS
>   S1 = -1.62828568571
>   S2 = 1.22828568571

      
Apr 17, 2003