Thank you.
Usefull code. Here a more compact version of your code I have input into a personal note format:
Step Function t: z: y: x: Lastx:
----- -------- ------ ---------------------- ----------------------- ---------------------- ------
01 LBL E ~ a b c
02 ENTER a b c c
03 R^ b c c a
04 / b b c c/a a
05 R^ b c c/a b
06 LSTx c c/a b a
07 / c c c/a b/a a
08 2 c c/a b/a 2
09 CHS c c/a b/a -2 -2
10 / c c c/a -b/2a -2
11 ENTER c c/a -b/2a -b/2a
12 ENTER c/a -b/2a -b/2a -b/2a
13 x^2 c/a -b/2a -b/2a b²/4a² -b/2a
14 R^ -b/2a -b/2a b²/4a² c/a
15 - -b/2a -b/2a -b/2a b²/4a²-c/a c/a
16 SQRT -b/2a -b/2a -b/2a SQRT(b²/4a²-c/a) b²/4a²-c/a
17 - -b/2a -b/2a -b/2a -b/2a-SQRT(b²/4a²-c/a) SQRT(b²/4a²-c/a)
18 x<>y -b/2a -b/2a -b/2a-SQRT(b²/4a²-c/a) -b/2a
19 LSTx -b/2a -b/2a-SQRT(b²/4a²-c/a) -b/2a SQRT(b²/4a²-c/a)
20 + -b/2a -b/2a -b/2a-SQRT(b²/4a²-c/a) -b/2a+SQRT(b²/4a²-c/a) SQRT(b²/4a²-c/a)
21 RTN x1 x2
----- -------- ------ ---------------------- ----------------------- ---------------------- ------
where
x1 and
x2 are the real roots of equation
a.x2+b.x+c=0
Exemple :
Type 2 [ENTER] 10 [CHS][ENTER] 12 [ GSB ][ E ] to solve
2.x2 - 10.x + 12=0 and get
x1 = 2 and
x2 = 3
The calculator first display
x2, you have to press [x<->y]key to get
x1.
But you will be in trouble solving
2.x2 - 8.x + 26=0 !
Note that on HP-15c, this code needs very few modifications to also produce real or complex solution(s) to any
a.x2+ b.x + c = 0 equation with real or complex coefficients
a,
b and
c.
Step Func
----- --------
01 LBL E
02 ENTER
03 R^
04 /
05 R^
06 LSTx
07 /
08 2
09 CHS
10 /
11 ENTER
12 ENTER
13 x^2
14 R^
15 -
16 TEST 2 @ ( x<=0 ? )
17 SF 8 @ (Complex mode ON)
18 SQRT
19 -
20 x<>y
21 LSTx
22 +
23 RTN
----- --------
To solve quadratic equation 2.x2 - 8.x + 26 = 0, y have to type :
[ g ][ CF ][ 8 ] to set complex mode OFF in order to enter real coefficients :
[ 2 ][ENTER^][ 8 ][CHS][ENTER^][2][6] to type in respectively a=2, b=-8 and c=26.
[GSB][ E ] to run code.
Note that the ‘C’ enunciator indicates complex solutions z1 = 2-3i and z2 = 2+3i. Imaginary parts have to be displayed using [ f ][Re<->I] switchs or by holding [ f ][(i)] key.
To enter complex coefficients, simply enter a, b and c as complex using [ f][ I ] or [ f ][Re<->Im] method.
Amazing HP-15c!
Edited: 29 Sept 2011, 4:54 p.m.