Re: Which quadratic formula is use? Message #7 Posted by C.Ret on 29 Sept 2011, 4:42 p.m., in response to message #6 by Jeff O.
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/2aSQRT(b²/4a²c/a) SQRT(b²/4a²c/a)
18 x<>y b/2a b/2a b/2aSQRT(b²/4a²c/a) b/2a
19 LSTx b/2a b/2aSQRT(b²/4a²c/a) b/2a SQRT(b²/4a²c/a)
20 + b/2a b/2a b/2aSQRT(b²/4a²c/a) b/2a+SQRT(b²/4a²c/a) SQRT(b²/4a²c/a)
21 RTN x1 x2
      
where x_{1} and x_{2} are the real roots of equation a.x^{2}+b.x+c=0
Exemple : Type 2 [ENTER] 10 [CHS][ENTER] 12 [ GSB ][ E ] to solve 2.x^{2}  10.x + 12=0 and get x_{1} = 2 and x_{2} = 3
The calculator first display x_{2}, you have to press [x<>y]key to get x_{1}.
But you will be in trouble solving 2.x^{2}  8.x + 26=0 !
Note that on HP15c, this code needs very few modifications to also produce real or complex solution(s) to any a.x^{2}+ 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.x^{2}  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 z_{1} = 23i and z_{2} = 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 HP15c!
Edited: 29 Sept 2011, 4:54 p.m.
