Saturday, September 23, 2023

HP 15C: Quadratic Solver Using Solve and Flags

HP 15C:  Quadratic Solver Using Solve and Flags



Introduction


This program solves the quadratic equation for real roots:


a x^2 + b x + c = 0


Instructions:


1.  Key:  a [ENTER], b [ENTER], c [ f ] [ A ]   (enter coefficients into label A)

2.  The first root is displayed. 

3.  Press [ R/S ] for the second root.


Registers Used:


R1 = a

R2 = b

R3 = c

R4 = root 1

R5 = root 2

R6 = abs((R1 + R2 + R3) ÷ 3),  I use [-R6, R6] as my initial guesses.


Flag 0: used to adjust the equation to be solved

Equation 1:  finding the first root:   (a x^2 + b x + c)  (flag 0 is set)

Equation 2:  finding the first root:   (a x^2 + b x + c) ÷ (x - root)  (flag 0 is clear, this is a depressed equation)


When a function with multiple roots is present, we can take out roots already found by dividing f(x) by (x - root).  




HP 15C Program:  Quadratic Solver

Steps:  47, Bytes:  57


Code:


Step : Key Code : Key


001 : 42,21,11 : LBL A

002 : 44, 3 : STO 3

003 : 44, 6 : STO 6

004 : 33 : R↓

005 : 44, 2 : STO 2

006 : 44,40, 6 : STO+ 6

007 : 33 : R↓

008 : 44, 1 : STO 1

009 : 44,40, 6 : STO+ 6

010 : 45, 6 : RCL 6

011 : 3 : 3

012 : 10 : ÷

013 : 43,16 : ABS

014 : 44, 6 : STO 6

015 : 43, 4, 0 : SF 0

016 : 42,21, 0 : LBL 0

017 : 45, 6 : RCL 6

018 : 16 : CHS

019 : 45, 6 : RCL 6

020 : 42,10, 1 : SOLVE 1

021 : 43, 6, 0 : F? 0

022 : 22, 2 : GTO 2

023 : 22, 3 : GTO 3

024 : 42,21, 2 : LBL 2

025 : 44, 4 : STO 4

026 : 43, 5, 0 : CF 0

027 : 22, 0 : GTO 0

028 : 42,21, 1 : LBL 1

029 : 36 : ENTER

030 : 36 : ENTER

031 : 45,20, 1 : RCL× 1

032 : 45,40, 2 : RCL+ 2

033 : 20 : ×

034 : 45,40, 3 : RCL+ 3

035 : 43, 6, 0 : F? 0

036 : 43, 32 : RTN

037 : 34 : x<>y

038 : 45, 4 : RCL 4

039 : 30 : -

040 : 10 : ÷

041 : 43,32 : RTN

042 : 42,21, 3 : LBL 3

043 : 44, 5 : STO 5

044 : 45, 4 : RCL 4

045 : 31 : R/S

046 : 34 : x<>y

047 : 43, 32 : RTN



Examples


x^2 - 5 x - 24 = 0

a = 1

b = -5

c = -24


1 [ ENTER ] 5 [CHS] [ ENTER ] 24 [ CHS ] [ f ] [ A ]

Roots:  8 [ R/S ] -3   (x = 8, x= -3)


2 x^2 + 8 x - 2 = 0

a = 2

b = 8

c = -2


2 [ ENTER ] 8 [ ENTER ] 2 [ CHS ] [ f ] [ A ]

Roots:  0.2361 [ R/S ] -4.2361  (x ≈ 0.2361, x ≈ -4.2361)


Eddie


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.