HP Forums

Full Version: What is this HP-41 program doing?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

LBL A
RCL Z ST+ T * 4 *
RCL Y CHS STO Z X^2 X<>Y - SQRT
STO T X<>Y + LASTX R^ -
RCL Z ST/ Z /
END

Just a little exercise for the hot summer days ...

It is computing the real roots of a quadratic equation,
where the coefficients have been entered into the X,Y,Z
stack registers initially.

Bravo! I used it in the school, some 17 years ago. In fact, I have used the following program which can handle complex solutions as well:

LBL A
CF 00 RCL Z ST+ T * 4 *
RCL Y CHS STO Z X^2 X<>Y -
X<0? SF 00 FS? 00 CHS SQRT
FS? 00 GTO 01
STO T X<>Y + LASTX R^ -
LBL 01 RCL Z ST/ Z /
END

Real solutions: flag 0 cleared, X=x1, Y=x2
Complex solutions: flag 0 set, X=Im, Y=Re

The size of this program is 41 bytes (not counting LBL A and END). I am aware this is not optimal and would like to make a proposal: Who can write a shorter program? Only stack registers and flag 00 can be used. Alpha register and data registers cannot be used. Synthetic instructions are welcome but alpha register should not be disturbed.

This is a slightly modified version:

LBL A
CF 00 RCL Z ST+ T * 4 *
RCL Y CHS STO Z X^2 X<>Y -
X<0? SF 00 ABS SQRT
FS? 00 GTO 01
STO T X<>Y + LASTX R^ -
LBL 01 RCL Z ST/ Z /
END

39 bytes.

Reminds me the integration with Simpson rule I've once done only on the stack. Was useful when you had a table of points with uniform steps in X.

Ciao.....Mike

Hi, HrastProgrammer;

Hey, have a look here. If you cannot open it, tell me and I'll send the text.

Cheers.

Thanks Luiz ...