Hp42s Examples and Techniques - HiRes OCR
Hp42s Examples and Techniques - HiRes OCR
HP-425
A acians
HP-42S
RPN Scientific
Programming Examples and Techniques
HEWLETT
[fifi] PACKARD
The programsthat control your calculator are copyrighted and all rights
are reserved. Reproduction, adaptation, or translation of those programs
without prior written permission of Hewlett-Packard Companyis also
prohibited.
Corvallis Division
1000 N.E. Circle Blvd.
Corvallis, OR 97330, U.S.A.
Printing History
Edition 1 July 1988 Mfg. No. 00042-90019
Contents
6 List of Examples
9 How to Use This Manual
1 12 Programming
12 Simple Programming
13 Flowcharting
15 Defining the Program
15 Prompting for Data Input
16 Displaying Program Results
19 Executing the Program
21 Branching
22 Conditional Branching
25 Subroutines
29 Menu-Controlled Branching
39 Controlled Looping
43 Indirect Addressing in Programs
46 Flags in Programs
46 User Flags
47 System Flags
49 Error Trapping
51 A Summary Program
58 The Triangle Solutions Program
Contents
2 67 Enhancing HP-41 Programs
67 Using Named Variables
68 Using HP-42S Data Input and Output Functions
68 Prompting for Data with INPUT
€8 Displaying Data with VIEW
69 Operations with HP-42S Data Types
69 Using the Two-Line Display
71 Using Menu Variables
73 Assigning a Program to the CUSTOM Menu
3 77 The Solver
77 Basic Use of the Solver
80 Providing Initial Guessesfor the Solver
80 Directing the Solverto a Realistic Solution
83 Finding More Than One Solution
86 Emulating the Solver in a Program
92 Using the Solver in Programs
92 Using the Solver and Explicit Solutionsin a Program
101 Using the SOLVE and PGMSLYVFunctions with
Indirect Addresses
105 More on How the Solver Works
105 The Root(s) of a Function
107 The Solver’s Ability to Find a Root
108 Interpreting the Results of the Solver
123 Round-Off Error and Underflow
4 124 Integration
124 Basic Integration
127 Approximating an Integral That Has an Infinite Limit
131 Using the Solver and Integration Interactively
134 More on How Integration Works
134 The Accuracy Factor and the Uncertainty of
Integration
140 Conditions That Can Cause Incorrect Results
143 Conditions That Prolong Calculation Time
4 Contents
146 Matrices
146 Using the Matrix Editor and Indexing Functions
147 Creating a Named Matrix
147 Using the Matrix Editor
149 Using Indexing Utilities and Statistics
Functions Interactively
150 Matrix Utilities
154 Vector Solutions
154 Geometry
156 Coordinate Transformations
163 Solving Simultancous Equations
168 Using the Solver with Simultaneous Equations
172 Matrix Operations in Programs
174 Statistics
175 List Statistics
181 Using the Summation-Coefficient Functions +,
¥ -, and CLY) in Programs
193 Curve Fitting in Programs
Contents
List of Examples
The following list groups the examples by chapter.
1 Programming
20 Executing a Program from the CUSTOM Menu
32 A Programmable Menu
42 Loop Control in a Program
57 The Flag Catalog Program
3 The Solver
78 Basic Use ofthe Solver
80 Directing the Solver to a Realistic Solution
84 Using the Solver to Find Two Real Solutions
87 Using the Solver for a Simple Resistive Circuit
90 Calculating Complex Values in an RC Circuit
99 Executing Algebraic Solutions for TVM Problems
101 Using SOLVE with an Indirect Address
110 A Case 1 Solution with Two Roots
112 A Case 2 Solution
114 A Discontinuous Function
116 A Pole
6 List of Examples
118 A Relative Minimum
119 An Asymptote
120 A Math Error
121 A Local Flat Region
Integration
125 Basic Integration
128 Evaluating an Integral That Has an Infinite Upper
Limit
131 Using the Solver and Integration Interactively
136 The Accuracy Factor and the Uncertainty of
Integration
138 A Problem Where the Uncertainty of Integration is
‘ Relatively Large
140 A Condition That Causes Incorrect Results
142 Subdividing the Interval of Integration
143 An Upper-Limit Approximation That Prolongs
Calculation Time
Matrices
146 Accumulating Meterological Data
158 The Area of a Parallelogram
161 A Three-Dimensional Translation with Rotation
163 Solving Real-Number Simultaneous Equations
166 Solving Simultaneous Equations That Have
Complex Terms
169 Using the Solver to Find the Value of an Element
in the Coefficient Matrix
Statistics
178 Accumulating Statistical Data in a Matrix
191 A Linear Regression for Three Independent
Variables
List of Examples 7
7 Graphics and Plotting
199 Building a Logo
201 Using Binary Data to Build a Logo
210 Plotting Multiple Functions
219 Plotting Data from a Compression Process
and Fitting a Power Curve to the Data
8 List of Examples
How to Use This Manual
Welcome to the Programming Examples and Techniques manual for your
HP-42S calculator. This manual builds on concepts introduced to you in
the HP-42S Owner’s Manual so that you can more fully utilize your
calculator’s powerful problem-solving capabilities. This manual focuses on
the following subjects:
There are many examples in this manual. We feel that the best way to
help you gain expertise with yourcalculator is to show you how to solve
practical problems in mathematics, science, engineering, and finance.
Many of these problemsare solved using programs. Chapter 1, "Program-
ming," addresses the task of creating programs with the HP-428. It further
develops material presented to you in chapters 8 through 10 ofthe
owner’s manual.
Chapter 7 describes how to generate graphics patterns and plots using the
HP-42S calculator and, in several examples, the optional HP 82240A
Infrared Printer. It builds on the material presented in chapter 7 of the
owner’s manual.
The notations in this manual are consistent with those in the owner’s
manual:
® Simple programming.
= Branching.
s Looping controlled by a counter.
® Indirect addressing.
s Flags in programs.
m Error trapping.
Simple Programming
The program SSS in this section finds the values of the three angles of a
triangle when the values of the three sides are known. (The annotated list-
ing is on pages 17 through 18.)
12 1: Programming
S3
When the dimensions of the three sides (S, Sz, and S3) of a triangle are
known, the following equations are used to calculate the three angles
(Al 9A2’ andA3)‘
A,=2arccos |——————
VPP —sl)]
2 (S2S3)
A, = arccos [ -cos (A3 + Az)]*
Flowcharting
1: Programming 13
Here is a flowchart for one possible program solution for the side-side-
side triangle problem.
CALCULATE
A3
v
CALCULATE
Ao
v
CALCULATE
Ay
v
DISPLAY
AyAsAg
14 1: Programming
This manual uses the following conventions for flowchart symbols:
Bl LBL "gsg
45 END
SSS prompts you for data input (prompts you for the three known values
of the sidesofthe triangle).
B2 INFUT "S51°
83 INPUT “sz2"
84 IHFUT "53"
1: Programming 15
Displaying Program Results
SSS concludes by displaying (or printing) the calculated results (the three
angles).
41 SF 21
42 YIEW "A1"
43 VIEW "R2"
44 YIEW "R3"
This section of the program begins by setting flag 21, the Printer Enable
flag. When flag 21 is set, a VIEW (or AVIEW)instructionis:
16 1: Programming
Helpful hints for keying in programs:
To key in SSS: Create variables S1, S2, §3, 41, A2, A3, and P before
program entry.
Program: Comments:
1: Programming 17
STU IIPII
Are
LASTA
RCLx "2
RCL "S1"
RCLx "5z
S SRORT
HCOS
i a0 ) oo,
Lo 0 03 Q3 Q0 0 00 Q0 P P T3 {0 P P D M) T
¥ I2
STO "AS"
SIN
RCL P
K12
LASTH
RCLx "S1°
9 RCL+ "5
03 =l T i £ IO oD
RCL+ 'S
SERT
G
HLLES
0 n H-E n
CL+ "A3"
RACOS
STO "ALY
18 1: Programming
Executing the Program
You can execute SSS by using any oneof the following keystroke
sequences.
Using the Program Catalog. The global label SSS was automatically
placed in the program catalog when you keyed in program line 01. You
can execute the program by pressing
PCATALOG] FGM . 888
888
This sequence requires a minimum of two keystrokes, depending on
where label SSS is in the program catalog.
Using the CUSTOM Menu. Alternately, you can assign SSS to the
CUSTOM menu by pressing
1: Programming 19
The program can now be executed directly from the CUSTOM menu by
pressing
BCUSTOM) 5885
This sequence requires three keystrokes when you first select the
CUSTOM menu, and only one keystroke on subsequent executions if you
stay in the current row of the menu.
83 =275t
Assign SSS to the CUSTOM menu. Set the angular mode to Degrees.
Execute PRONif you have a printer and wantto print the results. Begin
program execution.
S170.8600
Lsss [ 11|
Enter the value for S, (in feet) and continue program execution.
24 12 [ 5270, 0000
SID
20 1: Programming
calculates the
Enterthe value for S5, then for S3. The program now
executed PRON
three angles and displays 41, the first result. (If you have
ys.)
to print the results, you won’t see the next two displa
1 2.75 Al=129.8384
N
Branching
to a different
A branch instruction enables program execution to jump
location in program memory. A branch can be:
» Conditional (based on a test).
on completion,
s Unconditional (used typically to call a subroutine that,
returns program execution to the main progr am).
m Menu-controlled (executed by you from a programmable menu).
1: Programming 21
Conditional Branching
The program SSA on pages 24 through 25 in this section illustrates the
use of conditional branching. SSA finds the two unknown angles and the
unknown side ofa triangle when two sides and the adjacent angle (S,
S2,and 4,) are known,
. S2] .
Ag=arcsin =] sinAd,
Sy
Note from the drawing that two possible solutions exist if S, is greater
than S; and A3 does not equal 90°. This leadsto a fourth equation.
22 1: Programming
SSA
LBL
SSA
INPUT
S1.55, A
Y
CALCULATE
Ag
v
CALCULATE
Ay.S;
Y
DISPLAY
RESULTS
NO
CALCULATE
A’
3
v
CALCULATE
Ay Sy
v
DISPLAY
RESULTS
1: Programming 23
Observe from the flowchart that the program calculates the first answer
set, then compares the values of S, and S;. Depending on the result of
the comparison,the program either returns to label SSA or calculates the
second answerset. SSA accomplishes this with a conditional branch. The
corresponding keystrokes are highlighted in the following annotated list-
ing. (This conditional branch is based on a number test. Later in this
chapter, you’ll write programs that make conditional branches based on
flag tests.)
To key in SSA: Create variables S1, S2, $3, 41, A2, and A3 before pro-
gram entry. (These variables already existif you keyed in program SSS.)
Program: Comments:
86 { 157-Bute Pram 2
A1 LBL "SSA"
B2 SF 21
24 1: Programming
STO "s53"
VIEW "A1" Lines 24~ 26: Display (or print) the
VIEW "S3" unknown variables.
VIEW "A3"
RCL "S1" Lines 27-30: Test if S, is less than or
s RCL “g2" equal to S, . If so, return to the begin-
5 HEY? ning of the program. If not, calculate
GTO “SSA" the second answer set.
sTO 53"
VIEM "A1" Lines 49 - 52: Display the second
VIEW "53" answerset and return to the beginning
VIEW "A3" of the program.
GTO "SSA"
EMD
1: Programming 25
Subroutines
Notice that SSA calculates the second answer set (if there is one) by first
calculating 45" . It then calculates the remaining unknowns using the
same equations that were used to calculate thefirst answer set and
displays the second answer set using the same instructions that were used
to display the first answerset. By placing these shared instructions in a
subroutine, the program becomes:
m Shorter.
s Easier to read.
= Easier to write.
m Easier to edit.
26 1: Programming
SSA2
INPUT
—)
S1.8.4
Y
CALCULATE
A3
Y
XEQ
B-=<>
SSASUB
ALCULATE CALCULATE
A ’
3 Ay S
Y
XEQ
v
DISPLAY
SSASUB RESULTS
, RTN
To key in SSA2:
1. Create variables S1, 52, $3, 41, A2, and A3 before program entry.
2. Create label SSASUB when you begin program entry.
1: Programming 27
Program: Comments:
0e { 137-Byte Pram >
01 LBL "SsAz2"
a2 SF 21
a3 INPUT "S1"
04 INPUT "S2°
@5 INPUT "R2"
1: Programming
25 +--
26 RACOS
z7 5T0 "A1"
2% RCL "A2"
29 CDsS
Ze RCLx "g2"
=1 RCL "A3"
22 COS
@3 RCLx "S1"
24 +
35 STO "S3t
36 VIEW "ALY
37 WIEW "g3"
22 VIEW "R3"
22 RTH
48 EHD
SSAZ2is 13 lines shorter than SSA and 20 bytes shorter than SSA.
Menu-Controlled Branching
Programmable menus enable you to make a decision during a program,
prompted by labeled menu keys that cause branches to new locationsin
program memory. Using KEY XEQ or KEY GTO instructions (which act
just like XEQ and GTO instructions), any label in program memory can
be madethetarget of a programmable menu key. When MENU and
STOP instructions are subsequently executed, program execution is
suspended, the programmable menu is displayed, and keys 1 through 9
(the six top-row keys, plus the [a], [¥], and keys) assume their
menu definitions.
1: Programming 29
The previous two programs, SSS and SSA,each calculated one ofthe five
triangle solutions. The other solutions respectively find:
® S3, Az,and Ss(when 44, S, and A, are known).
® S;, S3,and A5 (when S,, 4,, and A, are known).
B A, S3,and 43 (when S;, 4,, and S, are known).
1A o0
TRIA
BUILD MENU
DISPLAY MENU
AND STOP FOR INPUT
KEY 1 KEY 2 KEY 3 KEY 4 KEY 5
“SSs* "SSA" *ASA" “SAA" "SAS"
XEQ XEQ XEQ XEQ XEQ
i
B Cc D E
v v v
@)
XEQ RESULTS
30 1: Programming
7
INPUT
S1,82,83
INPUT
S1,82,A2
¥ 7 7
INPUT
Aa,S1,A1
INPUT
S1,A1,A2
INPUT
S1,A1,S2
@—
RESULTS
RESULTS
CALCULATE
CALCULATE AREA
F———————— e ————— -
(SSASUB) Ay’
v
DISPLAY
CALCULATE XEQ INPUTS,
Ay,S3 SSASUB RESULTS
RTN RTN
v
1: Programming 31
The triangle symbol in the flowchart indicates where the program stops to
display the menu. You choose which solution you wantto execute by
pressing the corresponding menu key.
Program: Comments:
32 1: Programming
Aq=98°127
Sy=171.63m Sp=207.35m
Set the angular mode to Degrees. (Execute PRON if you want to print the
results.) Begin program execution.
IN ICHETN T.
Keyin the values for A, (you need to convert A, to its decimal equivalent)
and S,. The program calculates the unknowns and displays the initial
known values and calculated results.
1: Programming 33
Press again to see Sj.
53
%
A multirow menu has more than one row oflabeled keys. (For example,
the CLEAR menu has two rows.) When you enter a multirow menu,the
(¥) and (&) keys enable you to move to each row in the menu. (The va
annunciator appearsin the display to show you that these keys may be
used to display more rows.)
34 1: Programming
Consider the following simple menu ofcalculator functions.
VA
R
VA
KR Y
e
To key in ROW1:
1. Create labels ROW1, ROW2, and ROW3 when you begin program
entry.
2. Note that program lines 03, 05, 07, 16, 18, 20, 29, and 31 are Alpha
strings.
Program: Comments:
08 { 184-Buyte Pram
@81 LBEL "ROW1"
1: Programming 35
14 LBL "ROW2" Lines 14 -26: Clear the current menu
15 CLMEHNU definitions, then build and display the
16 IIR¢II
second row of the menu. Assign
17 KEY 3 XKEQ 94 branch instructions to keys 7 and 8 to
18 "SIN" the previous and succeeding rows
19 KEY 4 XEQ 85 respectively (lines 22 -23).
z2e "cos"
21 KEY S XKEQ B8
22 KEY v GTO "ROW1™
23 KEY & GTO "ROW3"
24 MERU
25 STOF
26 GTO "ROW2"
1: Programming
50 LBL @5
51 SIN
S52 RTH
53 LBL 96
54 COS
55 RTN
56 LBL B7
57 ROV
58 RTH
59 LBL @8
68 +/-
61 RTH
62 END
Nested Menus. In many menus, one or more ofthe six top-row menu
, in
keys bring up a new menu called a nested, or submenu. For example
a nested
the PGM.FCN menu, when you press the =¥7@ menu key,
X#0?, ..., X>0?) is display ed. To return
menu of related functions (X=0?,
to the main menu, you press the key.
To key in LVL1:
1. Create labels LVL1 and LVL2 when you begin program entry.
2. Note thatlines 03, 05, 07, 14, 16, and 18 are Alpha strings.
1: Programming 37
Program: Comments:
ag { 188-Bute Pram >
a1 LBL "LwL1"
GTO "LwvLz"
-+
24-38: Execute the calculator func-
RTH tions corresponding to each menu
LEL 82 label.
RTHN
LEL 11
SIN
RTH
LEL 12
Cog
o
1: Programming
35 RTHN
36 LBL 13
37 TAN
32 RTHN
39 EHND
Controlled Looping
A controlled loop is a loop that is executed a specified number oftimes.
You can build a controlled loop with a local or global label, an ISG or
DSE instruction, and a GTO instruction.
X =xp+Wvt
where:
1: Programming 39
Here is a flowchart for DISPL.
DISPL {BL
DISPL
INPUT
Xg 1V t; STEP
v
BUILD COUNTER
FROM t, , STEP
VIEW
X
INCREMENT
t
=
The program segmentthat uses a controlled loop to calculate successive
values ofx is highlighted in the following annotated listing.
40 1: Programming
To key In DISPL: Create variables x, x0, v, tF, STEP,fff, ii, and COUNT
before program entry.
Program: Comments:
88 { 110-Byte Pram 2
@1 LBL "DISPL"
B2 SF 21
28 END
1: Programming 41
Example: Loop Control in a Program. Find successive values of
the displacement x of an object in intervals offive seconds from ¢ = 0 to
t = 15 seconds when x, = 10 meters and v = 20 meters/second.
The value ofx at ¢ = 0 is 10. Press again to display the value ofx at
t=35.
T
Press to see the value ofx at t = 10.
T
Press againto see the value ofx at ¢t = 15.
A
Press again to prompt for new values. Exit from the program.
[@73) [EXm) 0.0000
% 10,6000
42 1: Programming
Indirect Addressing in Programs
Indirect addressing is a useful programming tool, particularly when used
in combination with a controlled loop. The operation index in your
owner’s manual indicates which functions can use indirect addresses. In
this section, three applications of indirect addressing in programs are
presented.
B2 EHD
1: Programming 43
Using Indirect Addressing to Clear Registers. The following
routine clears a specified number of storage registers using STO IND in a
controlled loop.
Program: Comments:
a0 { 74-Byte Pram >
a1 LBL "CLEARR"
4 1: Programming
Using Indirect Addressing to Execute Subroutines. The follow-
ing routine retrieves data (telephone numbers) from subroutines using
XEQ IND.
Program: Comments:
oo { 134-Byte Pram 2
a1 LBL "PHONE"
24 EHD
1: Programming 45
Flags in Programs
Earlierin this chapter you wrote a program SSA that makes a branch
based on a numbertest; specifically, SSA uses the X<Y? function to con-
struct the branch. The program asks the question: Is S < S, ? Then it
makes a decision based on the answer —either calculate the second answer
set or end the program.
The X?0 and X?Y sets of functlons enable programsto ask questions only
concerning numbervalues.© However, programscan also make condi-
tional branches (ask questions and make decisions) based onflag tests.
Flag tests follow the "do-if-true” rule. If the testis true, the next instruc-
tion is executed. If the testis false, the next instruction is skipped.
Because flags have unique meanings for the calculator, they greatly
expand the logic control you can exercise in a program. (User flags 00
through 35 and 81 through 99 may be set, cleared and tested. System flags
36 through 80 may only be tested. Refer to appendix C in your owner’s
manualfor a complete listing of the HP-42S flags and their meanings.)
User Flags
Flags 00 through 35 and 81 through 99 are user flags; they may be set,
cleared, and tested.
* The X=Y? and X£Y? functions are exceptions; they can compare Alpha strings.
46 1: Programming
The program LIST on pages 176 through 178 creates a matrix ZLIST
using the following instruction sequence.
31 LBL A2
32 1
33 ENTER
34 FC? 91
25 2
26 DIM “"ELIST"
37 KER I
38 Ry
39 R+
48 GTO 84
Before you execute LIST, you set flag 01 if you want ELIST to be a 1-
column matrix, or you clear flag 01 if you want ZLIST to be a 2-column
matrix. Flag 01 is defined to have a unique meaning in the program,;its
status determines the number of columnsin the matrix XLIST.
(Rememberthat currentstatus of user flags is maintained by HP-42S
Continuous Memory. This can affect other programsthat use the same
flags.)
System Flags
System flags 36 through 80 also have a specific meaning for the calculator.
You cannot directly set or clear these flags. However, you can test them.
1: Programming 47
MINMAX also uses general purpose flag 09 in line 08 to determine
whetherto search for the maximum or minimum element of the matrix,
Before you execute the program, you set flag 09 to find the maximum ele-
ment, or clear flag 09 to find the minimum element.
g2 STO "MIHMAX"
B2 IHDEX "MIMMAR®
a4 RCLEL
B85 GTO B3
Bc LEL 01
87 RCLEL
82 FS? B9
B9 GTO &2
18 XaY?
11 GTO b4
12 GTO B3
12 LBEL B2
4 RLY?
15 GTO a4
& LEL B3
— —_ .
0 0 =g
7 RCLIJ
e RCL ST
-l
EHTER
LEL &4
Po3 o [ P M
=
R+
e
J+
Y
FC? 77
GTO a1
Ja
S END
J
i
48 1: Programming
Error Trapping
When you attempt an improper operation during function execution, the
operation is not executed and an explanatory message is displayed. For
example,if you execute the keystroke sequence
1 [E 2600(x?)
the calculator returns the message Out of Range, and leaves the value
1 x 10*° in the X-register.
If you execute TRAP and supply the value 1 10% for X, the program
halts at line 03 and the calculator displays the message Qut of Range.
To supply a new value for X, you must restart the program at line 01 (by
pressing “TRAFY). In a short program like TRAP,this method of
recovery from an error presentslittle problem. However, when executing
a program that performs time-consuming calculations, or that has
numerousstops for intermediate data entry,it may be inconvenient to
restart the program at line 01 each time an error occurs.
1: Programming 49
You can enable program execution to continue after an error has occurred
by setting flag 25, the Error Ignore flag. When flag 25 is set:
88 { S8-Bute Pram 2
@l LBL "TRAP"
a2 SF 21
863 SF 25
@4 [HPUT "X
05 ¥+2
Qe FC?C 25
By GTO pBa
B2 STO "y
a3 MIEW "y"
18 GTQ "TRAP"
11 LBL @@
12 CF 21
12 EBEEFP
14 "0Qut of Range"
15 AVIEW
16 PSE
17 PSE
12 GTO "TRAF"
1% EHD
50 1: Programming
A Summary Program
flags 00
The program FCATin this section displays the currentstatus of
ow menu in sets of six.
through 99. The flags are displayed in a multir
a flag number . You can set and
Each of the menu keysis labeled with
lag 25) and 81 throug h 99 by press-
clear user flags 00 through 35 (exceptf
"u" charact er is append ed to the
ing the corresponding menu key. The
a
menu labelif that flag is currently set. When you attempt to set or clear
system flag, FCAT beeps and display s the error messag e Restr icted
menu
Dperat ion. The previous set of six flags is displayed by pressing
key 7 ([a]), and the succeeding set is display ed by pressin g menu key 8
(V).
FCAT uses many of the programming concepts discussed in this chapter:
# Global and local labeling.
® Prompting for data input.
w Conditional branching based on:
= Numbertests.
m Flag tests.
Subroutines.
Multirow menus.
Counter-controlled looping.
Indirect addressing.
Error trapping.
1: Programming 51
Here is a flowchart for FCAT.
O
INITIALIZE
BUILD A MENU
OF SIX FLAGS
v
KEYS 1 THRU 6 KEY 7 KEY 8
(PAGE UP) (PAGE DOWN)
TOGGLE FLAG
Y
DECREMENT
COUNTER BY 6 RESET
COUNTERTO 0
YES
ERROR ?
*RESTRICTED
OPERATION"
MESSAGE
RESET
COUNTER TO 96
52 1: Programming
Here is the annotated listing.
Program: Comments:
B8 { 234-Byte Pram 2
@l LBL "FCAT"
1: Programming s3
LEL a8 Subroutine 00, lines 26-37; Build the
~J T B 0 Y= @D 0~
G0 0y (0 0 ) ) N M
1: Programming
53 SF 23 Lines 53— 56 build the set/clear toggle
54 FC?C IND ST X and errortrap: Set the Error Ignore
55 GTO 89 flag (line 53). Test if the flag (whose
56 GTO A number value is in X) is clear, then
clear it (line 54). If the flag was clear
when tested in line 54, or the attempt
to clear causes a Restricted Operation
error, go to label 09 (line 55). If the
flag wasset, and the clear operation
does not cause a Restricted Operation
error, return to the menu-label rou-
tine to update theflag status (line 56).
1: Programming 55
’e LeL B8 Lines 70~ 73: Increment R o by 6 using
71 ISG 06 the ISG function. (Remember that the
ra GTO A number in R, is the loop counter; it
73 GTO "FCAT" has theinitial value 0.09906. When (&)
is pressed, the top row menu keys are
each relabeled with the numberthat is
six greater than in the previous menu,
When the countertest value exceeds
96, program executiontransfers to
FCAT,restoring the counter to its ini-
tial value; the menu keys are thus rela-
beled 0-5.)
74 LBL 18 Lines 74 -89: Execute the BEEP func-
7S FsS?C 21 tion, display the Alpha message
7E GTO 11 Restricted Operation, and
7 XE@ 12 transfer program execution back to
e GTO A label A.If flag 21 is set, clear it before
79 LBL 11 displaying the Alpha message, then
88 REQ 12 reset it. (Program execution continues,
81 SF 21 redisplaying the flag menu, and the
82 GTO A status offlag 21 is maintained.)
83 LBL 12
84 BEEP
g5 "Restricted "
26 F'Operation”
ar RAYIEHW
88 PSE
89 RTH
98 EMHD
1: Programming
Example: The Flag Catalog Program. Use FCAT to set flag 01.
Check the statusofflag 38. Attemptto set or clear it.
Start FCAT.
FLAG CATALOG
Lo2234]5§
1: Programming 57
The Triangle Solutions Program
This section contains the complete set of equations for the triangle solu-
tions,instructions for keying in TRIX., an annotated listing of TRI XA, and
instructions for using TRIX .
A4
Ag Az
58 1: Programming
@ Condition 2: S;, 2, and A3 (two sides and the adjacent angle) are
known:
| 1S2] .
Ag = arcsin == sinA4,|*
Sy
S S SinA3
S e
S3=S8,¢c084; + SycosA,
m Condition 4: S, A4,, and A, (one side and the following two angles)
are known:
* Two possible solutions exist if §, is greater than S, and A, does not equal 90°. Both
possible answersets are calculated.
1: Programming 59
To key in TRIX :
1. Create variables S1, 52, §3, 41, A2, A3, P, and AREA before pro-
gram entry.
2. Create labels RESULTS and SSASUB when you begin program
entry.
Program: Comments:
08 { 573~Bute Pram 2}
81 LBL "TRI&"
82 SF 21
60 1: Programming
26 STO " P "
27 Rr2
28 LASTX
29 RCLx "S2"
30
31 RCL "S1"
32 RCLx "S53"
33
34 SART
35 ACOS
36 2
37 X
38 STO "A3"
39 SIN
49 RCLx *S1"
41 STO @@
42 rRCL "P"
43 Rr2
44 LASTH
45 RCLx "S1*
46
47 RCL+ "“"s2"
48 RCL+ "&3"
49 SERT
58 ACOS
51 2
52 %
53 STO "A2"
54 RCL+ "A3"
S5 cos
56 4
57 ACOS
S8 5TO "AL"
59 RTH
68 LEL B Subroutine B,lines 60— 100: Calculate
&1 INFUT "&1" the SSA solution.
&2 INFUT “52"
63 INPUT "A2"
1: Programming 61
64 SIN
65 RCLx "g2"
66 RCL+ "St*
67 RSIN
68 STO "A3"
69 SIN
78 RCLx "si*®
71 STO 0@
72 XKER "SSAsSUB"
73 RCL "S1*
74 RCL "s2"
7S RLY?
76 RTH
77 XEQ “RESULTS"
78 RCL "A3"
79 COs
88 +-~
81 ACOS
82 STO “A3"
83 XEQ "SSAsSUB"
84 RTN
85 LBL “SsAsus*
86 RCL "RA3"
8¢ RCL+ "R2"
88 COs
89 +/~
968 ACOS
21 STO "A1"
92 RCL "“RA2"
93 CO0S
94 RCLx "g2"
95 RCL "A3"
96 COS
97 RCLx "siv
98 +
99 STO "S3"
188 RTH
62 1: Programming
181 LBL C Subroutine C, lines 101 —126: Calcu-
162 IMFUT "Az" late the ASA solution.
162 IHPUT "3S1"
184 IWFPUT "AL1"
185 RCL "R
186 RCL+ "ALY
1897 COS
188 +--
199 ACOS
116 STO "R2"
111 RCL "A3"
112 RCL "S51"
112 »REC
114 RH4xY
115 =TO S8
121 S0 "s2"
122 Rr
124 +
125 STO 53
126 RTH
1: Programming 63
*REC
RE>Y
STO an
RCL "AZ"
1
*REC
R+
STOQ g2
R+
X
+
sTO "s3v
RTH
2 RCL+ "Slu
REL+ "SEH
3
el
" F. "
o o
b
=
-)
LASTH
e
"2
e e e
a 03 fa3 e o
RCL»
=) ]
"St®
=g =g oy
RCL
SHRET
-
1: Programming
173 ACOS
ive 2
177 x
178 STO "A3"
179 SIN
186 RCLx "S1*
181 STO 99
182 rRCL "P"
183 xr2
124 LASTX
185 RCLx "51"
186
187 RCL+ "s2"
188 RCL+ "83"
189 SERT
198 ACOS
191 2
192 X
193 STO "R2"
194 RTH
283 EMD
1: Programming
To use TRIX :
1. Press TRI&.
2. Select a solution by pressing the corresponding menu key.
3. Input values as prompted. You can name any side §,. A, is the
adjacent angle. You can enter valuesin a clockwise or counterclock-
wise order. The values are displayed in the same orderas they were
entered.
66 1: Programming
2
Enhancing HP-41 Programs
In chapter 11 of your owner’s manual, you keyed in and executed a pro-
gram originally written for the HP-41 calculator. That program, named
QUAD, solves for (real number) roots of quadratic equations. Two pro-
grams Q2 and Q3 in this chapter use HP-42S features and functions to
enhance QUAD.A third program QSHORT uses only 11 linesto solve
for quadratic equation roots.
The HP-42S INPUT function enables programs to prompt for data in one
program line.
QUAD promptsfor the value of &, then stores the value 2a in a data
storage register with the three-instruction sequence
n a='? 1
oo
Fh 0 R
: PROMPT
5 STO 88
Q2 uses INPUT (and the named variable @) to replace these three
instructions with one.
a2 INFUT "a*
The HP-42S VIEW function enables programs to display data in one pro-
gram line.
29 “ROOTS="
38 ARCL ¥
31 AYIEM
Q2 uses VIEW (and the named variable R1) to replace these three
instructions with one.
22 VIEW "R1I™
Program: Comments:
80 { 132~Bute Pram I Lines 01— 05: Display the 0-input error
81 LEL a8 message.
gz "Zero Input Inwa"
B2 F"lid.%Fress R~s3"
B4 +" to continue."
85 PROMPT
SIGH
-b + Vb2 - 4qc
2a
or
-b - Vb? - 4dac
2a
48 END
Program: Comments:
ae { 143-Bute Prgm ?
o1 LBL 90
a2 "Zero Input Inva"
a3 F"lid.%“Press RsS"
a4 F" to contirnue."
a5 FPROMPT
14 RCL "a"
15 X=@7
16 GTO a0
1v RCL "c"
18 K=07
12 GTO &
28 RCL "b"
+/-
P PO MY T3 P D) M M
=) o R WM —-
EMTER
®+2
4
RCLX "a"
FCLx "e*
SORT
E‘I::L Ilbll
03 03
= I O
SIGH
®
oz
BEASSIGN] FGH - 03
then selecting the desired row of the menu and pressing the desired menu
key in that row. The program now can be executed directly from the
CUSTOM menu with one keystroke.
Part 1. Execute Q3 from the CUSTOM menuto find the roots of the
equation
R2=-8.1716
TN NNN.
Set the angular mode to Rectangular. Enter the values for a, b, and c.
Then calculate R1. (If you are printing the results, you won’t see this
display.)
RECT R1=-8.2500 -il.1990
1. E
82 -a.5
B3 x
84 ENTER
85 ENTER
Qe ¥r2
a7 RCL- ST T
83 SORT
89 STO+ ST 2
18 -
11 EMD
4. Press ‘SHO.
3: The Solver 7
e. Find the value of the unknown variable by pressing the
corresponding menu key.
PV =nRT
where:
Part 1. Create a program for the Solver that declares the variables and
expresses the equation.
PV -nRT =0
Now write the program.
Program: Comments:
@3 { 42-Bute Pram X
@1 LEL "GAS"
Bz MVWAR "P" Lines 02 ~-05: Declare the variables.
BE: r.1 I'"IHE n I.‘.I n
B4 MYAR "n"
85 MYAR "T"
A& RCL “"P" Lines 06— 12: Express the equation
BF RCLx "y such thatits right side equals 0.
83 BCL "m"
83 RCLx “T"
18 @.822857
11 =
12 -
12 EHD
78 3: The Solver
Part 2. Use the Solverto find the solution to the following problem.
423 .1
Part 3. Given the same volume and weight of oxygen, what is the tem-
perature of the gas at a pressure of 15 atmospheres?
Since the values of the volume and weight are unchanged, you need only
enter the value of the pressure.
5. P=15. 0000
D W T S A
80 3: The Solver
Part 1. Write a Solver program that declares the variables and expresses
the equation suchthatits right side equals 0.
68 { 45-Byte Pram
B1 LBL "COHE"
g2 MVAR "v"
83 MVYAR "h"
B84 MYAR "a"
85 MVYAR "b"
g6 RCL "a"
a7y ®+2
88 LASTH
B89 RCLx "b"
18 +
11 RCL "b"
12 ¥+2
13 +
14 RCLx "h"
15 PI
16 %
17 3
18 =
19 RCL- "y
28 END
For the purposes of this example, assume that you have already created
variable ¢ and used it in a previous program. Assume that the value
-3.7765 is currently stored in a (Go ahead now andstorethat value in ¢
by pressing 3.7765
3: The Solver 81
Part 2. For a frustum of volume V' = 119.381 meters®, height 4 = 6
meters, and radius b at the base of the cone = 3 meters, use the Solver
to
find radius a .
a=-3.0000
IINA
The value 2.0000 meters for radius @ is mathematically valid and has phy-
sical significance.
82 3: The Solver
Finding More Than One Solution
The equation of motion for an object experiencing constant acceleration
due to gravity is
Y =Yo+vol + %8‘2
where:
3: The Solver 83
To find both times ¢, and ¢, you must execute the Solver twice, and at
least once provide the Solver with an initial guess to directit to the second
solution.
Part 1. Create a Solver program that declares the variables and expresses
the equation such thatits right side equals 0.
a8 { 353-Bute Pram 2
81 LBL "MOTION"
a2 MYAR "y"
83 MYAR "yB"
a4 MVYAR "va"
B85 MVARA "t
as RCL "QB"
ar RCL "v@"
ag RCLX lltll
a9 RCL Iltll
18 K2
11 -2.8
12 *®
13 2
14
15 +
1e +
17 RCL_ Ilgll
1a EMD
84 3: The Solver
Part 2. Exccute the Solver to find the first time ¢; . Since you know that
this time is close to 0 seconds, provideinitial guesses of 0 and 1.
The Solver finds the value of ¢, = 0.2151 seconds. Now find the second
time ¢, by providing two initial guesses that you can expect to bound the
second solution. Guesses of 1 and 20 seem reasonable. (You need not
enter values for the other variables since they have not changed.)
=2.8461
v [weooT1|
3: The Solver 85
Emulating the Solver in a Program
For certain types of functions, the Solver algorithm cannotfind solutions.
For example, the Solver cannotsolve for complex numbers. However, for
such functions, you can write a program that finds explicit solutions and
acts like the Solver during program execution.
R
m
E=1IR
Since there are no complex termsin this equation, the Solver can be used
to find the value of any variable in the equation.
86 3: The Solver
t. For
Example: Using the Solver for a Simple Resistive Circui
the
a simple resistive circuit, use the Solver to find the resistance R when
voltage E = 10 V, and the current I=5A.
es
First, create a Solver program that declares the variables and express
the Ohm’s law equation such thatits right side equals 0.
@p { 29-Byte Pram 2
@1 LBL "CIRCUIT"
82 MVAR "E"
63 MVAR "I"
@4 MVAR "R"
8s RCL "1
@6 RCLx "R"
8?7 RCL- "E"
B8 EMD
3: The Solver 87
Now consider the following circuit.
W
€
E=1Z
where:
R - [—1]
wC
where:
Because the voltage, current, and impedance are complex numbers, you
cannot use the Solverto find their values. However, the HP-42S can per-
form grithmetic operations on complex numbers. (Refer to chapter 6 in
your owner’s manual for a discussion of complex-number arithmetic.) The
following program, EIZ, solves explicitly (algebraically) for the complex
numbers E, I, and Z, and uses a variable menu to simulate the external
appearance of the Solver. (Referto the section "Using a Variable Menu"
in chapter 9 of your owner’s manual for a discussion ofvariable menus.)
88 3: The Solver
Here is an annotated listing of the program.
Program: Comments:
8o { 96-Byte Prom
a1 LBL "EIZ2"
3: The Solver 89
26 LBL "24" Subroutine Z 4., lines 26 -29: Calcu-
27 RCL "Eg" late Z& interms of EX and IX.,
28 RCL+ "Ix"
29 RTN
38 END
|><: B.bopo I
SWNNN
@OPFCN) 1¢x
The circuit capacitance is .001 F.
If, at the original input voltage, the impedance is now varied and measures
20 01 at phase angle —45°, whatis the current?
Return to polar mode. Then enter the new value for the impedance and
solve for the current.
3: The Solver o1
Using the Solver in Programs
92 3: The Solver
In the example in your owner’s manual, you wrote a program TVM that
declares each of the TVM variables and expresses the TVM equation.
The Solveris used to find the solution for each of the function variables.
Notice, though,that the variables PV, N, FV, and PMT can each be iso-
lated. For example, PV can be expressed as
Only the variable i cannot be isolated; you need to use the Solver only
when you want to find the value of i.
Program: Comments:
88 { 533-Bute Pram ¥
@81 LEBL "Tvmz"
3: The Solver 93
LBL 99 Lines 16 -35: Build the main menu,
QO 0x D) G Q)WM M M o M N M o —_ s e e
N oF 0 Mo @D 0w =~ o [V I~ O 0N
KEY 2 XERQ 82
H plv! n
KEY 3 XEQ 83
"PMT"
KEY 4 XER B4
"Fll'll "
94 3: The Solver
49 LEL @6 Lines 49 -62: Build and display the
S50 XER 28 payments-per-year and payment-mode
51
" P/YR LU
menu.
‘52 KEY 1 XE@ 21
23 "BEG"
o4 KEY 2 XEQ 22
S5 "EMD"
56 KEY 3 XER 23
o7 "TVHM"
58 KEY 4 GTO "Tv¥mMz"
59 MENU
&g RCL "Ps¥R"
61 STOP
62 GTO @6
3: The Solver 95
82 LBL @1 Subroutine 01, lines 82-107: If
83 IINII numeric input is made for N, return to
84 FS?C 22 the main menu and display the value
85 RTHN of N. If not, calculate N in terms of
86 1 the other variables. If i = 0, go to label
8¢ STO “H" 00 to calculate N (lines 93-95).
88 XEQ 18
89 RCL "Fy"
98 RCL+ "MODE"
91 +/=
92 RCL "PMT"
93 RCL "i"
94 ®=a7
95 GTO o8
26
97 +
28 LASTX
99 RCL "Pv"
108 RCL+ "MODE"
161 +
182
183 LN
184 RCL "i"
1835 LN1+X
106
187 RTH
3: The Solver
114 LBL @2 Subroutine 02, lines 114-123: Use the
115 " I:,:YR n
Solverto calculate I%YR. Specify the
116 FS?C 22 Solver subroutine "i". Supply initial
117 RTH guesses of 0 and 20 for I%YR.
118 PGMSLY "i"
1139 8
120 sSTO “IXYR"
121 28
122 SOLVE "IxYR"
123 RTH
148 +
141 +/ -
142 RTH
3: The Solver 97
149 RCLx "Fy"
158 RCL+ "PV"
151 XC>Y
152
152 +/-
154 RTN
STo 5T 2
b
20
ek
0D
RCL= “MODE"
ek
O
SF 25
Pt bk
COO0
T N
F:I:L_:_ n i "
3: The Solver
187 FS?C 25
182 RTHN
To use TVM2:
1. Press TUME .
2. Supply values for the known variables. For example, press 60
H
3. Solve for the unknown variable by pressing the corresponding menu
key.
4. TVM?2uses the variable I%YR to prompt for and display the
interest rate. I%YR is the percent form of the annualized interest
rate.
5. The default payment period is one month (12 payments per year).
The default payment timing is the end of each period. To specify a
different payment period or payment timing,first select the MODE
menu. Then, for example,to specify six payments per year, press 6
EoYER
3: The Solver 99
Set the displayformat to FIX 2. Then execute TVM2.
12 P/YR END M
-:-m
5750 PV FV=0.00
10.5 1%YR IKBTA TNRS
36N
0 F¥
The explicitly calculated value is —186.89 (the same as when you used
TVM) and the calculation takes less than one second. Also note that the
calculation time is independent of the previously calculated value PMT.
(The Solver interprets the previously calculated value as a guess if two
guesses are not supplied. The explicit solution does not use guesses.)
TVM uses the Solverto calculate the new interest rate. The Solver uses
the guesses 0 and 20 (supplied by the program) to startits iterative search.
The calculation takes about 11 seconds.
In the previous section, you used the SOLVE function in TVM2to find
the value of the interest rate i in the TVM equation:
You used the PGMSLYVfunction to specify the routine that expresses the
TVM equation:
PV -nRT =0
The "van der Waals" equation ofstate refines the ideal gas equation to
[+ P+ 2w 2
-m)
2 (v -nb)|-nRT =0
Part 1. Write a program that enables you to solve for the value of any of
the variables using either the ideal gas or van der Waals equation ofstate.
(GAS2)
v
DECLARE MENU
VARIABLES
v
DISPLAY VARIABLE MENU
FOR DATA INPUT
KEY 1 iKEYZ ¢KEY3 iKEY4 ¢KEY5 KEY 6
V llPlI Ivll -nl ITI Ial V Ibl
STORE NAME OF
UNKNOWN VARIABLE
FROM ALPHA REGISTER
TO VARIABLE CONTROL
Y
SPECIFY SOLVER
PROGRAM WAALS
y
SOLVE FOR
UNKNOWN VARIABLE
¢
VIEW SOLUTION
EXPRESS THE
VAN DER WAALS
EQUATION
& v
Program: Comments:
88 { 129-Byte Pram
@81 LBL "GRS2"
Execute GAS2.
GHE2 %: 8. 0000
Ill:lllflllnllllllllnllmlfl
250 H b=0.08427
2750y (PvN¥|E]
359 A
0427 B
Using the van der Waals equation ofstate, the predicted pressure is
25.9816 atmospheres.
Now use the ideal gas equation to predict the pressure. Simply supply the
value 0 for @ and b and solve for P. The previously calculated value for P
serves as an initial guess.
0 H P=27.8248
0. B f » N7 #E]
EXIT
Setting the equation equalto 0 by subtracting the termson the right side
from both sides gives
To use the Solver, you now write a program that declares the variables x,
y, and z and expresses the equation. When you select the Solver applica-
tion and,for example, supply the value 2 for y, and 3 forz, by substitution
the equation becomes
2x2-7x -2=0
where:x is the unknown variable and f(x) = 2x% - 7Tx - 2. Each value x
for which f(x) = 0is called a root of the function. The Solveriteratively
f(x)
All except one of the functions in the examples in this section are func-
tions of one variable x only. Remember, though,that the situations
described in the examples apply equally to multivariable functions, since
multivariable functions become single variable functions when, in the
Solver application, you supply values for the known variables.
m Two estimates yieldf(x) values with opposite signs, and the function’s
graph crosses the x-axis in at least one place between those estimates
(figure 3-1a).
® f(x) always increases or always decreases as x increases (figure 3-1b).
m The graph off(x) is either concave everywhere or convex everywhere
(figure 3-1c).
= Iff(x) has one or more local minima or maxima, each occurs singly
between adjacent roots off(x) (figure 3-1d).
f(x) f(x)
A A
.
|
"
1
b X e X
)
a - b
f(x) f(x)
m The X-register contains the best guess. This guess may or may not be
a root ofthe function.
m The Y-register contains the previous guess.
s The Z-register contains the value ofthe functionf(x) evaluated at the
best guess.
m The T-register contains a code 0~4 that indicates the Solver’s
interpretation ofits search for a root. (This code is displayed in the
current display mode; in FIX 4, code 0 is displayed as 8.@0880.).
When a Root Is Found. There are two cases in which a root is found:
a b
w Viewing the contents of the Z-register (the value off(x) at the calcu-
lated root). For a case 2 solution,it will be a nonzero number.
m Comparing the best guess (the contents of the X-register) and the
previous guess (the contents of the Y-register). For a case 2 solution,
the guessesdiffer by 1 in the 12th digit.
w Immediately solving again for the variable. For a case 2 solution, the
Solver will return the message Sian Reversal on the second
attemptto find the root.
Example: A Case 1 Solution with Two Roots. Find the two roots
of the equation
2x2-7x -2=0
81 LEL "AR"
B2 MYAR "R"
83 RCL e
Set the display format to ALL. Select the Solver application and then pro-
gram AA,
BODISP) ALE :@
BSOLVER |n-——--|
X=3.769556443708
NIIANANI
The estimatesare the same in all 11 decimal places. Roll the stack con-
tents down to see the value off(x) at the root.
Ix: 0 |
INDT
ftx) is exactly 0. Now enter guesses of ~0.1 and 1 for the second root
and solve.
A fwe =-2.659564437075E- 1
164
3: The Solver 11
Roll the stack contents down to see the value off(x) at the root. Again,
f(x) is exactly 0.
RY) RY x: @
|“-----l
Exit from the Solver and return the display format to FIX 4,
EXIT v: 8. 0000
H(DisP) 4 x: 0. 0000
Using the same valuesfor the variables V, n, and T, solve again for P.
Start program GAS2. (Reenter the program if you have cleared it from
the calculator.)
GASZ2 |><= 0 I
NYOB
Enter the values for the known variables and solve for the pressure.
P=27,8247827273
(Pv[NT&]E|
7 \_ >x
The Solver will return an x-value adjacentto the discontinuity. The value
off(x) may be relatively large.
Select the Solver, select program BB, provide guesses of 0 and 5, and
solve forx.
B(SOLVER) BB |X=2 . pBPO l
ENE DRNNS
The Solver finds a root at x = 2.0000. Now check the value off(x).
BY RY E -9.5000 I
1t{1
The value off(x) seems relatively large. This indicates that you should
further evaluate the function. By plotting the function, you find that the
root atx = 2.0000 is in fact a discontinuity, and not a true zero crossing.
Finally, consider the following function. This function has a very steep
slope in the area of the root. Evaluation of the function at either neighbor
may return a very large value even though the function has a true root
between the neighbors.
o
Use care in interpreting the results of the Solver. The Solver is most
effective when used in conjunction with your own analysis of the function
you are evaluating.
Thefunction has a pole at x,. When the Solver evaluates such a function,
it returns the message Sian Rewsr=zal.
—x
(x* - 6)
Asx approaches V6,f(x) becomes a very large positive or negative
number.
~3 .« 4495
oK 4495
ft)
NN
Relative minimum Asymptote
PX
Relative maximum
x2-6x+13=0
(It has a minimum atx = 3.)
10 - 10
x
Express the function in program EE.
pa { 17-Byte Prgm 2
p1 LBL "EE"
92 MVYAR "X
a3 18
B4 RCL "X"
B85 1-/X%
96 -
a7 END
The Solver finds a root atx = 0.1000. Now enter guesses that have nega-
tive values.
1 R=-1.0D00E 500
2 Extr-emum
v: 9. 9246E498
x: -1, 0000E 560
" X -
W-O.S—O
1 _10-0
X
MWAR *&"
P RCL "R
174
14
" EHD
In this region of the function, the value off(x) is, within the 12-digit preci-
sion ofthe calculator, the same at every sample point. Hereis a graph of
the function.
f(x)
—
Try guesses of 0 and 10.
0 X=0. 1000
LsT[[|
The Solver finds the root ati = 0.1. Exit from the Solver.
v: 8. lfigg
X
[(lx] +1)+10%2 - 10 =0
has no roots because f(x) is always positive. However, given initial guesses
of 1 and 2, the Solver returns the answer 1.0000 because of round-off
error.
Round-off error can also cause the Solverto fail to find a root. The equa-
tion
[x2-7| =0
has a root at v'7 . However, no 12-digit numberexactly equals v'7so the
calculator can never make the function equal to 0. Furthermore, the func-
tion never changes sign. The Solver returns the message Extt-zmun.
However, the final estimate ofx is the best possible 12-digit approxima-
tion of the root when the routine ends.
—1 =0
x2
Basic Integration
124 4: Integration
Example: Basic Integration. The angle of twist in a round shaft
undertorsional loading is calculated by evaluating the following integral.
where:
T =13x*+8x3+15x2+9x + 6
4: Integration 125
Substituting this expression for T, the equation becomes
_ 2 (((13x +8)x +15)x +9)x +6
6=[ G dr
Program: Comments:
81 { S3-Bute Fram 2
@1 LEL "TORGQUE"
28 EMD
126 4: Integration
Supply the known values for J and G,and specify the variable of integra-
tion X.
7.9521 E] 8 4]
Specify the lowerlimit (0), the upperlimit L (2), and an accuracy factor of
0.01.
ECC=0 . 0100 |
STWTNTEEBTNNNNN
S=0.8281
OTEEETHTERTSNNNR
[X: ¥
[fee) de
is calculated "by hand" by evaluating the equivalent expression
lim,oo, fG&) dx
4: Integration 127
You cannot use the HP-42S to directly evaluate such an expression. You
can, however, approximate an answer by substituting a large number for
the infinite limit.
128 4: Integration
Select the Integration application and then program INFIN.
WA1 ‘N. Set Varsj; Select Sfvar
Specify the lower limit (0), the upper limit approximation (1,000), and an
accuracy factor of 0.01.
ACC=06.861
|mmmnnmnnlmnllllllllllllfl
Calculatethe integral.
S=1.57620935993
tumfunifwce[&
Exit from the Integration application and return the display format to FIX
4
EXIT] [EXIT] (EXIT v: 0.0156
B(0ISP) x: 1.57082
The following table summarizes results and calculation times for upper
limit approximations of 100, 1,000, and 10,000, and accuracy factors of
0.01 and 0.0001.
4: Integration 129
Acc. Calc. Time
Factor uLIM Result (seconds)
( % actual) 1.5707963268
0.01 100 1.57518831857 5
1,000 1.57020935993 36
10,000 1.57088603739 140
0.0001 100 1.5607891695 18
1,000 1.56979476064 69
10,000 1.57069673168 279
130 4: Integration
Using the Solver and Integration
Interactively
In the first example in this chapter, you found the twist angle 6 at the end
ofa shaft by integrating the applied torque with respect to x. (The torque
varied as a function of the position x along the shaft.) You were limited, in
that example, to solving specifically for the twist angle 6. In general, for
the equation
ULIM
I-= fLLIM f(x) dx (calculated to accuracy ACC)
the Integration application enables you to solve only for the value 7 of the
integral. To solve for I, you:
However, by writing a program S for the Solver that declares each vari-
able in the equation and invokes the Integration application on program P,
you can solve for any of the variablesin the equation:
m/
m The variables in the integrand f(x).
s LLIM, ULIM.
In the following example, you'll solve for the length L ofa shaft (the vari-
able ULIM in the Integration application) in the angle-of-twist equation.
4: Integration 131
Consider again the solid steel shaft of the first example in this chapter.
Forthis shaft, G = 83x10° N/m? andJ = 7.9521 x 108 m*. The shaft
is subjected to the same torsional loading T as in thefirst example. That
loading varies along the length x ofthe shaft as a function ofx.
The variables in the equation are §, L, T,J, and G. The unknown variable
L is the upper limit of integration ULIM.
Program: Comments:
88 { 68-Bute Prgm X
gl LBL "SHARFT"
132 4: Integration
In lines 09 - 10, the integralis calculated using the current value of ULIM,
which is iteratively supplied by the Solver as it searches for a solution.
Notethat the specified integration program is TORQUE from the first
example in the chapter.If you've deleted this program, you need to keyit
into the calculator now.
Now solvefor the upper limit L, providing initial guesses of 1 and 10.
ULIM=2.9528
(TBT ITRTRT
The shaft must be 2.9528 meters long to twist through an angle of 0.1396
radians.
4: Integration 133
More on How Integration Works
134 4: Integration
The accuracy factor is your estimation of the (decimal form of the) per-
cent error in each computed value off(x). This value is stored in ACC.
The accuracy factoris related to the uncertainty of integration (a measure-
mentof the accuracy of the integral) by:
f(x)
A
4: Integration 135
integration.
Find Si (2).
Set the display format to ALL. Set the angular mode to RAD.
B0OIsPF]HALL v: O
R(MODES] RAD x: ©
Select the Integration application and then program SI.
136 4: Integration
Since the function
xXx) =
sinx
—
f&x) *
Calculatethe integral.
Ly S=1,6054129768
Lifuiiafncc|o
4: Integration 137
The errorof integration is much larger now. However,it is still relatively
small compared to the value of the integral, and the calculation takes only
3 seconds.
Exit from the Integration application and return the display format to FIX
4
EXIT) [EXIT) [EXIT y: 1.6054
|[PIEIRE x: 0.0016
fx) = sinx
f(x)
A
By inspection, you can see that the value of the integral is a small positive
number, since the area with positive value from 0 to x is almost cancelled
by the area with negative value from = to 6.
138 4: Integration
Write the program that expresses the function.
66 { 14-Bute Pram >
@1 LBL “"SIN"
82 MVYAR "X"
83 RCL "»r"
84 SIM
85 EHND
Set the angular mode to RAD.Select the Integration application and then
program SIN.
BMODES] © RAD Set Vars; Select Jfvar
B/fx) TIDA
SIH
4: Integration 139
Conditions That Can Cause Incorrect Results
Although the integration algorithm in the HP-42S is one ofthe best avail-
able, in certain situations it - like all algorithms for numeric integration —
might give you an incorrect answer. The possibility of this occurring is very
remote. The integration algorithm has been designed to give accurate
results for almost any smooth function. Only for functions that exhibit
extremely erratic behavioris there any substantial risk of obtaining an
inaccurate answer. Such functions rarely occur in problems related to
actual physical systems,
j:oxe" dx
Since you’re evaluating this integral numerically, you mightthink that you
should represent the upperlimit of integration with a large number,say
100,000. Try it and see what happens. First write a program that expresses
fx).
08 { 17-Byte Pram 3
81 LBL "XEX"
82 MYAR "R®"
@3 RCL "X"
84 ENTER
a5 +/-
86 E+¥
arv x
83 END
140 4: Integration
Select the variable of integration X, then enter the lower and upperlimits
and an accuracy factor of 0.001.
ACC=06.8010
STATTATEN TOB
Integrate with respect tox. (Stay in the Integration application after exe-
cuting this calculation. You will integrate this function again in the next
section.)
S=0,00008
(LbJutia] wic][|-]
f(x)
A
= »X
The graph has a spike (illustrated here with a greatly exaggerated width)
very closv.: to the origin . Because no sample point discovered thespike,
the algorithm assumed that f(x) was equal to 0 throughout the interval of
4: Integration 141
integration. Even if you increased the number of sample points by specify-
ing an accuracy factor of 1x 10! | none ofthe additional sample points
would discover the spike when this particular function is integrated over
this particular interval.
[0 xe™®ax
Approximate the integral by subdividing the interval of integration into
three subintervals, one from 0 to 10, the second from 10 to 100, and the
third from 100 to 100,000.
First, integrate between 0 and 10. If you arestill in the Integration appli-
cation, simply supply the new value for ULIM.
10 ULIH 7=9.9595
mog RTINS ON
The answer is very close to 0. The sum ofthe approximations over the two
subintervals is 1. Finally, integrate between 100 and 100,000. (Stay in the
Integration application after executing this calculation. You will integrate
this function again in the next section.)
100 L S=0.0000
EI
TN TN TR IA
142 4: Integration
The integral overthe third subinterval is 0. The sum of the integrals over
the three subintervalsis 1.
foc,xe “*dx
o
Approximate the integral by calculating it over the interval (0, 1,000).
Enter the new values for LLIM and ULIM. Then integrate with respect to
x.
OLLIM 7=1.0000
1000 M LLLIMJULwis |-
This is the correct answer, but it took a long time to calculate. To under-
stand why, compare the graph of the function betweenx = 10 andx = 10°
(which looks about the same as that shown on page 141) with the follow-
ing graph ofthe function betweenx = 0 andx = 10.
4: Integration 143
f(x)
0 10
You can see that the function is "interesting" only at small values ofx. At
greater values ofx, the function is not interesting sinceit decreases
smoothly and gradually in a predictable manner.
In the last example, most of the sample points capture the function in the
region where its slope is not varying much. The algorithm finds that the
few sample points at small values ofx return values of the function that
change appreciably from one iteration to the next. Consequently, the func-
tion has to be evaluated at additional sample points before the disparity
between successive approximations becomessufficiently small.
144 4: Integration
Forthe integral to be approximated with the same accuracy over the larger
interval as over the smaller interval, the density of sample points must be the
same in the region where the function is interesting. To achieve the same
density of sample points, the total number of sample points required over
the larger interval is much greater than the number required over the
smaller interval. Consequently, several more iterations are required over
the largerinterval to achieve an approximation of the same accuracy, and
the calculation requires considerably more time.
4: Integration 145
S
Matrices
This chapter builds on material introduced to you in chapter 14 of your
owner’s manual. The following topics are covered:
m Create a matrix.
m Use the matrix editor to manipulate data.
m Use indexing functions and statistics functionsinteractively.
146 5: Matrices
Day # Temp Wind Humid
1 67 8 54
2 69 14 36
3 74 4 72
Enter the matrix editor and select the matrix you just created.
EDITH NTHR 1:1=0.0060
GOTOD
Fill element 1:1 with the Alpha string DAY #. (Remember,to execute
(ASTO], press in ALPHA mode.)
B(ALPHA] DAY # U 1:1="DAY #"
Lejoe+4[oOTO]»
EXIT
Fill the remaining clements in row 1 with the corresponding Alphastrings
from the table. (The keystrokes for element (1:2) are shown here.)
5: Matrices 147
Now fill the remaining elements with the corresponding data.
qi14=72_
Stormwarning finds that his assistant has incorrectly recorded the tem-
perature on day 1; it was 77, not 67.
GOTO2 [ENTER] 2 [ENTER] 77 [EXIT) x: 77 . 00008
Several days later the doctor has more data to add: on day #4, the tem-
peratureis 77, the windspeed is 5, and the humidity is 76. First,set the cal-
culator to Grow mode to create a new row in the matrix.
EDITN WTHR ¢« S:1=0. 0000
(v] GROW. (&)
5:4=76_
ITTT
Stormwarning now realizes he has entered the data for day #5, not day
#4. For day #4, the temperature was 68, the windspeed was 12, and the
humidity was 41. First change the value in element 5:1 to 5.
5:1=5_
148 5: Matrices
Enter the actual data for day #4.
(a) 4 Dt4=41_
[+Joc]++Jooto]+
Set the index pointers to element 2:2 (thefirst temperature data entry).
2 [ENTER) (V] 5TOLY . 7.0000
Now get the 5 x 2 submatrix that contains the temperature and windspeed
data.
5 2.GETH % [ Sx2 Matrix ]
STOI[RELI[TOEL[RCLEL|PUTH[GETH]
5: Matrices 149
Clear the summation registers, then store the data from the matrix in the
summation registers. (If the calculator returns the message
Nonexistent, the current SIZE allocationis insufficient.)
B(CLEAR] ‘CLY X 5. 0000
B(TOPFCN) 3%
Select the STAT menu and find the mean of the temperature data.
B(STAT] MEAN x: 73,0000
LZeJUM[HEANJHIMNTSOEY]CFIT]
The mean temperature for the five days is 73. The mean windspeed is 8.6.
Matrix Utilities
The following routines use existing matrix functions to build useful matrix
utilities.
150 5: Matrices
04 TRANS
a5 END
5: Matrices 151
Finding the Maximum and Minimum Elements of a Matrix.
MINMAX finds the maximum or minimum element of the real matrix in
the X-register. The elementis returned to the X-register. The indexed
location of the elementis returned to the Y- and Z-registers (column
number in Y, row number in Z). Set flag 09 to find the maximum ele-
ment. Clear flag 09 to find the minimum element.
Program: Comments:
ae { 61-Byte Pram
a1 LBL "MINMAR"
19 EHTER
152 5: Matrices
23 FC? 77
24 GTO B1
25 END
Program: Comments:
B3 { 81-Bute Pram 2
@1 LBL "SORT"
@2 STO "SORTHAT"
63 IWDEY “SORTHMAT"
5: Matrices 153
25 LBL 93 Lines 25-32: Increment the *sort-row"
26 R+ number. If the increment causes the
27 R+ index pointer to wrap, return the
238 1 sorted matrix to X and end the pro-
29 STOIJ gram.
38 GTO 91
31 LBL B4
32 RCL "SORTMAT"
33 EMD
Vector Solutions
Vectors are a special subset of matrices. You can describe a vector with
either a 1-row X n-column matrix, or a 1-column X n-row matrix.
Geometry
The area of a parallelogram can be determined by the equation
154 5: Matrices
Example: The Area of a Parallelogram. Findthe area of the fol-
lowing parallelogram.
(0,0,0)
2 [EXIT
5: Matrices 155
The area ofthe parallelogram is 15.0000.
Coordinate Transformations
156 5: Matrices
ORIGINAL
SYSTEM
o x
i W~ NEWSYSTEM
6
The equation for a coordinate transformation of a point from the old sys-
tem to a new system is
where:
5: Matrices 157
Note that the translation occurs before the rotation. The rotation is rela-
tive to the translated origin.
Program: Comments:
B8 { 216~Buyte Pram >
gl LBL "COOGRD®
@Y KEY 2 HERQ
=
M
as "AXIs"
89 KEY 2 XEQ
1)
1
16 "g"
11 KEY 4 XEQ 84
"He0®
ea
o0
KEY S GTO 83
[
&0
158 §: Matrices
21 IIO_)HII
22 KEY & GT0 Bé&
23 LBL 97 Lines 23—-27: Display the submenu.
24 MEHU
29 CF B8
26 STOP
27 GTO 37
42 KEY HEC 11
-
43 II_}II
44 KEY ®ERQ 12
o
32 RTH
5: Matrices 159
LBL 83 Lines 56— 57: Set flag 00 for a new-to-
SF a8 old transformation.,
LBL 86 Lines 58 -90: Evaluate the transfor-
EXITALL mation equation. If flag 00 is clear,
RCL "“P" calculate the old-to-new transforma-
FC? 08 tion.If flag 00 is set, calculate the
RCL- "T" new-to-old transformation.
STD IIP "
RCL "n"
UVEC
sTO "n"
DOT
1
RCL "&"
cos
RCLX "n"
X
RCL “&"
cos
RCLx “P'"
+
RCL "P'"
RCL "n"
CROSS
RCL "<"
FS? 89
+/-
SIN
®
+
F5? @@
RCL+ “T"
sTO "P"
GTO @1
END
160 5: Matrices
To use COORD:
1. Press COORD.
2. Press | then supply values for the elements of T using the
matrix editor labels in the menu. Press ([EXIT] to return to the main
menu.
Press (A% 185 ,then supply values for the elementsof the rotation
axis using the matrix editor labels in the menu. Press to
return to the main menu. Note that COORD stores the rotation
axis in variable n, calculates the unit vector of the rotation axis, and
stores the unit vector back in n. If you press 'AXISafter executing
a three-dimensional transformation, you will see the newly calcu-
lated elementsof the unit vector, not the original rotation axis.
Forthis problem:
COORD
e X 2.949
.45 g GBETEA
x: 0.00
fv [es] &«]|
Loa x: 62.50
62.5 lnnmgul
Enter the elements of P.
Ce12|[N>0]0-N]
162 5: Matrices
Check element 1:3.
The coordinates of the point in the new system are (3.59, 0.26, 0.59). Exit
from program COORD and return the display format to FIX 4.
v: 1.0000
BOISF) F1x4 x: 8.5891
Ry Rg Rs Rz
W W—MN—7"W
Apply the technique of loop currentsto find the currents I, I,, I3, 1,.
5: Matrices 163
The equations to be solved are (in variable form):
1. (Ry+R3)(I1) - (R3)(I3) =V
2. -(R3)(11) + (Rz+ Rs + R)(I2) - (Ry)(13) =0
3. -(R)(I2) + (R¢+Rs+ Rg)(I3) - (Rg) (1) =0
4. -(Rg)(I3) + (Re+R7+Rg)(14) =0
Put the equations in matrix form, substituting the following values for the
variables: V' = 34 V and R, through Rg = 111
2 -1 0 of |1
OOQ%
-1 3-1 0 I,
0 -1 3-1| [,| =
o o0-1 3| [g,
Enter the values for the elements of the coefficient matrix MATA. (The
keystrokes for the entering the first row data are shown here.) After
entering all the values, return to the main menu.
x: 3.0000
(NITRTSNN
EXIT
MATB %: 0.0000
2 RCTXT3TAA
0 EXIT)
164 5: Matrices
Calculate the unknowns.
HATR. 1:1=21.0000
1, is 21 A. Now check I.
g 2: 1=8, 0000
Check I.
3t 1=3.0000
4:1=1.060060
€lop ++[GOT0{-
5: Matrices 165
Example: Solving Simultaneous Equations That Have Com-
plex Terms. Now consider the following circuit.
R4 R3 Rg R7
W—TW
IODF-OLT $Q$’”
)| AY
/1 /1 /1 JI
o C, Cg Cy
The capacitor in each loop ofthe circuit introduces a complex term into
cach loop equation:
166 5: Matrices
Put the equations in matrix form, substituting the following values for the
variables: V = 34V, R, through Rg = 511, w = 100 radians/second,
and C; through C,=1F.
10 - i0.01 -5 0 0 I, 34
-5 15 - i0.01 -5 0 I3 0
0 -5 15-i001 -5 I;) T |o
0 0 -5 15-i001| |f, 0
W(COMPLEX]
EXIT
Solve for MATX. (MATB has the same value as in the previous example.)
1:1=4.2000 i8.00861
5: Matrices 167
Check I3-
G 311=0.6000 10,00
=foww]+4+Joorn]
Chcck I4
4:1=0.2000 10.0008
Make MATA and MATX real matrices. Exit from the Matrix application.
MATA B(COMPLEX)
MATA
v: [ 4x1 Hatrix 1
x: [ 4x1 Matrix 1]
(RCL) MATXWMCOMPLEX]
MATR
[EXIT) [EXIT)
In the following example, you’ll use the Solver and matrix division to find
the value of one elementof the coefficient matrix, MATA, given:
168 5: Matrices
Example. Using the Solver to Find the Value of an Element
of the Coefficient Matrix. Consider again the circuit from the previ-
ous section in this chapter.
R4 Rga Rs Rz
M——W W W
_D Ro I R4 Iy
<) =
[+
Rg
T/ S/
I
<
Find the resistor value R; such that loop current I, is 20 A greater than
loop current I, (I; = I;+20), when V' = 40 V, and R, through Rg = 111.
R -1 0 0 I,+20
QOOS
-1 3-1 0 I,
0 -1 3 -1 I,
0 0-1 3 1,
5: Matrices 169
Part 1. Write the program for the Solver.
Program: Comments:
a0 { 82-Byte Praom 2>
a1 LBL "SIMUL"
21 EHD
170 5: Matrices
Part 2. Enter the Matrix application, and specify a system of equations
with four unknowns.
BMATRIX] &IM @4 [ENTER x: 0. 0000
atalttaTeltnrs]||
Fill MATA with the known coefficients. Element 1:1 contains the
unknown resistor value R. You can leave this elementat its current value.
(The keystrokesfor the first two rows are shown here.) After entering all
the data, return to the main menu.
x: 3.00008
EEIEELETRI
Fill MATB with the known constants, then exit from the Matrix applica-
tion.
0
EXIT] [EXIT] [EXIT
Enter 20 for D.
20 |D=28. B0oA l
ITNTTT
5: Matrices 17
Enter guesses of 0 and 10 for R and solve for R.
=1.6190
ITT
I, is 323077 A. Check I,
2:1=12.3677
The program LIST on pages 176 - 178 enables you to accumulate statisti-
cal data in a matrix with the same keystroke sequence that you use in nor-
mal data entry into the summation registers.
The program MLR on pages 186 — 192 uses matrix and statistical functions
to calculate a linear regression for data sets of three independentvari-
ables. MLR creates a coefficient matrix MATA and a constant matrix
MATB. It executes matrix editor functions to fill them with data, then exe-
cutes matrix division to calculate the solution matrix MATX,
172 5: Matrices
The program PFIT on pages 218 —222 plots the statistical data from the
matrix currently in the X-register, then fits and plots a curve to the data
using the currentstatistical model. It plots the curve and the data points
using x-y data pairs from complex matrices.
6
Statistics
This chapter presentsfive programs for statistical operations. The pro-
gramsuse statistical functions introduced in chapter 15 of your owner’s
manual, and integrate matrix operations presented in the previous chapter
and in chapter 14 of your owner’s manual.
174 6: Statistics
List Statistics
To supply a set ofx-y data pairs to the calculator for subsequent statistical
operations, you use the keystroke sequence
y-value [ENTER] x-value
for each data pair. The summation cocfficients in the 6 (or 13) summation
registers are automatically recalculated each time you press (Z+]). The cal-
culator does not, however, maintain a list of the individual data pairs.
To update the summation registers and maintain a list of the x-y data
pairs, you:
(You did this in chapter 5 in the section "Using Indexing Utilities and
Statistics Functions Interactively”.)
6: Statistics 175
The LIST Program. The following program, LIST, enables you to fill a
1- or 2-column matrix LLIST with x-y data pairs using the keystroke
sequence
where [187T# is one of three menu keys built by LIST. Note that this is
the same keystroke sequence that you use to enter statistical data into the
summation registers.
To key in LIST:
Program: Comments:
176 6: Statistics
12 LBL "LIST+" Lines 12-20: If ZLISTexists, index it
13 SF 23 and make it grow by one row. If it
14 XE@ I doesn’t exist, create and index it (in
15 FC?C 23 lines 32-42).
16 GTO 82
17 GROM
18 ‘J_
19 J+
28 WRAP
6: Statistics 177
43 LBL "LIST-" Lines 43— 53: Recall the element(s) in
44 SF 25 the last row of ZLIST to the X- (or X-
45 KEQ@ I and Y-) register(s).
46 FC? 25
47 RTN
48 J-
49 RCLEL
50 FS? B1
51 GTO @3
52 J_
53 RCLEL
64 EMND
178 6: Statistics
To use LIST:
1. For two-variable statistics (x- and y-values), clear flag 01. For one-
variable statistics (x-values only), set flag 01; the program makes
TLIST a 1-column matrix.
2. Pross (XEQ) [LIST.
x-value y-value
6 2
5 3
9 5
12 6
21 11
7 4
Clear XLIST.
x: 8. 8000
(LisTeuist=-f|| JCLIET)
6: Statistics 179
Enter the first data pair.
2 6LIST+ ZLIST=[ 1x2 Matrix ]
ISERRY[WETT INNY
Key in the remaining data pairs (the keystrokes are not shown here). Exit
from LIST.
EXIT
The mean of the x-values is 10. Check the mean of the y-values.
(xxy] x: 5. 1667
E+ 3Ut4 [MERNTWMN]Z0EVCRIT
EXIT v: 16,8040
X: 9. 1667
180 6: Statistics
Redimensioning the £L/ST Matrix to nm x 2. In the previous exam-
ple, you used LIST to create a 6 x 2 matrix ELIST. You then recalled
SIIST to the X-register, and executed £+ to accumulate the x-y data
pairs from the matrix into the summation registers. To execute L+ when a
matrix is in the X-register, that matrix must have a column dimension equal
(by
to 2. If, for example, you use LIST to create an n X 1 matrix ZLIST
setting flag 01), you must redimen sion it before executi ng £+,
az 2
A3 RCL “ELIST"
a4 DIM?
A5 X
86 DIM “"ZLIST"
@7 INDEX "ZELIST"
ag 1
a9 ENTER
18 2
11 ROR
12 RCL "ZELIST"
13 TRANS
14 STO "ZELIST"
15 END
6: Statistics 181
Program: Comments:
80 { 46~Byte Pram
a1 LBL "XVALS"
15 END
The program MLRin this section uses the £+ function and matrix opera-
tionsto calculate a multiple linear regression for three independent vari-
ables.
t=a+bx+cy+dz
182 6: Statistics
Regression coefficients a, b, c, and d are calculated by solving the follow-
ing set of equations.
n &t Wi &t
a 21',-
23 - "17(2‘.')2
6: Statistics 183
sansnels ;9 181
Caw Cwey Ca
1
SH31S193Y
1
13S viva 1Sv13HL
!
|'44302 IVOILSILVLS
NOILVWWNS TV LOVHLENS OL—-X ANV| 3Lvadn OL-+X ANV
Hv370 Ol X110 3sn HLIHV MOVLS 3sn HLIHV XOV.LS 38N
€D &
&
@ [ eroax|| zroax|| rroax ]
uO1VOl
”3101/ II_ZII 44"'3//
€A €A 2 AN b ATN
1NdNI 404 dOLS ANV
NN3W NIYW AV1dSIa
f
SAIN NN3INW
NIVN @1ing
00
147
13S viva M3aN
HLIM SIN3IDI44300
IvOILSILVYLS 31vadn
01 00 ODv14 HY31D
A
XLYW ‘G1VIN YiVW
S30I14H1VW a1ing
HIN
FILL MATA, MATB
WITH SUMMATION
COEFFICIENTS
v
CALCULATE MATX
AND R2
y
BUILD SOLUTION
MENU
y
INDEX MATX AND
DISPLAY VARIABLE
6: Statistics 185
To key in MLR:
Program: Comments:
B8 { 460-Bute Prgm 2}
81 LBL "MLR"
19 KEY 2 XE@ 12
28 "CL=z"
21 KEY 3 XEQ 13
22 "CALc"
23 KEY 6 GTO 14
24 MENU
25 CLD
26 STOP
27 GTO BB
186 6: Statistics
28 LBL 11 Subroutine 11, lines 28 - 58: Emulate
29 RCLx ST I+ (or Z- if flag 00 set) to update the
30 FS? 88 following summation coefficients: Ixz
31 +/- in Rys, Bt in Ry5, Tyz in Ryy, Tyt in
32 STO+ 13 R 6. Execute £+ to update the follow-
33 CLX ing coefficients: £z in Ry, 22 in R g,
34 LLASTX Tt in Rog, ¥2in Ry, X2t in Ry, 1 in
35 RCLx ST Ry
36 FS? @8
57 +/=
28 STO+ 15
29 CLX
49 LASTH
41 E+
42 RCL® ST
43 FS? @8
44 +-
45 STO+ 14
46 CLX
47 LASTH
48 RCLx ST
]
49 FS? ag
58 +/—
51 STO+ 16
52 CLX
53 LASTX
54 R+
55 ZREG 87
56 FS? 68
57 RTH
58 Z+
G: Statistics 187
59 LBL 81 Subroutine 01, lines 59 - 68; Execute
e CLX I+ to update the following
61 LASTX coefficients: £x in Ro;, Zx?in Rgy, Ty
62 R+ in Reg, y? in Ry, Ty in Reg, and 1 in
63 R+ R . (Note that n is also calculated in
64 ZREG 81 subroutine 11.)
65 FS?C B84a
66 RTH
67 Z+
£3 RTH
7S RTH
188 6: Statistics
94 »
95 RCL 87
96 +
97 RCL 13
98 €
99 RCL @5
109 +
181 J+
1862 RCL 14
183 +
194 RCL "MATA"
185 TRAHNS
186 STO+ "MATA"
197 RCL 88
168 +
169 «
118 RCL 84
111 +
112 «
113 RCL 82
114 +
115 <
116 RCL RA6
117 STOEL
112 INDEX “MATE"
119 RCL a9
128 4+
121 RCL 15
122 «
123 RCL 16
124 4
125 RCL 11
126 STOEL
127 RCL "MATE"
128 RCL+ "MATA"
129 STO "MATH®
128 LASTH
131 TRANS
132 KOV
133 x
134 FHRM
6: Statistics 189
135 RCL 89
136 X+2
137 RCL+ @6
138 -
139 LASTX
148 RCL 1@
141 X<>Y
142 -
142 +
144 STO "R2"
145 CLD
146 FS? 53
147 SF 21
151 "g"
152 KEY 2 HER &
[
P
152 "C»
154 KEY KER :
03
M
L)
155 "D
156 KEY 4 EQ &
P
£
157 “"R2"
153 KEY 5 XER
T
n
159 »T?"
160 KEY & RER
[
T
162 MENU
163 STOP
164 GTO @2
190 6: Statistics
ive GTO 03
173 LBL 23
174 3
175 IICII
176 GTO B3
177 LBL 24
178 4
179 Ildll
120 LBL 83
181 1
182 IHDEX "MATR"
183 STOIJ
184 RCLEL
185 =
186 ARCL ST X
187 AVIEM
188 RTN
189 LBL 25
1909 RCL "R2"
191 VIEW "R2"
192 RTN
199 +
288 I_
201 RCLEL
282 o+
6: Statistics 191
286 LBL a4 Subroutine 04, lines 206 -210: Calcu-
287 I- late terms bx,cy, and dz.
288 RCLEL
209 RCLx ST T
218 RTH
211 END
To use MLR:
if112|3|4]|5
x| 71 1]11|n| 7
v |25 29|56 |31]52
z| 6|15| 8| 8| 6
t, [60|52|20]47 |33
.
e MLR
Execut
192 6: Statistics
Clear the summation registers. Enter the first data set, starting with the
t-value.
R] 6 (ENTER] 25 [ENTER]
Enter the remaining data sets (the keystrokes are not shown here). Now
calculate the regression coefficients and the coefficient of determination.
HLC x: 8. 9989
Lo&¢oJr2 Ty
d=-1.3395
o & ¢o [rRa |71y
6: Statistics 193
Calculate T (the forecasted value of ¢ given values for x, y, and z). Use the
values from data set #4.
8 [ENTER] 31 [ENTER] 11
T?
(The actual value of ¢ in data set #4 is 47.) Return to the main menu and
clearthe statistics registers for new data.
cL2
Refer to program PFIT on pages 218 —222 in the following chapter. PFIT
uses FCSTY in line 89 to forecast a y-value based on the currently
selected statistical model for each of 110 x-values. A curve is then plotted
with the 110 data pairs.
194 6: Statistics
Graphics and Plotting
The following topics are coveredin this chapter:
Graphics
The program HPLOGO in this section uses the XTOA and AGRAPH
functions to build the Hewlett-Packard company logo in the center of the
display.
To key in HPLOGO:
Program: Comments:
08 { 441-Byte Pram >
at LBL "HPLOGO"
157 EHD
Execute HPLOGO.
2
Insert the instruction PRLCD afterline 14 of HPLOGO to print the logo.
B(PRGM] B(GTO] (] 14 v: 9, 0000
(V] FRLCD [EXIT x: 40,0000
Print the logo. 4 x
BERINT] (4] FOH D
HFLO
O 0O DO LastDigitEntered
O O nm
O O =n
O B =nu
O B N
H B B
m B 0O
M O 0O FistDigit Entered
Column# 16 17 18
Use BINDATA to calculate the column print number for each column.
Multifunction Plots
The program PLOT3 in this section enables you to plot up to three func-
tions concurrently on the HP 82240A Infrared Printer. It is based on the
program PLOTin the section "Example Programs” in chapter 10 of your
owner’s manual. As in PLOT, you supply to the program the name of the
routine that defines the function you wish to plot. However, in PLOTS3,
you can supply upto three routine names.
&
PLOT3
v
PLOT HEADER INFO
AND INITIALIZE
v
SET INITIAL x-VALUE
LBL
00
CLEAR DISPLAY
Y
G NO
S
|{ABEL AXIS
<«
YES
NO |DRAW AXIS
i(—’
___.___._________________.________.)
FOR EACH FUNCTION
PRINT DISPLAY
EVALUATE f(x)
INCREMENT]
X-VALUE
v
PRINT FINAL
PLOT PIXEL
STOP
Program: Comments:
88 { 424-Bute Pram
A1 LEL “PLOTZ"
£
-
r
146 RTH
ARCL ST ¥
STR?
FRA
ETH
EHD
—
an
£
To use PLOT3:
2. Write a routine for each function that you wantto plot. The current
x-valueis in the X-register when the program calls the function rou-
tines. The routines need not recall the current x-valueto the X-
register.
3. Setthe display format to ALL.
4. Start the program (press FLOTS).
5. Supply the plot parameters. For example, specify 20 for YMIN by
pressing 20 “WHIH .
6. After supplying values for the plot parameters, press [R/S].
&. As prompted, store the name of each function routine in a
function variable. For example, to supply the name TAN for
FCNI, press TAN at the first prompt.
b. If you have already supplied a routine name for a function
variable, that nameis displayed at the prompt. If you want to
leave that namein the variable, simply press [R/S].
¢. If you wantto plot only two functions, supply names for only
two variables. Leave the Alpharegister clear for the third
variable (just press when prompted). If a nameis
displayed for the third variable, press to clear the Alpha
register, then press [R/S]. If you want to plot only one func-
tion, supply a name for only one variable and leave the Alpha
register clear (or clear it) for the other two variables.
Program: Comments:
Set the Display format to ALL. Execute PRON. Clear flags 00 and 01 to
draw and labelthe x-axis. Start PLOT3.
)
PRINT) &) FOH
|m AI II TRAT
lm Im
J
Plot of:
om
- DD T
nz
OTO®WW
==
OOXIZIUXCZ
nunuwan
-
[=aAt]
YMAX 2
X
;
”
™
"
x-value + iy-value
When such a matrix is in the X-register, PIXEL turns on each pixel in the
displayas specified by the elements in the matrix. For example, consider
the following complex matrix.
1+i10 5+i20
10+i30 16+i40
If you execute PIXEL when this matrix is in the X-register, pixels (1, 10),
(5, 20), (10, 30), and (16, 40) are each turned on.
v
XEQ MM TO FIND MIN
AND MAX VALUES, THEN
CALCULATE SCALING
FACTORS
v
PLOT
AXES
v
STORE DATA FROM
DATAMTX IN SUMMATION
REGISTERS
v
BUILD PLOTTING
MARKER
v
IC?EATE COMPLEX MATRIX
OF x AND y VALUES
CREATE 1 X 22 TEMPORARY
MATRIX AND FILL IT WITH
x -VALUES 1-22
i COMBINE x, y MATRICES
|
|
|
INTO A COMPLEX MATRIX
v
l
|
|
|
' PLOT 22 PIXELS
(DRAW THE CURVE)
To key in PFIT:
Program: Comments:
B8 { 295-Byte Prgm 3
61 LBL "PFIT"
121 END
To use PFIT:
P =gVt
where:
P is the pressure.
V is the volume.
~b is the polytropic constant.
VP
10 210
30 40
50 12
70| 9
% 6.8
EXIT x: ~0.9939
FLiTyd
eLOPE %: -1.6152
224 Index
C Controlled looping, 39-43
definition, 39
Calculation time DSE function in, 39
for an explicit solution, 100 GTO function in, 39
for Integration approximations, indirect addressing with, 43
129-130
INPUT IND in, 43
for the Solver, 99
ISG function in, 39
Integration conditions that pro- STO IND in, 44
long, 143145
XEQ IND in, 45
Case 1 and 2 (Solver) solutions, COORD program,listing of],
how to differentiate
158-160
between, 110
Coordinate transformations,
Case 1 (Solver) solution,
156-163
definition, 109
Correlation coefficient, 221
Case 2 (Solver) solution,
Curvefitting in programs, 194
definition, 109
CUSTOM menu, executing pro-
CIRCUIT program, listing of, 87
grams from, 73, 19
CLEAR program,listing of, 44
Coefficient matrix. See MATA
Column norm of a matrix, 151 D
Column sum of a matrix, 150 -151
Data input, prompting for in a
Complex numbers. See Emulating
program, 68, 15
the Solver; HP-41 programs,
Data output, displaying in a pro-
enhancing with HP-42S data
gram, 68, 16
types; Simultaneous equa-
Declaring variables. See MVAR
tions, complex-number
function
Compression process equation,
Directing the Solverto a realistic
220
solution, 8082
Conditional branching, 22 -25
Discontinuous function, Solver
based on a number test, 24
results with, 113-114
CONE program,listing of, 81
DISPL program
Conjugate of a complex matrix,
flowchart for, 40
151
listing of, 41
Constant matrix. See MATB
Displaying program results. See
Const ant ? message, 121
Data output
Constant velocity equation, 39
DSEfunction, in a controlled
Control flags, 47
definition, 47
loop, 39
flag 21 used to control VIEW
and AVIEW functions, 47,
16
Index 225
E trapping, 50
Error trapping, 49 -50
EIZ program,listing of, 89-90
Electricalcircuits. See Simultane- Examples, displays in the manual
may differ from your
ous Equations; Emulating
the Solver displays, 10
Executing a program
Emulating
from the CUSTOM menu, 73,
a multirow menu, 34-37
19
a nested menu, 37-39
from the program catalog, 19
T+ function, 176
the Solver, 86-91
with the XEQ function, 73, 19
END function, 15
Explicit solutions
calculation time, 100
Enhancing HP-41 programs, 67—
faster than iterative solutions, 92
76
for complex numbers, 88
Equation(s)
using with the Solver in pro-
angle of twist, 131, 12§
asymptote, 119 grams, 92 -100
Extremum message, 117
compression process, 220
constant acceleration due to
gravity, 83 F
constant velocity, 39
FCAT program
idealgas, 101, 78
flowchart for, 52
local flat region, 121
listing of, 53 -56
loop current, 166, 169, 163
uses programming concepts dis-
math error, 120
cussed in chapter 2, 51
multiple linear regression,
Finding more than one solution
182183
with the Solver, 83 -85
Ohm’s law, 86, 88
Flag 21
pole, 116
and PROFF function, 16
relative minimum, 118
and PRONfunction, 16
setting equal to O for the Solver,
effect on VIEW and AVIEW
105, 77
instructions, 47, 16
sine integral, 136
Flag 25, used in error trapping, 50
SSA (triangle solution), 22
Flag 77, used in MINMAX pro-
SSS (triangle solution), 13
gram, 47
time-value-of-money, 92
Flag tests, follow do-if-true rule,
triangle solutions, 58 - 59
46
van der Waals, 101
Flags, 4657
volume of the frustum of a right
control, 47
circular cone, 80
current status maintained by
Error Ignore flag, used in error
Continuous Memory, 47
Error Ignore, 50 GTO function,in a controlled
general purpose, 46-47 loop, 39
have unique meanings for the
calculator, 46 H
listing of in appendix C of
owner’s manual, 46
Horner’s method, 125
Matrix End-Wrap, 47 HP 82240A Infrared Printer
Numeric Data Input, 93 some examples include optional
Printer Enable, 47, 16 instructions for, 11
system, 47 - 48 HP-41 programs, enhancing, 67—
user, 4647 76
Flat region, Solverresults with, with HP-42S datatypes, 69
121 with INPUT function, 68
Flowchart with menu variables, 71-73
definition of, 13 with named variables, 67— 68
for DISPL program, 40 with the two-line display, 69
for FCAT program, 52 with VIEW function, 68
for GAS2 program, 102 HPLOGO program,listing of,
for MLR program, 184 196-200
for PFIT program, 214-215
for PLOT3 program, 204 —-205
for SSA program, 23
for SSA2 program, 27 Ideal gas equation, 101, 78
for SSS program, 15 Improperintegral, definition of,
for TRIXA program, 30-31 127
symbols for, 15 Incorrect results in Integration,
140-143
Indexing (matrix) functions, 146 —
G 154
GASprogram,listing of, 78 Indirect addressing, 43 —45
GAS?2program clearing storage registers with,
flowchartfor, 102 4
listing of, 103 -104 controlled looping with, 43
General purpose flags, 46-47 executing subroutines with, 45
definition of, 46 initializing data storage registers
in LIST program, 47 with, 43
in MINMAX program, 48 INPUT function with, 43
Global label, definesstart of a SOLVE and PGMSLY func-
program, 15 tions with, 101-105
Graphics, 195-203 STO function with, 44
binary datato build, 200203 XEQ function with, 45
Index 227
Infinite limit, approximating an and Integration, 131-133
integral that has an, 127 - and Simultaneous Equations,
130 168-172
Infrared Printer. Interpreting the results of the
some examples include optional Solver, 108 -122
instructions for, 11 ISG function,in a controlled loop,
See also Printing 39
INIT program,listing of, 43
Initial guesses, for the Solver,
80-85
K
INPUT function, 15 KEY GTO function
brings up variablecatalog in emulating a multirow menu
Program-entry mode, 17 with, 34-37
enhancing HP-41 programs emulating a nested menu with,
with, 68 37-39
indirect address with, 43 to build programmable menu,
Integration, 124-145 29
ACC variablein, 124 turns on VA annunciator when
accuracy factor and uncertainty assigned to menu key 7 or 8,
of integration, 134-139 34
approximating an integral that KEY XEQ function
has an infinite limit, 127 - to build programmable menu,
130 29
basic use of, 124-127 turns on VA annunciator when
calculation time for approxima- assigned to menu key 7 or 8,
tions, 129-130 34
conditions that can cause Keying in programs, helpful hints
incorrect results, 140-143 for, 17
conditions that prolong calcula- Keystrokes, required to execute a
tion time, 143 - 145 program, 19-20
limiting the accuracy of, 134
LLIM variable in, 124
more on how it works, 134-145
L
MVARfunction in, 124 LIST program
Solver and, 131 -133 accumulatesstatistical data for
subdividing the interval of plotting, 220
integration, 142-143 emulating £+ function in, 176
ULIM variable in, 124 fills ©2.IST matrix with x-y data
uncertainty of. See Uncertainty pairs, 176
of integration general purpose flag in, 47
Interactive use of the Solver listing of, 176 -179
228 Index
matrix operations in, 172 geometric calculations with vec-
List statistics, 175-182 tors, 154-156
LLIM variable interactive use of indexing utili-
in basic integration, 124 ties and statistics functions,
solving for with the Solver, 131 149-150
Local maximum or minimum, matrix editor and indexing func-
Solver results with, 117 tions, 146154
Loop current equations, 166, 169, matrix operations in statistics
163 and graphics programs,
LVL1 program, listing of, 38 -39 172-173
matrix utility programs, 150-
154
solving simultaneous equations,
MATA matrix 163-168
in MLR program, 172 sorting a matrix, 153 -154
in Simultaneous Equations vector solutions, 154—-163
application, 164 Matrix editor, 146 —154
solving for an element of, 168 Matrix End-Wrap flag, in MIN-
MATB matrix MAX program, 47
in MLR program, 172 Matrix sum of a matrix, 151
in Simultaneous Equations MATX matrix
application, 164 in MLR program, 172
Math error, Solver results with, in Simultaneous Equations
120 application, 165
Matrices, 146-173 Maximum and minimum elements
coordinate transformations with of a matrix, 152-153
vectors, 156-163 Menu
creating a named matrix, 147 multirow, emulating in a pro-
filling a matrix element with an gram, 34-37
Alpha string, 147 nested, emulating in a program,
finding the column norm of a 37-39
matrix, 151 programmable, 29
finding the column sum of a MENU function, 29
matrix, 150-151 Menu keys, 29
finding the conjugate of a com- Menu variables
plex matrix, 151 enhancing HP-41 programs
finding the matrix sum of a with, 71-73
matrix, 151 to simulate the Solver, 88
finding the maximum and Menu-controlled branching, 29—
minimum elements of a 39
matrix, 152 -153 Messages
Index 229
Bad Guess(ez), 120 0
Constant?, 121
Ohm’s law equation, 86, 88
Extremumn, 117
Out of Range message, 49
Out of Range, 49
Restricted Operation, 56
Sign Rewersal, 115 P
MINMAX program, flags in, 47 Parabolic equation. See
MLR program
Equation(s), relative
flowchart for, 184
minimum
listing of, 186— 192 PFIT program
matrix operationsin, 172
flowchart for, 214-215
MOTION program,listing of, 84 listing of, 216-220
Multifunction plotting, 203 -213
matrix operations in, 173
Multiple linear regression, 182 -
PGMSLYVfunction, indirect
194
address with, 101 — 105
Multiple-linear-regression
PHONE program,listing of, 45
equations, 182- 183
PIXEL function, operates on com-
Multirow menu
plex matrices, 213
VA annunciator in, 34
PLOT3 program
{¥] and (4] keysin, 34 flowchart for, 204 - 205
emulating in a program, 3437 listing of, 205-210
MVARfunction
Plotting, 203 -222
defines variables in Integration
multifunction plotting, 203 -213
programs, 124
plotting data from a complex
defines variables in Solver pro- matrix, 213 -222
grams, 77
Pole, Solver results with, 115
Printer Enable flag, 47, 16
Printing
HPLOGO program results, 200
Neighbors, 109
optionalinstructionsfor, 11
Nested menu, emulating in a pro-
PLOT3 program results, 212
gram, 37-39
Q3 program results, 74
Notations, consistent with owner’s
SSS program results, 33
manual, 10
PROFF function, and flag 21, 16
Numeric Data Input flag, 93
Program catalog
executing a program from, 19
global labels placed in, 19
Program listing
for BINDATA,201
for CIRCUIT,87
230 Index
for CLEAR, 44 programs, 194
for CONE,81 defining the program, 15
for COORD, 158 -160 displayingresults, 16
for DISPL, 41 error trapping, 49-50
for EIZ, 89-90 flags, 46— 57
for FCAT, 53-56 helpful hints for keying in pro-
for GAS, 78 grams, 17
for GAS2, 103-104 indirect addressing, 43 —45
for HPLOGO, 196 -200 prompting for data input, 15
for INIT, 43 simple programming, 12-21
for LIST, 176-179 Solver and explicit solutions in
for LVL1, 38-39 programs, 92-100
for matrix utility programs, Solver in programs, 92-105
150-154 subroutines, 2629
for MLR, 186-192 summation-coefficient functions
for MOTION, 84 in programs, 182 —194
for PFIT, 216-220 Programs
for PHONE,45 executing from the CUSTOM
for PLOT3, 205-210 menu, 19
for Q2, 69-71 executing from the program
for Q3,72-73 catalog, 19
for QSHORT, 75 executing with XEQ function,
for ROW1, 35-37 19
for ZFORM,181 keystrokes required to execute,
for SHAFT, 132 19-20
for SIMUL, 170 Prompting for data input. See
for SSA, 24-25 Data input
for SSA2,28-29 PRONfunction, and flag 21, 16
for SSS,17-18 Providing initial guesses for the
for TORQUIE, 126 Solver, 80 -85
for TRAP (revised), 50
for TRIA, 6065
for TVM2, 93-99
Q
for XVALS, 182 Q2 program,listing of, 69-71
Programmable menu Q3 program,listing of, 72-73
definition of, 29 QSHORT program,listing of, 75
in TRIA program, 32
Programming, 12-66
branching, 21-39
controlled looping, 39-43
curve fitting functions in
Index 231
nonzero, 108
RCL function, brings up variable Bad Guess(es) message, 120
catalog in Program-entry basic use of, 77-80
mode, 17 calculation time in TVM pro-
Realistic solution, directing the gram, 99
Solver to, 80— 82 cases when a root is found,
Redimensioning £LIST matrix, 109-115
181 codes returned to the T-register,
Regression, multiple linear, 182 - 108-109
194 Const ant ? message, 121
Festricted Operation mes- differentiating between Case 1
sage, 56 and Case 2 solutions, 110
Root(s) of a function directing to a realistic solution,
approximations of, 108 80-82
definition of, 105 emulating in a program, 86 -91
ideal solutions for, 108 explicit solutions and, 92-100
multivariable function roots, 106 Extremur message, 117
Solver’s ability to find, 107-108 finding more than one solution,
Round-off error, can affect Solver 83-85
results, 123 ideal solution, definition, 108
ROWI1program,listing of, 35-37 Integration and, 131-133
interpreting the results of,
108-122
S more on how it works, 105-123
SHAFT program, listing of, 132 MVAR function in, 77
Sion Rewversal message, 115 providing initial guesses for,
Simple programming, 12-21 80-85
SIMUL program,listing of, 170 results may be affected by
Simultaneous equations round-off error or
complex-number, 166 —168 underflow, 123
real-number, 163 -165 results with a discontinous func-
Simultaneous Equations, 163 -172 tion, 113-114
Solver and, 168-172 Sign Reversal message, 115
Sine integral equation, 136 Simultaneous Equations and,
Solution matrix. See MATX 168-172
SOLVE function, indirect address using in programs, 92105
with, 101 -105 Sorting a matrix, 153-154
Solver, 77-123 SSA program
ability to find a root, 107 -108 flowchart for, 23
approximations for which f(x) is listing of, 2425
SSA (triangle solution) equations,
232 Index
22 coefficient functions
SSA2 program Summation-coefficient functions,
flowchart for, 27 using in programs, 182 - 194
listing of, 28 -29 System flags, 47 - 48
SSS program in MINMAX program, 47
flowchart for, 15
listing of, 17-18
SSS (triangle solution) equations,
T
13 Time-value-of-money equation, 92
Stack registers, contain results of TORQUE program,listing of, 126
the Solver, 108 Translations, coordinate. See
Statistics, 174-194 Coordinate transformations
calculating a multiple linear TRAP program,listing of, 50
regression, 182 -194 TRIX. program
correlation coefficient, 221 flowchart for, 30-31
curve fitting in programs, 194 listing of, 60-65
linear or exponential curve Triangle solutions equations, 58—
fitting for one-variable data, 59
181 TVM?2program,listing of, 93-99
list statistics, 175-182
matrix indexing utilities and,
149-150
U
redimensioning X.LIST matrix to ULIM variable
execute X+, 181 in basic integration, 124
summation-coefficient functions solving for with the Solver, 131
in programs, 182 -194 Uncertainty ofintegration
STO function definition, 135
brings up variable catalog in is greater than error in finalcal-
Program-entry mode, 17 culation, 135
indirect address with, 44 may be relatively large, 138 -
STOP function, 29 139
Subdividing the interval of integra- returned to the Y-register, 135
tion, 142143 Underflow, can affect SolverV
Subroutines, 26 -29 results, 123
advantagesof, 26 Userflags, 46-47
called with XEQ,26
definition, 26
end with RTN or END,26
in SSA2 program, 26
Summation registers. See T+
function; Summation-
Index 233
v
Valid solution. See Directing the
Solverto a realistic
van der Waals equation, 101
Variable menu
enhancing HP-41 programs
with, 71-73
to simulate the Solver, 88
Variables
ACC, 124
keying in in programs, 17
LLIM, 124
MATA, 164
MATB, 164
MATX, 165
LLIST, 176
ULIM, 124
Vector solutions, 154 -163
VIEW function, 16
brings up variable catalog in
Program-entry mode, 17
enhancing HP-41 programs
with, 68
Volumeof frustum of rightcircu-
lar cone, equation, 80
X
XEQ function
executing a program with, 73, 19
indirect address with, 45
XTOA function
in HPLOGO program, 195
used if corresponding character
cannot be typed, 203
XVALS program, listing of, 182
234 Index
Programming Examples and Techniques
for Your HP-42S Calculator
____________________________________________
8 Programming
Simple Programming ¢ Branching ¢ Controlled Looping « Indirect
Addressing in Programs e Flags in Programs * Error Trapping
B Enhancing HP-41 Programs
Using Named Variables « Using HP-42S Data Input and Output
Functions ¢ Operations with HP-42S Data Types * Using the Two-
Line Display » Using Menu Variables * Assigning a Program to the
CUSTOM Menu
B The Solver
Basic Use of the Solver ¢ Providing Initial Guesses for the Solver
» Emulating the Solver ¢ Using the Solver in Programs ¢« More on
How the Solver Works
B Integration
Basic Integration » Approximating an Integral That Has an Infinite
Limit « Using the Solver and Integration Interactively s More on
How Integration Works
H Matrices
Using the Matrix Editor and Indexing Functions « Vector Solutions
* Solving Simultaneous Equations ¢ Using the Solver with
Simultaneous Equations « Matrix Operations in Programs
B Statistics
List Statistics » Using the Summation-Coefficient Functions in
Programs « Curve Fitting in Programs
8 Graphics and Plotting
- Graphics » Multifunction Plots + Plotting Data from a Complex
Matrix
HEWLETT
fifi PACKARD
Reorder Number
00042-90020
00042-90019 English
Printed in US.A. 7/88 0""88698"00036" 6