03-21-2018, 06:50 AM (This post was last modified: 03-23-2018 05:51 AM by Gamo.)
Post: #1
 Gamo Senior Member Posts: 700 Joined: Dec 2016
The program calculates the real or complex solutions of a quadratic equation.

aX^2 + bX + c = 0

c [ENTER] > b [ENTER] > a > [LBL A] briefly shown [+] or [-] solution.

If Positive (+) then two real solutions with R/S for second answer.
If Negative (-) then two complex solutions with X<>Y for complex of +,-

Program:
Code:
 LBL A LBL 1 ENTER Rv / 2 / CHS ENTER X^2 Rv Rv X<>Y / STO 0 - PSE X<0 GTO 1 SQR X<>Y X<0 GTO 2 + GTO 3 LBL 2 X<>Y - LBL 3 R/S 1/x RCL 0 x RTN LBL 1 CHS SQR X<>Y R/S

Example:
1) 2x^2 + 5x + 3 = 0

3 ENTER 5 ENTER 2 [A] > 0.0625 (Show briefly with positive) so the solutions are real:
Answer: -1.5 > [R/S] > -1
X={-1.5, -1}

2) 2x^2 + 3x + 4 = 0

4 ENTER 3 ENTER 2 [A] > -1.4375 (Show briefly with negative) so the solutions are complex:
Answer: -0.75 > [X<>Y] > 1.1990 round to 1.2
x1 = -0.75 + 1.2i
x2 = -0.75 - 1.2i

3) Here are examples of quadratic equations lacking the linear coefficient or the “bX”:

6x² + 144 = 0

144 ENTER 0 ENTER 6 [A] > -24 (Briefly show negative) solution are complex:
Answer: 0 > [X<>Y] > 4.8990
x1 = 4.8990i
x2 = -4.8990i

x² – 16 = 0

16 CHS ENTER 0 ENTER 1 [A] > (Briefly show positive) solution are real.
Answer: 4 > [R/S] > -4
x={4, -4}

4) Here are examples of quadratic equations lacking the constant term or “c”:

2x² + 8x = 0

0 ENTER 8 ENTER 2 [A] > (Briefly show positive) real solution.
x={0, -4}

Gamo
03-22-2018, 10:18 AM (This post was last modified: 03-22-2018 11:58 AM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
(03-21-2018 06:50 AM)Gamo Wrote:  The program calculates the real or complex solutions of a quadratic equation.

aX^2 + bX + c = 0

c [ENTER] > b [ENTER] > a > [LBL A] briefly shown [+] or [-] solution.

If Positive (+) then two real solutions with R/S for second answer.
If Negative (-) then two complex solutions with X<>Y for complex of +,-

One of my first books on RPN and HP calculators also had a program for quadratic equations. To distinguish real and complex solutions it displayed "1111111111" for the latter case. In the calculator display this looks like a line of "i"s that indicate a solution with an imaginary part. ;-)

I like this idea, so here is an adapted version. It differs from yours in three points:

- The coefficients are entered  a [ENTER] b [ENTER] c
- Two real solutions are directly returned in X and Y
- An imaginary solution is indicated by a line of 1s, then real and imaginary part are returned in X and Y again.

Edit:
The program now also handles a=0, i.e. a simple linear equation. The previous versions returned an error in this case.

Code:
LBL A R↓ x<>y x=0? GTO 2 / R↑ LastX / ENTER ENTER R↑ 2 / CHS ENTER x^2 R↑ - x<0? GTO 1 SQRT x<>y x>0? + x>0? GTO 0 x<>y - LBL 0 ENTER R↑ x<>y / RTN LBL 1 EEX 1 0 ENTER 9 / PAUSE R↓ CHS SQRT x<>y RTN LBL 2 R↑ - x<>y / ENTER RTN

Examples:

2x² + 5x + 3 = 0
2 [ENTER] 5 [ENTER] 3 [A] => –1,0000 [X↔Y] –1,5000
Two real solutions: –1 and –1,5.

2x² + 3x + 4 = 0
2 [ENTER] 3 [ENTER] 4 [A] => "1111111111"  –0,7500 [X↔Y] 1,1990
Two conjugate complex solutions: –0,75 ± 1,199 i

BTW, for those who want to try more sophisticated quadratic equation solvers: take a look at the HP15C Advanced Functions Handbook (appendix, "Example 6 continued"). It includes a special version of such a program that shows how the limitations of the standard methods can be overcome. However, note that this solves ax²–2bx+c=0.

Dieter
08-11-2018, 10:34 AM
Post: #3
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
(03-22-2018 10:18 AM)Dieter Wrote:  BTW, for those who want to try more sophisticated quadratic equation solvers: take a look at the HP15C Advanced Functions Handbook (appendix, "Example 6 continued"). It includes a special version of such a program that shows how the limitations of the standard methods can be overcome. However, note that this solves ax²–2bx+c=0.

Cf. Solve the real quadratic equation $$c-2bz+az^2=0$$ for real or complex roots.
08-11-2018, 04:39 PM (This post was last modified: 09-06-2018 11:49 AM by Albert Chan.)
Post: #4
 Albert Chan Senior Member Posts: 1,646 Joined: Jul 2018
(03-22-2018 10:18 AM)Dieter Wrote:  One of my first books on RPN and HP calculators also had a program for quadratic equations.
To distinguish real and complex solutions it displayed "1111111111" for the latter case.
In the calculator display this looks like a line of "i"s that indicate a solution with an imaginary part. ;-)

I did a Quadratic Solver for Casio FX-3650P:

Instead of using a special number for signaling complex roots.
I CRASH the program, on purpose, by taking square root of negative discriminant.
(complex roots = X +/- Y * I, stored in memory X, Y)

If user is still not warned about roots being complex, I don't know what will :-)

Edit:
I had revised the solver, allowed for adjustable discriminant (if more precise available).
Since discriminant is shown, it's sign signaled real or complex roots.
 « Next Oldest | Next Newest »

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