This is yet another attempt at finding a shorter (but not necessary faster) quadratic formula program for the HP-41C, while preserving the stack register T (Thanks to Jeff Kearns - if it were not because of his interest, I wouldn't have taken a second look at
this old thread)
Code:
01 LBL 'Q
02 X<> Z
03 CHS
04 ST/ Z
05 ST+ X
06 /
07 STO Z
08 X^2
09 +
10 SQRT
11 RCL Y
12 ST+ Z
13 +
14 ST- Y
15 END
x₂ is computed using this well-known property:
\[x_{1}+x_{2}=-\frac{b}{a}\]
Real roots only, but since the stack register T is preserved it will solve the first example for the HP-42S program
here.
I'd rather present it here first, before submitting it to the HP-41C Software Library, as any issue I might have overlooked would surely be pointed out soon. Thanks!
Gerson.
PS.: The title should read ...faster quadratic formula program... - as the formula is essentially the same, but I cannot edit it.
Code:
00 { 22 Byte-Prgm }
01 LBL "Q"
02 X<> ST Z
03 STO/ ST Z
04 STO+ ST X
05 /
06 ENTER
07 X^2
08 RCL- ST Z
09 SQRT
10 -
11 +/-
12 STO/ ST Y
13 END
x₂ is computed using this well-known property:
\[x_{1}\cdot x_{2}=\frac{c}{a}\]
Cheers
Thomas
(06-04-2014 05:32 AM)Thomas Klemm Wrote: [ -> ]
Code:
00 { 22 Byte-Prgm }
01 LBL "Q"
02 X<> ST Z
03 STO/ ST Z
04 STO+ ST X
05 /
06 ENTER
07 X^2
08 RCL- ST Z
09 SQRT
10 -
11 +/-
12 STO/ ST Y
13 END
x₂ is computed using this well-known property:
\[x_{1}\cdot x_{2}=\frac{c}{a}\]
Cheers
Thomas
Thomas,
I fear there might be trouble when c = 0. Also, the HP-41 lacks recall arithmetic.
Anyway, records exist to be broken. I won't be surprised if you or someone else comes up with a shorter (or a lower byte-count) HP-41 or 42S program.
Cheers,
Gerson.
P.S.: On the HP-42S, replace line 10 with
10 +
P.P.S.: This won't solve the case when both b and c are zero, however.
(06-04-2014 05:59 AM)Gerson W. Barbosa Wrote: [ -> ]I fear there might be trouble with c = 0.
I know. But then who is going to use this program to solve \(ax^2+bx=0\)?
Quote:Also, the HP-41 lacks recall arithmetic.
I tend to forget this.
Quote:P.S.: On the HP-42S, replace line 10 with
10 +
This won't solve the case when both b and c are zero, however.
Should this solve the problem with the division by zero?
In case of \(c=0\) this depends on the sign of \(b\).
So it doesn't really matter whether we use + or -.
I prefer to have \(x_1\) in register
X.
Cheers
Thomas
The same program for a 34S is very very tiny
- Pauli
(06-04-2014 07:33 AM)Paul Dale Wrote: [ -> ]The same program for a 34S is very very tiny
Not tinier than "QROOT" in the SandMath ;-)
(06-04-2014 07:11 AM)Thomas Klemm Wrote: [ -> ] (06-04-2014 05:59 AM)Gerson W. Barbosa Wrote: [ -> ]Also, the HP-41 lacks recall arithmetic.
I tend to forget this.
I re-learn this every time I come back to using my 41. Which I suppose means I never really learn it all...
Very nice Gerson. Short AND sweet.
(06-04-2014 07:33 AM)Paul Dale Wrote: [ -> ]The same program for a 34S is very very tiny
It won't solve
this one, however, unlike the HP-42S programs (mine and Thomas's). But what would
CSLVQ (SSIZE8 mode only) be useful for anyway?
Gerson.
(06-04-2014 08:52 AM)walter b Wrote: [ -> ] (06-04-2014 07:33 AM)Paul Dale Wrote: [ -> ]The same program for a 34S is very very tiny
You can say that
d:-)
In another post, about two years ago, I said "nothing beats SLVQ on the WP 34S, however". Definite a killjoy, but very useful :-) (I remember having used SLVQ in a program once).
Gerson.
(06-04-2014 01:07 PM)rprosperi Wrote: [ -> ]Very nice Gerson. Short AND sweet.
Thanks, Bob!
For the sake of documentation I should have mentioned that I have used the quadratic formula in this form, valid when a = -1:
\[x_{1}= \frac{b}{2}+\sqrt{\left ( \frac{b}{2} \right )^{2}+c}\]
Please see Allen's post in
this thread from 2007.
Regards,
Gerson.
(06-08-2014 02:55 AM)Gerson W. Barbosa Wrote: [ -> ]It won't solve this one, however, unlike the HP-42S programs (mine and Thomas's). But what would CSLVQ (SSIZE8 mode only) be useful for anyway?
ZQRT in the 41Z module does too ;-)
(06-08-2014 09:26 AM)Ángel Martin Wrote: [ -> ] (06-08-2014 02:55 AM)Gerson W. Barbosa Wrote: [ -> ]It won't solve this one, however, unlike the HP-42S programs (mine and Thomas's). But what would CSLVQ (SSIZE8 mode only) be useful for anyway?
ZQRT in the 41Z module does too ;-)
...with no native complex number support, you might have said! Sorry for my ignorance!
Gerson.
Yes, quadratic and cubic equations with complex coefficients and obviously results. Interestingly, I took the opportunity to review the code in the 41Z - finding a typo (a.k.a. bug) on the Spherical Hankel functions (not in the Bessel functions, those were ok). It appears that, like rust, bugs never sleep!