Post Reply 
(35S ALG) Quadratic Equation Solver (with complex solutions support)
03-17-2015, 10:57 AM (This post was last modified: 06-15-2017 02:01 PM by Gene.)
Post: #1
(35S ALG) Quadratic Equation Solver (with complex solutions support)
Based on this article:
http://www.hpmuseum.org/cgi-sys/cgiwrap/...?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.


Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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