Post Reply 
(42S) Short Quadratic Solver
04-24-2014, 12:32 AM (This post was last modified: 05-17-2017 12:37 PM by Gerson W. Barbosa.)
Post: #1
(42S) Short Quadratic Solver
Code:
00 { 25-Byte Prgm }                        
01 LBL "Q"                     
02 X<> ST Z                                        
03 +/-
04 STO/ ST Z
05 STO+ ST X 
06 /                 
07 STO ST Z        
08 X^2                
09 +             
10 SQRT      
11 RCL+ ST Y                     
12 X<>Y               
13 RCL- ST L 
14 END

Examples:

1) Given x² - 5x + 6 = 0, compute 123456*x₁ and 123456*x₂

.................... 123456 ENTER 1 ENTER 5 +/- ENTER 6 XEQ Q -> Y: 3 ; x₂ = 3
................................................................ X: 2 ; x₁ = 2
........................................................ Rv * -> X: 370,368 ; 123456*x₂
........................................................ Rv * -> X: 246,912 ; 123456*x₁


2) 3x² - 12x + 87 = 0


............................... 3 ENTER 12 +/- ENTER 87 XEQ Q -> Y: 2 .i5 ; x₂ = 2 + 5i
................................................................ X: 2 -i5 ; x₁ = 2 - 5i

3) x² - (4 + 6i)x + (-5 + 10i) = 0

.. 1 ENTER 4 ENTER 6 COMPLEX +/- 5 +/- ENTER 10 COMPLEX XEQ Q -> Y: 3 i4 ; x₂ = 3 + 4i
................................................................ X: 1 i2 ; x₁ = 1 + 2i


Edited to change code. Now it is one step and one byte shorter. This is the older code:

Code:
00 { 26-Byte Prgm }                        
01 LBL "Q"                     
02 X<> ST Z                                        
03 +/-
04 STO/ ST Z
05 /                       
06 2                  
07 /                 
08 STO ST Z        
09 X^2                
10 +             
11 SQRT      
12 RCL+ ST Y                     
13 X<>Y               
14 RCL- ST L 
15 END

Edited again to change subject line.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(42S) Short Quadratic Solver - Gerson W. Barbosa - 04-24-2014 12:32 AM



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