HP-42S Help



#2

I've used an HP-28C and 15C for years. Two weeks ago my sons gave me an HP-42S with both Owner's Manual and Programming Manual. I have figured everything out for the most part except for roots of polynomials. I can figure quadratics and cubics such as x^3+3x^2+9x-1 but I can't get the programming syntax for 3x^3-9x^2+14x+7 nor can I figure any kind of quadratics. Please help me. These are a breeze to figure on the 15C and 28C. Also, is there any kind of program for the 42S that can compute complex roots of polynomials?


#3

Hi.

I guess the closest technique is the Horner's method. Think of

3x^3-9x^2+14x+7
as
((3*x-9)*X+14)*X+7
If you want to use the HP42S built-in SOLVER, you could program it like this:
LBL "XMPL"
MVAR "X"
RCL "X"
ENTER
ENTER
ENTER
3
*
9
-
*
14
+
*
7
+
END
Now you just need to SOLVE for XMPL:
[SHIFT][SOLVER]
You'll see [XMPL] amongst the menu labels. Press the key right (...) below it (SoftKey) and the display will show the possible variables for solving (the Variables Menu, hence the MVAR "X"), in this case a single [X]. You can either guess a starting value (avoiding possible miscalculations) or simply press the key right above [X]. My HP42S found
[X=-0.3897]
with the example above.

Hope it helps.

Cheers.

Luiz (Brazil)


Edited: 28 June 2012, 1:12 p.m. after one or more responses were posted


#4

There is no need for Horner's method with this one, you can simply, though unelegantly key in

LBL TST

MVAR "X"

RCL "X"

3

Y^X

3

*

RCL "X"

X^2

9

*

-

RCL "X"

14

*

+

7

+

RTN

...and than solve TST for X, that yields X=-0.3897

As this is pretty straightforward, maybe I have not completely understood what the initial problem with this is...?

Edited: 28 June 2012, 4:40 a.m.


#5

Hi.

I just considered that by using Horner's method to reduce a polynomial expression to a few arithmetic operations with no need for powers/exponents, the final program would be easier to be written. 8^)

Cheers.

Luiz (Brazil)


#6

Right, in this case two program step are spared :

001 LBL "TST        001 LBL "XMP
002 MVAR "X" 002 MVAR "X"
003 RCL "X" 003 RCL "X"
004 3 004 ENTER
005 Y^X 005 ENTER
006 3 006 ENTER
007 * 007 3
008 RCL "X" 008 *
009 X^2 009 9
010 9 010 -
011 * 011 *
012 - 012 14
013 RCL "X" 013 +
014 14 014 *
015 * 015 7
016 + 016 +
017 7 017 RTN
018 +
019 RTN

Very similar in fact


#7

Thanks so much for helping me with the cubic equation. I tried both methods given to me to find the roots for the following quartics and I get only one root for each equation:

x^4+8x^3+9x^2-8x-10=0
4x^4-31x^2+21x+18=0

I am obviously doing something wrong.


#8

I only tried the first one but could find all four roots: -6.4495, -1.5505, -1 and 1.

It all depends on the right initial guesses, use the programmed function to calculate some values to plot it roughly, then you put in two guesses for x that are located in the vicinity of the potential roots. You do this by starting the solver, selecting the programmed function and than keying in the lower guess, press [X], upper guess, press [X] and than [X] again to solve. See the manual on further details.

Edited: 28 June 2012, 5:08 p.m. after one or more responses were posted


#9

What program syntax did you use to solve the first equation? I will copy and save it for future reference.


#10

The same straightforward syntax I used in my posting above.

#11

I've found the following program at Thomas Okken's website:

"G4_G3_G2.raw Solves 2nd, 3rd, and 4th order polynomials. using closed-form solutions. Contributed by Christian Vetterli."

 00 { 526-Byte Prgm }

01>LBL "G2"
INPUT "A" INPUT "B"
INPUT "C" RCL "B" X^2
RCL "A" RCL× "C" 4 ×
- SQRT STO "C"
RCL "A" 2 × STO÷ "C"
+/- STO÷ "B" RCL "B"
RCL+ "C" RTN RCL "B"
RCL- "C" RTN

26>LBL "G3"
RECT DEG INPUT "A"
INPUT "B" INPUT "C"
INPUT "D" SF 00 CF 01
RCL "A" STO÷ "B"
STO÷ "C" STO÷ "D"

39>LBL 15
RCL "B" 3 Y^X 13.5 ÷
RCL "B" RCL× "C" 3 ÷
- RCL+ "D" STO "A"
RCL "B" X^2 3 ÷
STO- "C" RCL "C" 3 ÷
3 Y^X RCL "A" 2 ÷
X^2 + SQRT RCL "A" 2
÷ X<>Y X=Y? +/- X<>Y
- 3 1/X Y^X STO "D"
2E-3 STO 00

82>LBL 16
FS? 01 GTO 01 3
STO÷ "C" SF 01

88>LBL 01
POLAR 1 120 COMPLEX
STO÷ "D" RCL "C" SF 25
RCL÷ "D" RCL "D" X<>Y
- RECT RCL "B" 3 ÷
- RTN ISG 00 GTO 16

108>LBL "G4"
SF 00 CF 01 CF 02
RECT DEG INPUT "A"
INPUT "B" INPUT "C"
INPUT "D" INPUT "E"
RCL "A" STO÷ "B"
STO÷ "C" STO÷ "D"
STO÷ "E" RCL "B"
STO "G" X^2 RCL× "C"
16 ÷ RCL "B" 4 Y^X
3 × 256 ÷ - RCL "B"
RCL× "D" 4 ÷ -
STO+ "E" RCL "B" 3
Y^X 8 ÷ RCL "B"
RCL× "C" 2 ÷ -
STO+ "D" RCL "B" X^2
0.375 × STO- "C" 2
RCL× "C" STO "B"
RCL "C" X^2 4
RCL× "E" - STO "C"
RCL "D" STO "F" X^2
+/- STO "D" XEQ 15

175>LBL 05
STO ST Y ABS 1E-8
FC? 02 X<=Y? GTO 02
SF 02 ISG 00 XEQ 16
GTO 05

186>LBL 02
RCL ST Z SQRT STO "A"
SF 25 STO÷ "F" ISG 00
XEQ 16

194>LBL 06
STO ST Y ABS 1E-8
FC? 02 X<=Y? GTO 02
SF 02 ISG 00 XEQ 16
GTO 06

205>LBL 02
RCL ST Z SQRT STO "E"
SF 25 STO÷ "F" RCL "E"
RCL+ "A" RCL- "F"
XEQ 04 RCL "F"
RCL+ "A" RCL- "E"
XEQ 04 RCL "E"
RCL+ "F" RCL- "A"
XEQ 04 RCL "E"
RCL+ "F" RCL+ "A" +/-

227>LBL 04
2 ÷ RCL "G" 4 ÷ -
STOP RTN .END.

I haven't tested it on the real HP-42S, but for William's polynomial Free42 Decimal returns the following roots:
XEQ G4
A?1 R/S
B?8 R/S
C?9 R/S
D?-8 R/S
E?-10 R/S

-1.55051025722 -i3.35403051129e-25
1 i6.25300999685e-25
-1 -i9.54592314951e-27
-6.44948974278 -i2.80352025407e-25

These match your results, considering the very small imaginary parts are actually zero.


Edited: 28 June 2012, 9:53 p.m.

#12

That’s the problem with numeric solver; you have to initiate each root search with an appropriate initial value.
There is no trick to find all these values by only looking at the polynomial. That is why graphic calculators, such as the HP-28C, will spare a lot of time. It is a good advice to start plotting the curve.

For x^4+8x^3+9x^2-8x-10, enter the polynomial equation into you HP-28C :

 « X 8 + X * 9 + X * 8 – X * 10 - »  STEQ
A draw the curve between x=-10 up to x=+10 abscises.
(10,31) DUP PMAX CHS PMIN
And start drawin the curve :
DRAW

You may obtain the following graph, using cursor keys and INS key you simply have to plot positions close to the four roots. Then press ON key to exist graph . You have now in the stack the four initial values close enough to the root to use in the HP28C’s solveur (or any solveur of you alternative HP calculators).

|4:     (-6.4706,1.0000)|
|3: (-1.6176,1.0000)|
|2: (-0.8824,1.0000)|
|1: (1.0294,1.0000)|
(Exact value may depend upon pixel positions where you press the INS key)
[SOLV][SOLVR]
Enter first estimate into X register :
 [  X  ] 
And initiate seek of the first root :
[shift][  X  ]
The HP28C may display ‘Solving for X’ and stop indicating that a first zero is found :
|#X:#1.0000#############|
|Zero |
|2: (-0.8824,1.0000)|
|1: 1.0000|
Write down this first root or store it in a safe place (for example in the stack):
  4  [shift][ ROLL ]
Enter second estimate into X register:
 [  X  ] 
And initiate seek of the second root:
 [shift] [  X  ] 
There-6.4706 value is used as the initial value and rapidly the process converges to a ‘sign reversal’ root; a root that is not exactly evaluated to zero due to limited precision of the calculator:
|#X:#-6.4495##############|
|Sign Reversal |
|1: -6.4495|
| X |EXPR=| | | | |

Process the same way for the two last estimates:

 4 [shift] [ ROLL ] [  X  ] [shift] [  X  ] 4 [shift] [ROLL][  X  ] [shift] [  X  ] 4 [shift] [ROLL] [CURSOR]
And you will have the four root of the polynomial into the stack:
|4:              -6.4495|
|3: -1.5505|
|2: -1.0000|
|1: 1.0000|

For the second equation, process the same way and take advantage of your HP-28C to draw the curve. It is great helper in finding how to initiate root seeking. Making all previous HP a crabs


P.S.: For second equation { -3 -0.5 1.5 2.0 } obtained the same graphicaly way!

Edited: 28 June 2012, 5:10 p.m. after one or more responses were posted


#13

Thanks for the programming syntax for the 28C. But what I actually needed was the syntax for the 42S to solve the quartic equation I referenced above.


#14

The HP42S solver is acting exactly as one the HP28C does. Main differencies are that it only use a pair of initial values to start seeking. The HP28C may use a single, a pair or a triplet as initial(s) guess entered as a list { best_guess, low_interval_guess, high_interval_guess } .


On the HP42S, you first have to enter the equation as a program:

 [shift][PRGM]
You may enter your code as you prefer (using or not exponents or Horner’s format, whatever), simply indicate variable(s) to be put in menu by using the MVAR command. And avoid syntax error or typing-bug as you have few chances on such a calculator to easily check tips.
     00 { 39-Byte Prgm }
01>LBL "P_X"
02 MVAR "X"
03 4
04 RCL "X"
05 X^2
06 ×
07 31
08 -
09 RCL "X"
10 ×
11 21
12 +
13 RCL "X"
14 ×
15 18
16 +
17 RTN
18 .END.
Leave program mode :
 [shift][PRGM]

Now you are ready to start the solver:

 [shift][SOLVER]
Select the equation you just type in by pressing the corresponding soft-key
[  P_X  ]
Enter low guess and high guess for first root seeking. Here, a plot is missing that why I am in trouble trying to understanding you, as you have an HP28C which is much superior for this type of guessing! :-)
 6 [+/-] [  X  ]  2 [+/-] [  X  ][ X ]
That make { -6 -4 } the first pair of initial values to seek for the first root.
Rapidly the HP42S displays first root stored in X register:
| X = -3                      |
[ X ][ ][ ][ ] [ ][ ]
Note that you can get the same result and investigate how the calculator is seeking by keying on a HP28C/S in its solver :
 { -6 -4 } [  X  ][shift][  X  ]

Second root can be found using a different set of initial values:

 2 [+/-] [  X  ]  0 [  X  ][ X ]
That make { -2 0 } as second interval to seek for the second root.
| X =-0.5                    |
[ X ][ ][ ][ ] [ ][ ]
That is rapidly found and displayed.
And so on for other guess pair to seek after the two other roots :
 0 [ X ] 1 [ X ] [ X ]
| X =1.5                      |
[ X ][ ][ ][ ] [ ][ ]

Finaly , last interval :

 1.8 [ X ] 5 [ X ] [ X ]
| X =2                        |
[ X ][ ][ ][ ] [ ][ ]

But, I sorry to repeat it again, it is hard to have efficient initial guess without a graph. And nothing is as easy and convenient as a graphic calculator to quickly plot it and zoom in regions of interest. Having the shape of the function is a great help to seek after its roots!


#15

Thank you for your response. I thank everyone for their helpful responses. I totally agree with you about graphing. I have loved my 28C since I got it in 1986. As I said before, I have had a 45, 15C, 28C and a 50g. Of all, the 28C is my favorite. I'm glad I joined this forum. All of you have been incredibly helpful.


#16

Christian Vetterli's program above will compute all roots, real or complex, of polynomials up to degree 4 (if you don't mind keying in 200+ lines). Let it solve 4x^4-8x^3-13x^2-10x+22=0, for instance:

XEQ G4
A?4 R/S
B?-8 R/S
C?-13 R/S
D?-10 R/S
E?22 R/S --> 3.11803398875 i0
R/S --> -1 -i1
R/S --> -1 i1
R/S --> 0.88196601125 i0
#17

You can simplify the program above by deleting the three ENTER commands after RCL X. The HP-42S solver populates the stack with the independent variable, just as the HP-15C did. This is true for the integrator also.


#18

Hi.

Thanks for pointing that out, but as a matter of fact, those three ENTER are actually needed.

The HP42S does not actually work as the HP15C (*) because of one fact: you can have more than one unknown in an equation when writing them for the HP42S SOLVER so you can choose which unknown to solve for. That's why you may actually 'declare' the unknowns you want to solve for by using the 'MVAR' statement/function. Then your program simply returns the function value based upon the many unknowns you have previously declared. Because neither the user nor the calculator can predict which variable will be claimed for solving for, the program must be written having all possibilities being handled.

As you see, right after the 'RCL "X"' there is only one copy of the variable "X" in the stack register 'X'. If you do not copy it into the whole stack, the program will not compute the polynomial expression correctly because any previously existing values in Y, Z and T will be used, instead of the actual "X" value being tested. Think of an expression with two unknowns, like "A" AND "B", whether they repeat or not in the expression. You could choose to solve for either "A" or "B", once the other is known and previously defined (stored). Then the SOLVER will compute the same expression as many times as needed for the chosen variable, and its value will be updated in the variable name itself, not in the stack registers.

You see, when you have a program in the HP15C that is going to be used by the SOLVER or the numerical integrator, it must be programed in such a way that it returns the value of the function being evaluated based in one specific unknown. Some years ago the multivariable 'functionality' of the HP42S SOLVER was proposed for the HP15C by using the index register. It worked pretty fine, and the resulting programs are listed in the article forum somewhere in the far past...

Hopefully I expressed myself correctly... in English, at least.

Cheers.

Luiz (Brazil)

(*) it applies to the HP34C SOLVER and its implementation found in the MATH module for the HP41 as well.


Edited: 1 July 2012, 9:31 p.m.

#19

Quote:
Two weeks ago my sons gave me an HP-42S


Sounds like you raised him well :-).

#20

Thanks, we tried. One went to Notre Dame, the other University of Washington. Both had their minors in mathematics. I try to catch up! Unfortunately, their calculators of choice was the TI-89.


Possibly Related Threads...
Thread Author Replies Views Last Post
  42s questions and 42s vs 35s snaggs 13 675 09-19-2011, 02:44 AM
Last Post: snaggs

Forum Jump: