Post Reply 
Mathematician Finds Easier Way to Solve Quadratic Equations
05-08-2024, 02:23 AM (This post was last modified: 05-08-2024 02:25 AM by Gerson W. Barbosa.)
Post: #57
RE: Mathematician Finds Easier Way to Solve Quadratic Equations
(05-07-2024 03:05 PM)Albert Chan Wrote:  KISS quad solver
Code:
function quad(a,b,c)
    b = -.5*b
    local y = I.sqrt(b*b-a*c)
    y = I.abs(b+y) < I.abs(b-y) and b-y or b+y
    return y/a, c/y
end

lua> quad(1e-13,-2,1)
(19999999999999.496+0*I)      (0.5000000000000125+0*I)

I assume by KISS you mean “Keep It Simple & Short”. Anyway, for me the acronym would sound offensive only if there were a comma before the second S (“Keep it simple stupid” is quite a different thing than “keep it simple, stupid!”– at least for those of us who use to place a comma before nouns in vocative case).

BTW, do you have an RPL version of that code? Regarding “Lua”, I know the meaning of the name only. Also, the relational < operator doesn’t work for complex numbers on the HP-42S.

Meanwhile I have received two modified versions of my latest “Y” program from an anonymous contributor. The shorter one is suitable for the real HP-42S while the other is meant for Free42.

HP-42S:
Code:

00 { 24-Byte Prgm }
01▸LBL "Q"
02 X<> ST Z
03 STO÷ ST Z
04 STO+ ST X
05 ÷
06 +/-
07 ENTER
08 X↑2
09 RCL- ST Z
10 SQRT
11 X=Y?
12 +/-
13 -
14 STO÷ ST Y
15 END


Free42:
Code:

00 { 28-Byte Prgm }
01▸LBL "Q"
02 X<> ST Z
03 STO÷ ST Z
04 STO+ ST X
05 ÷
06 +/-
07 ENTER
08 X↑2
09 RCL- ST Z
10 SQRT
11 SF 25
12 X≤Y?
13 +/-
14 CF 25
15 -
16 STO÷ ST Y
17 END


Best regards,

Gerson.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Mathematician Finds Easier Way to Solve Quadratic Equations - Gerson W. Barbosa - 05-08-2024 02:23 AM



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