Post Reply 
(35S) Smart quadratic equation solver with complex roots
05-06-2017, 10:36 AM (This post was last modified: 06-15-2017 01:15 PM by Gene.)
Post: #1
(35S) Smart quadratic equation solver with complex roots
Yet another quadratic solver, but I love mine because:
- it preserves all the variables of the calculator
- it uses only the stack (input and output)
- it computes real or complex roots
- it displays a text notifying if there are 1 or 2 real roots, or 2 complex roots

Equation is of the form: a.x² + b.x + c = 0
Determinant is: delta = b² - 4.a.c

Stack before the program:
Z: a
Y: b
X: c

Run the program: XEQ Q
It first shortly displays one of the following messages:
    SINGLE ROOT
    2 REAL ROOTS
    2 CPLX ROOTS

Stack after:
T: b
Z: delta (determinant)
Y: x1 (first root)
X: x2 (second root)

Code of the solver:

Code:

Q001 LBL Q
Q002 SQ(REGY)-4*REGZ*REGX    CK=E203 LN=20
Q003 x<>y
Q004 Rdown
Q005 x!=0?
Q006 GTO Q014
Q007 SF 10
Q008 SINGLE ROOT    CK=230E LN=11
Q009 PSE
Q010 CF 10
Q011 -REGY/REGZ/2    CK=5AC5 LN=12
Q012 ENTER
Q013 RTN
Q014 x<0?
Q015 GTO Q023
Q016 SF 10
Q017 2 REAL ROOTS    CK=9C4D LN=12
Q018 PSE
Q019 CF 10
Q020 (-REGY+SQRT(REGX))/REGZ/2    CK=2A08 LN=25
Q021 (-REGZ-SQRT(REGY))/REGT/2    CK=E499 LN=25
Q022 RTN
Q023 SF 10
Q024 2 CPLX ROOTS
Q025 PSE
Q026 CF 10
Q027 (-REGY+SQRT(-REGX)*i)/REGZ/2    CK=1DFA LN=28
Q028 (-REGZ-SQRT(-REGY)*i)/REGT/2    CK=D662 LN=28
Q029 RTN

CK=75AA LN=260


To check the code:

2.x²+3.x+4=0
2 ENTER 3 ENTER 4 XEQ Q ENTER
should give:

2 CPLX ROOTS
Z: -23.0000
Y: -0.7500 i 1.1990
X: -0.7500 i -1.1990


2.x²+7.x+3=0
2 ENTER 7 ENTER 3 XEQ Q ENTER
should give:

2 REAL ROOTS
Z: 25.0000
Y: -0.5000
X: -3.0000


2.x²-12.x+18=0
2 ENTER 12 +/- ENTER 18 XEQ Q ENTER
should give:

SINGLE ROOT
Z: 0.0000
Y: 3.0000
X: 3.0000
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)