HP Forums
(35S ALG) Quadratic Equation Solver (with complex solutions support) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (35S ALG) Quadratic Equation Solver (with complex solutions support) (/thread-3401.html)



(35S ALG) Quadratic Equation Solver (with complex solutions support) - BartDB - 03-17-2015 10:57 AM

Based on this article:
http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=1003

It is a simple program using the traditional quadratic root formula:
$$\frac{-b±\sqrt{b^{2}-4ac}}{2a}$$

the program is converted for use in ALG mode:

Code:

Q001 LBL Q
Q002 CF 10
Q003 INPUT A
Q004 INPUT B
Q005 INPUT C
Q006 -B÷(2×A)       ;the first - is the +/- key
Q007 LASTx STO R    ;LASTx is blue ENTER, a black > will show instead of STO
Q008 B^2-4×A×C      ;using y^x instead of x^2
Q009 x>=0?
Q010 GTO Q015
Q011 -LASTx         ;press +/- key followed by LASTx
Q012 SQRT(LASTx)
Q013 i×LASTx
Q014 GTO Q016
Q015 SQRT(LASTx)
Q016 LASTx÷(2×A)
Q017 R+LASTx
Q018 R-REGY         ;for REGY press Roll Down (E-key) & if necessary underline Y
Q019 RTN

Press x<>y to see the other root.

In RPN mode the 35s will dispay 2 lines, thus both roots.
In ALG mode only one line is displayed. After running the program, use x<>y to swap between roots.