7g

000 000O0OGEOGFOGOIOGOSRPN Scientific
Programming Examples and Techniques

ot

ﬂﬂ

HEWLETT
PACKARD

Help Us Help You!
Please take a moment to complete this postage-paid card, tearit
out and put it in the mail. Your responses and comments will help
us better understand your needs and will provide you with thebest procedures to solve your problems. Thank you!

HELP US HELP YOU!
Book: Programming Examples and Techniques
NameDate acquired:

StreetCity, State, Zip
Phone ()

Businessor Home1. What calculator will you use this book with?
009 ]HP-42S 006 ] Other
2. How many other HP solution books have you bought for this calculator?

3. What is your OCCUPATION?
101 ] Student

103 ] Professional

109 ] Other

4. Where did you purchase this book?
403 ] Bookstore 404 ] Discount or Catalog Store407 [_] Mail Order 410 ] HP Direct 411[ ] Other
5. How did you first hear about this book?
501 [ JHP Owner 503 ]Advertising 506 ] Salesperson508 ] Other

507 ] Brochure

6. To what degree did this book influence your calculator purchase decision?
601 ] Major Influence 602 ] Minor Influence 603 ] No Influence
7. How well does this book cover the material you expected?

701 ]Good

702[ ]Moderate

703[ ]Low

8. What level of knowledge is required to make use of the topics in this book?
801 ] High 802 ]Medium 803[ JLow
9. How clearly was the material in this book presented?
901[]Good 902 ]Moderate 903[ ]Low
10. How would you rate the value of this book for your money?
111 [JHigh 112[]Medium 113 ]Low
Comments: (Please comment on improvements and additional applications or subjects you would like HP to cover in this or another solution book.)CORVALLIS, OR

HEWLETT-PACKARD COMPANYCALCULATOR MARKET RESEARCH
1000 NE CIRCLE BLVD.
CORVALLIS OR 97330-9988

POSTAGE WILL BE PAID BY ADDRESSEEPERMIT NO. 40

BUSINESS REPLY MAIL

FIRST CLASS MAIL

NO POSTAGE
NECESSARY
IF MAILEDIN THEUNITED STATESHP-42SRPN Scientific
Programming Examples and Techniques(ﬁﬁ

HEWLETT
PACKARD

Edition 1

July 1988

Reorder Number

00042-90020

NoticeThis manual and any keystroke programs contained herein are provided" as is" and are subject to change without notice. Hewlett-Packard Company makes no warranty of any kind with regard to this manual or the
keystroke programs contained herein, including, but not limited to, theimplied warranties of merchantability and fitness for a particular pur-pose. Hewlett-Packard Company shall not be liable for any errors or forincidental or consequential damages in connection with the furnishing,performance, or use of this manual or the keystroke programs contained
herein.
© Hewlett-Packard Company 1988. All rights reserved. Reproduction,
adaptation, or translation of this manual, including any programs,is prohibited without prior written permission of Hewlett-Packard Company,
except as allowed under the copyright laws. Hewlett-Packard Company
grants you the right to use any program contained in this manualin thisHewlett-Packard calculator.
The programs that 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 Division1000 N.E. Circle Blvd.
Corvallis, OR 97330, U.S.A.

Printing History
Edition 1

July 1988

Mfg. No. 00042-90019

Contents

1

6

List of Examples

9

How to Use This Manual

12

Programming

12
13
15
15
16
19
21
22
25
29
39
43
46
46
47
49
51
58

Simple Programming
Flowcharting
Defining the Program
Prompting for Data Input
Displaying Program Results
Executing the Program
Branching
Conditional Branching
Subroutines
Menu-Controlled Branching
Controlled Looping
Indirect Addressing in Programs
Flags in Programs
User Flags
System Flags
Error Trapping
A Summary Program
The Triangle Solutions Program

Contents

3

2

3

67

Enhancing HP-41 Programs

67
68
68
68
69
69
71
73

Using Named Variables
Using HP-42S Data Input and Output Functions
Prompting for Data with INPUT
Displaying Data with VIEW
Operations with HP-42S Data Types
Using the Two-Line Display
Using Menu Variables
Assigning a Program to the CUSTOM Menu

77

The Solver

77
80
80
83
86
92
92
101

Basic Use of the Solver
Providing Initial Guesses for the Solver
Directing the Solver to a Realistic Solution
Finding More Than One Solution
Emulating the Solver in a Program
Using the Solver in Programs
Using the Solver and Explicit Solutions in a Program
Using the SOLVE and PGMSLYVFunctions with
Indirect Addresses
More on How the Solver Works
The Root(s) of a Function
The Solver’s Ability to Find a RootInterpreting the Results of the Solver
Round-Off Error and Underflow

105
105
107
108
123

4

124

Integration

124
127
131
134
134

Basic Integration
Approximating an Integral That Has an Infinite Limit
Using the Solver and Integration Interactively
More on How Integration Works
The Accuracy Factor and the Uncertainty ofIntegration
Conditions That Can Cause Incorrect Results
Conditions That Prolong Calculation Time

140
143

4

Contents

146
146
147
147
149
150
154
154

Matrices
Using the Matrix Editor and Indexing Functions
Creating a Named Matrix
Using the Matrix Editor
Using Indexing Utilities and Statistics
Functions Interactively
Matrix Ultilities
Vector Solutions
Geometry

156
163
168
172

Coordinate Transformations
Solving Simultaneous Equations
Using the Solver with Simultaneous Equations
Matrix Operations in Programs

174
175
181
193

Statistics
List Statistics
Using the Summation-Coefficient Functions (X+,¥ -, and CLY) in Programs
Curve Fitting in Programs

194
194
202
212

Graphics and Plotting
Graphics
Multifunction Plots
Plotting Data from a Complex Matrix

Contents

S

List of Examples
The following list groups the examples by chapter.

1

Programming
20
32
42
57

Executing a Program from the CUSTOM Menu
A Programmable Menu
Loop Control in a Program
The Flag Catalog Program

74

Executing an Enhanced HP-41 Program from the
CUSTOM Menu

2

Enhancing HP-41 Programs

3

The Solver
78
80
84
87
90
99
101
110
112
114
116

6

Basic Use of the Solver
Directing the Solver to a Realistic Solution
Using the Solver to Find Two Real Solutions
Using the Solver for a Simple Resistive Circuit
Calculating Complex Values in an RC Circuit
Executing Algebraic Solutions for TVM Problems
Using SOLVE with an Indirect Address
A Case 1 Solution with Two Roots
A Case 2 Solution
A Discontinuous Function
A PoleList of Examples

118
119
120
121

125
128
131
136
138
140
142
143

146
155
161
163
166
169

A Relative Minimum
An Asymptote
A Math Error
A Local Flat Region

Integration
Basic Integration
Evaluating an Integral That Has an Infinite Upper
Limit
Using the Solver and Integration Interactively
The Accuracy Factor and the Uncertainty ofIntegration
A Problem Where the Uncertainty of Integration is
Relatively Large
A Condition That Causes Incorrect Results
Subdividing the Interval of Integration
An Upper-Limit Approximation That Prolongs
Calculation Time

Matrices
Accumulating Meterological Data
The Area of a Parallelogram
A Three-Dimensional Translation with Rotation
Solving Real-Number Simultaneous Equations
Solving Simultaneous Equations That Have
Complex Terms
Using the Solver to Find the Value of an Elementin the Coefficient Matrix

Statistics
178
191

Accumulating Statistical Data in a Matrix
A Linear Regression for Three Independent
Variables

List of Examples

7

7

Graphics and Plotting
199
201
210
219

8

Building a Logo
Using Binary Data to Build a Logo
Plotting Multiple Functions
Plotting Data from a Compression Process
and Fitting a Power Curve to the Data

List of Examples

How to Use This Manual
Welcome to the Programming Examples and Techniques manual for yourHP-42S calculator. This manual builds on concepts introduced to you in
the HP-42S Owner’s Manual so that you can more fully utilize yourcalculator’s powerful problem-solving capabilities. This manual focuses on
the following subjects:
m Programming techniques for the HP-42S.
m Enhancing existing HP-41 programs.
m Using the HP-42S built-in applications:m The Solver.
m Integration.
m Matrices.
m Statistics.
m Building and printing graphics patterns and plots.
There are many examples in this manual. We feel that the best way tohelp you gain expertise with your calculator is to show you how to solve
practical problems in mathematics, science, engineering, and finance.

Many of these problems are solved using programs. Chapter 1, "Programming," addresses the task of creating programs with the HP-42S. It further
develops material presented to you in chapters 8 through 10 of theowner’s manual.
Chapter 2 specifically addresses the topic of enhancing programs written
for the HP-41 calculator. It builds on the material introduced in chapter
11 of your owner’s manual.
Chapters 3 through 6 further develop the built-in applications discussed inchapters 12 through 15 of the owner’s manual. If you wish to learn more

How to Use This Manual

9about matrix operations, for example, you can turn directly to chapter 5,"Matrices," without working through the preceding chapters. However,since many of the examples in the manual are programmed solutions toproblems, you should first review chapter 1.
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 theowner’s manual.
The notations in this manual are consistent with those in the owner’s
manual;m Plain typeface is used for numbers and Alpha characters in keystroke
sequences: 1.2345, ABCD.
m Black keyboxes are used for primary keyboard functions in keystroke
sequences: [EXIT].
m Orange keyboxes preceded by the orange shift key are used for secondary (shifted) functions in keystroke sequences: Jj[ASSIGN].
m Menu keyboxes are used for functions executed from a menu in
keystroke sequences:m Capitalletters are used for any function that is referenced in text:
CLP.

m Capital letters are used for program names that are referenced in
text: SSS.
m Italic letters are used for variable names that are referenced in text:
STEP

m Dot matrix typeface is used for program listings:
a1 LEL "ARER".

At the beginning of each example,it is assumed that the stack registers(X-, Y-, Z-, and T-registers) are clear (contain the value 0). It is also
assumed that the value of each variable in the examplesis 0. Your display
may sometimes differfrom the displays in the manual. However, if you execute the keystroke sequences as they are shown in the examples, thevalues ofthe stack registers and variables in your calculator at the start ofthe examples will not affect the answers you obtain.

10

How to Use This ManualSome examples include optionalinstructions to print results with the
HP 82240A Infrared Printer. If you have a printer and execute these
instructions, you will not see some of the subsequent displays in the example. These displays will be printed.

How to Use This Manual11

ProgrammingYour calculator is a powerful and easy-to-use toolfor creating and executing programs. This chapter builds on programming methods introduced toyou in chapters 8 through 10 of your owner’s manual. Specifically, thischapter addresses:
m Simple programming,m Branching.
m Looping controlled by a counter.
m Indirect addressing.
m Flags in programs.
m Error trapping.

Simple Programming
The program SSS in this section finds the values of the three angles of atriangle when the values of the three sides are known. (The annotated listing is on pages 17 through 18.)

12

1: Programming

When the dimensions of the three sides (S, S5, and S3) of a triangle are
known, the following equations are used to calculate the three angles(A;,A2,and 43).

VPP -S

S;+8,+S(51S53)2

Az = 2 arc cos [M} where P = (—1——2—3)
VPP -S
A, = 2 arc cos —(——1—)](S253)

Ay =arccos|[ -cos (Az + Ag)]*

These equations form the main body of SSS.

Flowcharting
A flowchart is a graphical outline of a program. Flowcharts are used inthis manual to help you understand how programs solve problems.

Flowcharts can also help you design your own programs by breaking themdown into smaller groups ofinstructions. The flowchart can be as simple
or as detailed as you like. Flowcharts are drawn linearly, from top to bottom, representing the general flow of the program from beginning to end.
*

This expression for 4 ; enables you to calculate 4 in any angular mode.

1: Programming

13

Here is a flowchart for one possible program solution for the side-sideside triangle problem.

CALCULATEAzv
CALCULATE
Aov

CALCULATEAyv

DISPLAY
A1A2.A3v

14

1: Programming

This manual uses the following conventions for flowchart symbols:
m An oval represents the beginning or end of a routine. This can be thebeginning or end of a program, a subroutine, or a counter-controlled
loop within a program.
m A circle represents a program label. It also represents a GTO instruction to a program label from another point in the program. (This convention reduces the need for connecting lines that can make theflowchart difficult to read.)m A rectangle represents a functional operation in the program.
m A diamond represents a decision the program makes based on a comparison of two values (or based on the status of a flag).
m A triangle represents a decision the user (that’s you) makes by selecting one of several possible program routines, each of which performs
a different task.

Defining the Program
Program SSS begins with a global label and ends with an END instruction.
These two instructions define the beginning and end of the program.
H1

LEL

"S55

45 EHD

Prompting for Data Input
SSS prompts you for data input (prompts you for the three known valuesof the sides of the triangle).
a2 IHFUT "z1*@z IMPUT "s2t
a4 IHMPUT "szv

1: Programming

15

Displaying Program Resulits
SSS concludes by displaying (or printing) the calculated results (the three
angles).

41 5F 2142 WIEW "A1"
43 YIEW "A2"
44 YIEW "A3"This section of the program begins by setting flag 21, the Printer Enable
flag. When flag 21 is set, a VIEW (or AVIEW) instruction is:
w Printed and displayed if you have executed PRON. Program execution
does not halt when a messageis displayed; a subsequent VIEW (or
AVIEW)instruction erases the current message. When you set flag
21 and execute PRON, and then execute a program that has asequence of VIEW (or AVIEW) instructions, you must have a printerpresent and turned on to record each message; you’ll see only the last
message in the display.
m Displayed by the calculatorif you have executed PROFF. (PROFF is
the default mode for the calculator. You need to execute PROFF only
if you have previously executed PRON.) When youset flag 21 in
PROFF mode, program execution halts after each VIEW (or
AVIEW) instruction and must be resumed by pressing [R/S].

16

1: Programming

Helpful hints for keying in programs:
1. If the variables you are using in your program do not already exist,
create them before you select Program-entry mode (by pressing 0
variable for each variable). When you subsequently key in a
STO, RCL, INPUT, or VIEW instruction during program entry andare prompted for a register or variable, the existing variables(including the ones you just created) are displayed in the variablecatalog menu. You only need to press the corresponding menu key,rather than fype the variable name.
2. In Program-entry mode, first key in all the global label instructions
in your program (by pressing li[PGM.FCN]
abel for eachlabel). When you subsequently key in branch instructions and areprompted for a label, the existing globallabels (including the ones
you just created) are displayed in the program-catalog menu. You
only need to press the corresponding menu key, rather than type thename.
Longer programsin this manual are preceded by instructions that list thevariables and labels to create for program entry.
To key in SSS: Create variables S1, §2, 53, A1, A2, A3, and P before
program entry.

Here is an annotated listing of SSS.
Program:Comments:

g8 £ 115-Bute Prom 2

Line 01: Define the beginning ofthe@1 LBL "S55¢

program.

a2 IMPUT "S1"Lines 02-04: Promptfor the values of

a2 IMPUT "s2"a4 IHPUT "S53

the three sides and store the values in
named variables.

a5 RCL "sS1
As RCL+ "s2°
a7 RCL+ "53v

Lines 05-40: Calculate A, A5, andA 5. Store the values in named variables.

gz 2

B3 =+

1: Programming

17

=TO

IlFlII

M2© LAST
FCLs=

FCLn :E' 1 "w RCL=P SRRT
S

OHCOS

0

=TO
T
et

T

[

=IH

24 FCL

IIFIH

LASTH

O
a0 VooQ0 o P [
TD0

-

FCL=

1" IE; 1 1

FCL+

e
Tl

FCL=
SRRET
HCOS

oo 0 Qa0
UoI

LN

W
o
IIHE:IIHCOS=TOIIHIIISF 2 1* VIEW

Lines 41 -44: Display (or print) thellHlllYIEW "Az"WIEW "AZ"
EHL

18

1: Programming

calculated results.

Line 45: End the program.

Executing the Program
You can execute SSS by using any one of the following keystroke
sequences.
Using the Program Catalog. The global label SSS was automaticallyplaced in the program catalog when you keyed in program line 01. You
can execute the program by pressing

B(CATALOG] :PGM
This sequence requires a minimum of four keystrokes, depending on
where label
is in the program catalog. (If you have created morethan five programs subsequentto SSS, use the [¥] key to find label
888)
Using XEQ. When you press [XEQ], the program-catalog menu is
automatically displayed. Thus, you can execute SSS by pressing
ERae

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

and then the desired menu key.

1: Programming

19

The program can now be executed directly from the CUSTOM menu bypressing

B(CUSTOM
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.
Example: Executing a Program from the CUSTOM Menu. Find
the angles (in degrees) of the following triangle.

Assign SSS to the CUSTOM menu. Set the angular mode to Degrees.
Execute PRON if you have a printer and want to print the results. Begin
program execution.
B(ASSIGN] :S$170.8600
S I I ID

( B(PRINT
B(CusTOMEnter the value for S, (in feet) and continue program execution.

24

125

20

1: Programming$270. D000
essT[TEnter the value for S5, then for S;. The program now calculates thethree angles and displays 41, thefirst result. (If you have executed PRON
to print the results, you won’t see the next two displays.)
1 [R/S] 2.75

Continue program execution to see A,.
R2=33.9479
IIDI.

Continue program execution to see A 3.
A3=16.2136

Exit from the program.
EXIT

BranchingA branch instruction enables program execution to jump to a different
location in program memory. A branch can be:
m Conditional (based on a test).
m Unconditional (used typically to call a subroutine that, on completion,
returns program execution to the main program).
m Menu-controlled (executed by you from a programmable menu).

1: Programming21

Conditional Branching
The program SSA on pages 24 through 25 in this section illustrates theuse of conditional branching. SSA finds the two unknown angles and theunknown side of a triangle when two sides and the adjacent angle ( S,S, and A;) are known.

The equations used to calculate 45, A,, and S5 are|

Az =arcsin

[S2]
S1

.

|—| sinA,

A, =arccos|[ -cos (A; + A3)]
S3=5,c0s43+ S,c05sA4,

Note from the drawing that two possible solutions exist if S, is greaterthan S; and 4 3 does not equal 90°. This leads to a fourth equation.
Az = arccos ( -cosAj3)
SSA calculates both possible answer sets.
Here is a flowchart for the program.

22

1: Programming

SSA

v
INPUT

S1.S,. Ayv

CALCULATEAzv

CALCULATE
A1, S3YDISPLAYRESULTSvNOCALCULATEA
3YCALCULATE
A1, S3v

DISPLAYRESULTS

1: Programming

23

Observe from the flowchart that the program calculates the first answer
set, then compares the values of §; and S,. Depending on the result of
the comparison, the program either returns to label SSA or calculates thesecond answer set. SSA accomplishes this with a conditional branch. The
corresponding keystrokes are highlighted in the following annotated listing. (This conditional branch is based on a numbertest. Later in thischapter, you’ll write programs that make conditional branches based onflag tests.)
To key in SSA: Create variables S1, S2, $3, A1, A2, and A3 before program entry. (These variables already exist if you keyed in program SSS.)—

L 157-Bute Pram
LEL "SsA"

2

IMFUT "S1"Lines 03-05: Input the known vari-

IMFUT "S2"ables.

IHFUT "AZ2"

5 SIH
RCLx "2

0}

Y
't

2N L0

[

2 SF 21

T
00

ASIN

- s
[ =

ECL+

s T
o0

150 1

o

Comments:

=y

[}

[x]

Y
15
v
[

Program:

STO

"S1"
"R3"

RCL+ "AZ"

COsS
3 -

14 ACO:
15 =STO "AL"16 RCL "AZ"
17 COsS

18 RCLx "g2"
19 RCL"R:

28 COS

21 ROLx "S1°24

1: ProgrammingLines 06 —23: Calculate the unknown
variables.

=)
00
o0

03 M rd )Aop 00 0w) G 0- w0 Q0 =) n £ Do)

STO g3VIEW "A1"
VIEW "S3"YIEW "A3"
RCL "S1"
RCL "s2"KLY
GTO "SSA"
RCL "A3"
COS

Lines 24 -26: Display (or print) the
unknown variables.
Lines 27-30: Test if S, is less than orequal to S, . If so, return to the beginning of the program. If not, calculate
the second answerset.
Lines 31-48: Calculate the second
answer set.

+./-

ACOS
sTO "AZ"
RCL+ "A2"
COS
+./-

ACOS
5TO "AL"
RCL "AZ2"COS
RCLx "S2"
RCL "AS"COS
RCLx "S1v+

STO "Sge

]

n

N o
[ =

43 VYIEW "A1"
VIEW "S3VYIEW "R=2"
GTO

Lines 49 - 52: Display the second
answer set and return to the beginningof the program.

"SSAY

» EMD

1: Programming25

Subroutines
A routine is a set of program steps defined by a local or global label and a
RTN or END instruction. (Programs SSS and SSA are routines.) A routine becomes a subroutine when it is called by (executed from) anotherroutine using an XEQ instruction. After the subroutine has been executed, the RTN or END instruction at the end of the subroutine returns

program execution to the main routine.
Notice that SSA calculates the second answerset (if there is one) by first
calculating 4 3" . It then calculates the remaining unknowns using thesame equations that were used to calculate the first answer set anddisplays the second answer set using the same instructions that were used
to display the first answer set. By placing these shared instructions in a
subroutine, the program becomes:m Shorter.

m Easier to read.
m Easier to write.
m Easier to edit.

Here is a flowchart for a new program SSA?2 that uses a subroutine.

26

1: Programming

SSA2

v

INPUT

S1:52,4v

CALCULATE
Aj

Y

XEQ
SSASUB

B-=<>
Yv
CALCULATEICALCULATE
A

Ay S

’

3

Y

v

XEQ

DISPLAYRESULTSSSASUBRTN

The corresponding program lines are highlighted in the following annotated listing.
To key in SSA2:
1. Create variables S1, 52, §3, A1, A2, and A3 before program entry.

2. Create label SSASUB when you begin program entry.

1: Programming

27

XEG “"SSRSUBR"

0o

L o =] I=
N Q0 Do

127-Bute Pram >LEL "SSAR2"
SF 21
IMFUT "S1"
INFUT "“S2"INFUT "R2"
SIH
RCLx "S2o

E:':L+

Lines 06—09: Calculate 4.

llsl "=A ASIMoPt£

Comments:

A

o
=
D = =

Program:

11
12
12
14

RCL "S1"
RCL "s2"KLY
GTO "SSAZ"

Line 10: Call subroutine SSASUB to
calculate 4, and S 5. This unconditional branch uses an XEQ instruction; the next encountered RTN (orEND) instruction will transfer program execution back to line 11. (Nowfollow the branch to line 21.)Lines 11-14: If S, is less than orequal to Sy, return to the beginning of
the program. If not, calculate thesecond answer set.

9

Lines 19 -20: Call subroutine
SSASUB to calculate 4," and S3”.
Then return to the beginning of the
program.

"SSASUEY

GTO "S55

[ 0

XEQ

D]
I

oL

Lines 15-18: Calculate 45" .

[ =15 RCL "R3"
1e Ccos
17 + .1= ACOS

1 LEL "SSRSUE

STO "RI"
RCL+ "AZ"
Cos28

1: Programming

Subroutine SSASUB,lines 21 -39:

Calculate the values 4, and S5 (4~and S3” in the second answerset), anddisplay the results.

N

+.=

26 ACOS27 STO "A1"
28 RCL "A2"
29 €0336 RCLx "52"
31 RCL "A3"3z COS
3 RCLx=4"S1v+

35 STO "S3"36 YIEW "A1"
37 VIEM "53"32 VIEM "A3"
3% RTH
46 EMD
SSA2 is 13 lines shorter than SSA and 20 bytes shorter than SSA.
Nested Subroutines. The program TRIX. in the following section
organizes each of the five possible triangle solutions in subroutines
labeled A through E. Refer to the flowchart for TRIXA on pages 30-31,
and note that subroutine B, which calculates the solution to the SSA initialcondition,itself calls subroutine SSASUB to calculate A5 and S5. In
TRI X, subroutine SSASUB is nested in subroutine B. When subroutine
SSASUB is called by subroutine B, there are two pending subroutines.
The HP-42S can have up to eight pending subroutines.

Menu-Controlled Branching
Programmable menus enable you to make a decision during a program,
prompted by labeled menu keys that cause branches to new locations inprogram memory. Using KEY XEQ or KEY GTO instructions (which act
just like XEQ and GTO instructions), any label in program memory canbe made the target of a programmable menu key. When MENU and
STOP instructions are subsequently executed, program execution issuspended, the programmable menu is displayed, and keys 1 through 9(the six top-row keys, plus the (4], [¥], andkeys) assume theirmenu definitions.

1: Programming

29

The previous two programs, SSS and SSA, each calculated one of the five
triangle solutions. The other solutions respectively find:m S,, Ay, and S3(when A3, S;,and A, are known).
m S,, S3,and A3 (when S,;, 4,, and A, are known).
m A,, S3,and A5 (when S, 4,, and S, are known).
Here is a flowchart for a program named TRIA . TRIA organizes eachof the five solutions in a subroutine, builds a programmable menu, andallows you to select any solution by pressing the corresponding menu key.

TRIA

LBL
TRIA

BUILD MENUDISPLAY MENU
AND STOP FOR INPUT
KEY 1
*SSS*
XEQ
A

v

KEY 2
"SSA"
XEQ
B

v

@

30

1: Programming

KEY 3
"ASA"
XEQ
C

v

KEY 4
"SAA"
XEQ
D

v

XEQ RESULTS

KEY 5
"SAS”
XEQ
E

v

§ vy 7

INPUT
S1:52:53|

INPUT|S1:52: 42|

INPUT|43, S1. A1

INPUT|S1,41. 4

INPUT
1S1:41, 2

CALCULATE] [CALCULATE] [CALCULATE| [CALCULATE] [CALCULATE
A Ay AAg
Sy, A5, 53 |55, 53. 45 Ay, S3. 45
RTN
)

XEQ
o2iQe

RTN
(B

RTN
RTN
(B
)

@
YES

NO

XEQ
RESULTSv

SSASUBCALCULATE

Ay,S3CALCULATE
A

3

’

v
XEQ
SSASUBRESULTSCALCULATEAREAv

DISPLAYINPUTS,RESULTSv

1: Programming

31

The triangle symbolin the flowchart indicates where the program stops todisplay the menu. You choose which solution you want to execute bypressing the corresponding menu key.
Here are the corresponding program lines.
Program:Comments:@3 "s55¢
B4 KEY#“EG A

a5 "SSA"B KEY 2 ®EQ B

67 "ASA"

Lines 03 - 12: Build the menu keys.
(For example, lines 03 and 04 labelmenu key 1 with the Alpha string SSS
and define that key to execute a
branch to label A.)

B2 KEY 2 XEQ C
A3"SAAR"

18 KEY 4 REQ D

11 "SAS"
12 KEY 5 KEQ E
2 MEHU
4 STOPo WER"REESULTS"& GTO "TRIZ"

Lines 13- 16: Select the menu (line13) and suspend program execution(line 14). (The menu is displayedwhen program execution halts.) After
execution of any subroutine A throughE, call subroutine RESULTSto

display the results (line 15). Then
return to label TRIX at the start ofthe program (line 16).
The complete listing of TRI X is on pages 60—65 at the end of thischapter.
Example: A Programmable Menu. A surveyor needs to find thearea and dimensions of a triangular land parcel. From point A, he measures the distance to points B and C, and the angle between AB and AC.

32

1: Programming

Aq=098°12"This is an SAS (side-angle-side) problem.
Set the angular mode to Degrees. (Execute PRON if you want to print theresults.) Begin program execution.

@(MODES] [EG(B(PRINT) (A] FOH )% 0. 0000

555ssnshs shs|

TREIZ

Select the SAS routine by pressing menu key 5.
HE

S170.8000
355 s hsn SanShs |Key in the value for §; and continue program execution.
171.63A1706. 0008
EA I rEIEESKey in 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.

98.12[CONVERT]

297.35

Press

+HF:

S1=171.6300

x: 25, 256.2094

three times to see A,.

[R/S] [R/S] [R/S]

A2=27,8278

X: 29y 236.2094

1: Programming

33

Pressagain to see S.

R/S]

Press

$3=363.9118
X: 29y 226. 2094

again to see A 5.

R/S]

Press

A3=53. 9734
X: 29y 296.2094

again to see AREA.

R/S)
Press

ARER=25,256. 2094
X: 25y 256, 2094
again to display the menu.

%: 255 256. 2094
EASR
End the program.
EXIT

v: 27.8270
X: 29y 296.2094

Multirow Menus. The preceding program, TRI X, builds menu labels
for five of the six top-row keys, and assigns a KEY XEQ instruction toeach labeled key.
A multirow menu has more than one row of labeled keys. (For example,

the CLEAR menu has two rows.) When you enter a multirow menu, the(¥] and (4] keys enable you to move to each row in the menu. (The va
annunciator appears in the display to show you that these keys may be
used to display more rows.)
You can emulate a multirow menu in a program by assigning KEY GTO
instructions to menu key 7 (the [A] key) and menu key 8 (the (V] key).
(KEY GTO or KEY XEQ instructions for menu keys 7 and 8 also
automatically turn on the va annunciator in the display.)34

1: Programming

Consider the following simple menu of calculator functions.

cpon
LH
VA

Ry
- Ccos
VA

Biay
; +G
Here is a program that emulates this multirow menu.
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 Alphastrings.
Program:AR £A1Comments:

124-Bute Pram X

LEL"ROMW1"@z CLMEHUaz "a4 EEY 2 RER 81
S "LOG"@& KEY 4 KEQ @2
a7 “"LH"

Lines 01-13: Clear the current menu
definitions, then build and display the
first row of the menu. Assign branch
instructions to keys 7 and 8 (the [(A]and (V] keys) to the previous andsucceeding rows respectively (lines

B2
@3
18
11
12
12

09-10).

KEY S wER B2
KEY ¢ GTO "REoMz"
EEY & GTO "ROM2Y
MEHU
STOF
GTO "ROM1™

1: Programming

35

i Ju
[yl

e

e
=g
e
0
T o
oo

LEL "ROKZ"
CLMEHU=KEY 2 HER &4
nGIM"
KEY 4 HER 85

g Tl
MO

EEY

I—

Q0 Q0 D0 0 O 03 O 02 PO [-.J
[ - o0 =l
1T 2N Q3

o
'I_.

T L

r'l_.l

P
Foo

T
03

"ogse

KEY 5 XER 86
KEY 7 GTO "ROK1"&

GTO"ROMzSM

MEHU
STOF
GTO "ROKZ"LEL "ROWz"
CLMENUROY"
KEY 3 REQ @7
Ny s

KEY 4 XER 88
KEY ¥ GTO "ROWZ"
KEY & GTO "ROWL"
MEHLU
STOF
GTa "ROMZ"

[n]
[+2

LEL
LH
FTH

.._
1!
et

FETH

LEL
R4

(A
Ja

a
=J

2 fu Juaofa Jo Jo O 00
T LN e D0 [ = w0 0o

LEL &1
SRET
FTH
LEL
CLOG

2 ETH

O

Ju

Lines 14-26: Clear the current menu
definitions, then build and display thesecond row of the menu. Assign
branch instructions to keys 7 and 8 tothe previous and succeeding rows
respectively (lines 22 -23).

1: ProgrammingLines 27-37: Clear the current menu
definitions, then build and display thethird row of the menu. Assign branch
instructions to keys 7 and 8 to the previous and succeeding rows respectively(lines 33-34).

Subroutines 01 -08, lines 38 - 61: Execute the calculator functions

corresponding to each menu label.

1

[ax]
T

n

l_
m
-

Ll

RTH
LEL @7
HEPY
RTH
LEL
%)
!
[n]

noonoCn Cnon onoon onocn
00 =g 0 N 00 Do [
E
T
TN
— w0
i

[

SIH
FTH
LEL

+./ -

RTH
EHD

Nested Menus. In many menus, one or more ofthe six top-row menu
keys bring up a new menu called a nested, or submenu. For example, in
the PGM.FCN menu, when you press the%78 menu key, a nested

menu of related functions (X=0?, X#07?, ..., X>0?) is displayed. To returnto the main menu, you press the
key.

e
Y

Ie
R

_-|

Y

IR

D

You can emulate a nested menu in a program by assigning a KEY GTO
instruction to any labeled top-row menu key. Consider the following simple menu of calculator functions.

Here is a program that emulates this menu structure.
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

IILI.I'IL1 n

CLMEMUn + "KEY 2 HER @1
KEY 2 ®ER @Z2"TRIG"KEY S GTO “"LwWLz"
MEHL

Pk

—

LE:L

O
N

"cose

ek
b

CLMEMU"IN
KEY 4 HER 11i
T

IIL"I'IL.I:_'"

—

1

;:|

e

Lines 01-11: Build and display the
primary level of the menu. Assign to
key 3 (labeled TRIG) a branch
instruction to label LVL2 to build thenested menu (line 08).

STOP

GTO "LAvVLLY

Lines 12-23: Build and display thenested menu. Assign a branch instruction to key 9 (thekey) back tolabel LVL1 (line 20).

KEY 5 HER 12"TAH"
KE'Y “ER 13
KE' 9 GTO "LvVL1"
MEMU
STOP
} GTO "LyLz"[

L0 D0 0 0 MY P DT T T
B 03 PO o= 300 00 =) 1T i Sor'l_.l

M
'l_:
o
[

g
'I_'
T

o
o0

OO

)

e

Comments:

182-Bute Pram 2
LE:L

ke

ek
=
o0 OO

=

%
1
T
I I DTo)
1L
i
T LN e 03T5.._,..
ol 15=

Program:

38

El

LEL &1<+FTHLEL 82FETH
LEL 11SIH
RETH
LEL 12

1: Programming

Subroutines 01, 02, and 11-13, lines
24 -38: Execute the calculator func-

tions corresponding to each menu
label.

I

—H

m
-

walee

A

*TH
2

0O

|
-

oD O
g =]
T

0
0

*TH
EL 13

Controlled Looping
A controlled loop is a loop thatis executed a specified number of times.
You can build a controlled loop with a local or global label, an ISG or
DSE instruction, and a GTO instruction.
The program DISPL in this section uses a controlled loop to calculate
successive linear displacements of an object traveling at a constant velocity.
The equation of motion for constant velocity on a smooth surface is
X =Xxo t+ WVt

where:
x is the total displacement.
X is the initial position.
v is the velocity.
t is the elapsed time.
DISPL calculates the displacement at successive time intervals from ¢ = 0
tot = t; . It builds a loop counter of the form fffcc by prompting you forthe value of ¢;, and for the value of STEP (the value of the time interval).
t; becomesthefff portion of the counter and STEP becomesthe ii portionof the counter.

1: Programming

39

Here is a flowchart for DISPL.

DISPL

LBL
DISPL

INPUT
Xg Vs tf,STEPv
BUILD COUNTERFROM t, , STEPFOR EACH TIME
(0TO t))CALCULATE

INCREMENTt@&=
The program segmentthat uses a controlled loop to calculate successive
values of x 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:g8 £Comments:

116-Bute Pram

81 LEL "DISPL">Bz SF 21"x@"

Lines 03-16: Promptfor the vari-

B2

IHPUT

@4
a5
Be
a7
Az
B39
18
11
12
12
14
15
16

IMPUT "ot
IMPUT "“tF"
IMPUT "STEPR"
RCL "tF"
1E-2
X
STO "fff"
RCL "STEPRP"
1E-5
x
STO "ii"
RCL+ "fff"
STO "COUMHT"

ables. Build the counter.

17
18
12
28

LEL @81
RCL "COUNT"IPRCLx "otLines 17-27: Calculate successive
values of x in the counter-controlled

21

RCL+

loop. (Note that the integer part of
COUNTin line 19 is the time ¢.)"x@"

22 STO "=22 CL=»
24 WIEMW "x"25

ISG"COuHT"

26 GTO @1
27 GTO "DISFL"
22 EHD

1: Programming

41

Example: Loop Control in a Program. Find successive values ofthe displacement x of an object in intervals offive seconds from ¢ = 0 to
t = 15 seconds whenx, = 10 meters and v = 20 meters/second.
Begin program execution.
XEQ] I-v: B.08080
xB870.08800

Enter the values for xy and v.
10 [R/S] 20 (R/S]

v: 28.008080
tF"B [5]5]%]%Enter the value for ¢, and continue program execution.
15 [R/S]

v: 15, 0000
STEP?0. 0000

Enter the value of STEP (the size of the interval) and continue program
execution.

5 [R/S]x=

The value ofx at ¢t = 0 is 10. Pressagain to display the value of x at

t=35.

TR

Press

to see the value ofx at t = 10.

5

Press [R/S] again to see the value of x at t = 15

T

Press

again to prompt for new values. Exit from the program.

[R/S] EXIT]

42

1: Programming

v: 8.0000

x 10. 0000

Indirect Addressing in Programs
Indirect addressing is a useful programming tool, particularly when usedin combination with a controlled loop. The operation index in yourowner’s manual indicates which functions can use indirect addresses. In
this section, three applications of indirect addressing in programs arepresented.

oY)

.'_
15!
-

Using Indirect Addressing to Initialize Data Storage
Registers. Program INIT prompts for data and storesit in successive
registers using INPUT IND in a controlled loop. Thisis a useful initialization routine if you are using registers instead of variables for data storage
and recall.
@1£

27-Bute PramLEL

"IMIT"

Az 1.a1
A2 STO "COuMT"

Lines 02-03: Build a counter andstore it in COUNT. The counter has abeginning value of 1, a test value of 10,
and a default increment value of1.

a4 LEL @1

Lines 04—-07: Prompt for data for suc-

B85 IMPUT IHD "COUHT"

cessive registers Rg; —Rg.

Be

ISG

"COUWT"

a8y GTO 81
Bz EMD

1: Programming

43

Using Indirect Addressing to Clear Registers. The following
routine clears a specified number of storage registers using STO IND in acontrolled loop.
Program:Comments:

Hi L 74-Bute Pram

Line 02: Initialize the X-register to 0.

S S
o0 00 =gO e 0"FIRST?"
FROMPT
STO "COUNT". "LAST?"
FEOMFT
1E-=

—

STO+

: d
"COouWT"

=)

oo

i

b
b

LI

2

44

Lines 11-15: Successively set thevalues of the block ofspecified registers to 0.

GTO 148& TOME 9
7 "READY"& PROMPT

P

ke

—— N

STO IMD "COUMT"
ISGLines 03-10: Build a counter in
COUNT. The counter has a beginningvalue equalto the first data storage
register to be cleared, a test value
equalto the last register to be cleared,
and an increment value of one.

"COuWT"LEL 1@[

Pt"CLERE"

]

]

M

LEL

-

EMD

1: ProgrammingLines 16—18: Sound a tone anddisplay the message FERLD'Y. Press
to end the program.

Using Indirect Addressing to Execute Subroutines. The following routine retrieves data (telephone numbers) from subroutines using
XEQ IND.

-~

[
OO

[N]

o
=~ O O

I
Fa

™
'

00

il

T

T
o
=

Program:Comments:

124-Byte Fram

LEL "FHOME""HAMET?"
HOH
FROMFTROFF
ASTO ST =REG IMD ST =W
FROMPT

Lines 02-08: Prompt for the name
(Alpha string) whose telephone
number is desired (lines 02-05) andstore the string in the X-register (line06). (The string may besix Alphacharacters maximum; the X-registerholds only up to six Alpha characters.)
Execute the subroutine whose label
matches the Alpha string (line 07),
then suspend program execution (line08).

LEL "JAHET""BER-5355-9374"
RTH
LEL "BRUCE""BEE-355-135"
FTH
LEL "FPAM""BERE-555-c022"
FTH

Lines 09 -23: Build the telephone
numbers (actually Alpha strings)in
the Alpha register.

g LEL "CHRIS""HEE-555-6276"
RTH
LEL "EOE""BEE-555-2411"
RTH
EHL

1: Programming

45

Flags in Programs
Earlier in this chapter you wrote a program SSA that makes a branchbased on a numbertest; specifically, SSA uses the X<Y? function to construct the branch. The program asks the question: Is S5 < 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 functions enable programs to ask questions only
concerning number values.” However, programs can also make conditional branches (ask questions and make decisions) based on flag tests.
Flag tests follow the "do-if-true" rule. If the test is true, the next instruction is executed. If the test is 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
manual for 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.

General Purpose Flags. General purpose flags (flags 00 through 10
and 81 through 99) are not used internally by the calculator; what theymean depends entirely on how you define them.

*46

The X=Y? and X#Y? functions are exceptions; they can compare Alpha strings.

1: Programming

on

LEL B2
1
EMTER
FC? @1bl

LIM "ELIST"
T ORER I
E4

0

2

2 E+

B

Q00

00
T

Ol

00
Jo

D)
O3

O
O

00
o

The program LIST on pages 176 through 178 creates a matrix LLIST
using the following instruction sequence.

A GTO 88

Before you execute LIST, you set flag 01 if you want ZLIST to be a 1column matrix, or you clear flag 01 if you want £LIST to be a 2-column
matrix. Flag 01 is defined to have a unique meaning in the program,;its
status determines the number of columns in the matrix XLIST.
(Remember that current status of user flags is maintained by HP-42S
Continuous Memory. This can affect other programs that use the same
flags.)
Control Flags. Control flags 11 through 35 have a specific meaning andare used internally by the calculator. For example, flag 21, the Printer
Enable flag, affects the way the VIEW and AVIEW functions work inprograms. When flag 21 is set in PROFF mode, VIEW and AVIEW messages are displayed, and program execution halts. When flag 21 is set and
PRONis executed, VIEW and AVIEW messages are printed and program execution does not halt. Many programs in this manual that use
VIEW or AVIEW alsoset flag 21.

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.
The following program, MINMAX, searches for the maximum or
minimum element of the matrix in the X-register. In line 23, it tests thestatus of system flag 77, the Matrix End-Wrap flag, to determine if the lastelement of the matrix has been checked.

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 element, or clear flag 09 to find the minimum element.

STO "MIMMAX"THDEY "MIHMA:"

P

Jarr
1o L
23 ea
Ly
—
it
1
a0
m
D
o

LEL BzRCLIJ
RCL =T
EMTER

=8
21
2z
22
24

LEL &4
F4J+
FC? 7YGTO @1

IJ

[n}
Ja

h

e
1V
1=
17

-

oo

— F. @

[y]
on S
N

Q0

b e T™
~
"
|
o0 00

FCLEL
GTO &2

DU]
=) i

LA

| KX
!

i

.,..
150
—
'
e

L Bl-Bute Fram
LEL "MIHMA="

od(The annotated listing is on pages 152 through 153.)=2 EHMD48

1: Programming>

Error Trapping
When you attempt an improper operation during function execution, theoperation is not executed and an explanatory message is displayed. For
example, if you execute the keystroke sequence
1 (E] 260 (7]the calculator returns the message Cut of Fanas, and leaves the value

1 x 10® in the X-register.

L

Z2e-Bute Fram>

LEL "TERF"
SF 21
IMFUT "avAt
STO "y= WIEW "W* GTO "TRAFR
= EHD

0

.._.._
120 )
o=

o
oL

™
Il

T
it

[

|T
e’
o
o

==

If an improper operation is attempted in a program, the calculator returns
the corresponding message, and program execution halts at the instructionthat caused the error. Consider the following program.

If you execute TRAP and supply the value 1 x 10?® for X, the program
halts at line 03 and the calculator displays the message Cut of Range.
To supply a new value for X, you must restart the program at line 01 (bypressing
TEHAF). In a short program like TRAP, this method ofrecovery from an error presents little problem. However, when executing
a program that performs time-consuming calculations, or that has
numerous stops for intermediate data entry, it may be inconvenient torestart the program at line 01 each time an error occurs.

1: Programming

49

You can enable program execution to continue after an error has occurredby setting flag 25, the Error Ignore flag. When flag 25 is set:m One error during program execution is ignored. The instruction thatcauses the error is not performed and program execution continues at
the next instruction.
m The error clears flag 25.

.,.

15!

[]

—
e

SF 21
SF 25
IHPUT "3"
K42
FC?C 25
GTO @e
STO "yWIEW "yGTO "TRAF"
LEL @8
CF 21
EEEF

—

LN e

[y

-]
T

"Out

Pt

-

+ S52-Bute Pram
LEL "TERF"

1

T
oD

T
00

T
=g

=
T

T
O

™
T
T
f O

O

i
151

Consider this revision to TRAP.

2 GTO

of

Rangs"o

AYIEHW
FSE
FSE"TEARF"

19 EHMD

TRAP now responds to the error condition by:
m Displaying an error message.
m Resetting flag 25 and prompting for a new value for X.
This programming technique, called error trapping, adds program steps,
but is effective when you can identify operations in a program that arelikely to generate errors.

50

1: ProgrammingA Summary Program
The program FCAT in this section displays the currentstatus of flags 00
through 99. The flags are displayed in a multirow menu in sets of six.
Each of the menu keysis labeled with a flag number. You can set andclear user flags 00 through 35 (except flag 25) and 81 through 99 by pressing the corresponding menu key. The "=" character is appended to themenu label if that flag is currently set. When you attempt to set or clear asystem flag, FCAT beeps and displays the error message Festricted
Operat ion. The previous set of six flags is displayed by pressing menu
key 7 ([A)), and the succeeding set is displayed by pressing menu key 8().
FCAT uses many of the programming concepts discussed in this chapter:
Global and local labeling.
Prompting for data input.
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.

OINITIALIZEBUILD A MENU
OF SIX FLAGSXKEYS 1 THRU 6KEY 7(PAGE UP)SET ERROR
IGNORE FLAGKEY 8

(PAGE DOWN)

INCREMENT
COUNTER BY 6v
TOGGLE FLAGYDECREMENT
COUNTER BY 6YES
ERROR ?
*RESTRICTEDOPERATION*MESSAGERESETCOUNTER TO 96-]

52

1: Programming

RESET
COUNTERTO 0

Here is the annotated listing.
Program:Comments:

BE L 224-Bute Fram
@1 LEL "FCRAT"X

B2 B, 89086

Lines 02-03: Store the loop counter

Bz STO Bd

iﬂ R 00 -B4 LEL H
HS RCL B8
Be HER B8

Lines 4—17: Build menu keys 1-6.

By KEY1

GTO 81The label for each menu key is built by
calling subroutine 00. (Now go to subroutine 00.)

BE HKER B8
83 KEY 2 GTO a2
18 =EQ B811 EEY 2 GTO B2
12 REQ B8
12 EEY 4 GTO &4
14 =ER @@o KEY S GTO 8%
16 #2EQ B8

L

—
It

13 KEY 7 GTO
19 KEY & G

I=]

17 KEY & GTO Bg

23 "FLAG CATALOG"
21 MEHUs

E'

2= STO 81
24 FROMFT
23 GTO A

Lines 18 -19: Assign GTO instructions
to menu keys 7 and 8.
Lines 20 -25: Build the Alpha string
FLAG CATALOG (line 20). Display
the menu (line 21). Initialize register
R, to 6 (lines 22-23). Display theAlpha register, suspend program execution, and prompt for numeric input(line 24).

1: Programming

53

T

OOD
-] T O

Gl
f

O
00

O O
o= S0

o0

0D

=)

[ [ [0 [Subroutine 00, lines 26 —37: Build the

W
RTH
ALF
Fo? IMD 5T =I__ " n "

1
+

FTH

S
P

2 DsE

T
== T

=g

D S I =So o= 0 =&[o ofo Jo D0 0D
N B 0 [ Pt W0 00

LEL |1
L=E a1
LEL
LSE
LEL
bSE
LEL
L=E
> LEL
DsSE
LEL
Foo

28 LELa1 RCL a1
s ECL+ 88

54

1: Programming

Alpha string for each menu key. First,
test to see if the current value in the
X-register (the loop counter) is
greater than 99 (lines 28-31). If yes,
do not build a label for the menu key.
(The highest numbered flag is 99.) If
no, append the (integer portion of) thevalue in the X-register to the Alpharegister (line 32). Test the status of
the flag whose number is in the Xregister. If that flag is set, append the"w" character to the Alpha register(lines 33—-34). (Thus, the Alpha label
for each menu key consists of anumber, and,if the correspondingflag
is set, a "u".) Increment the value ofthe X-register by 1 (lines 35-36).
Lines 38 - 52 establish the flag to be
set or cleared: Successively decrement
R, by 1 (lines 38-49). (If menu key 1
is pressed, the value in R, is 0 when
Ry is recalled to the X-registerin line
51. If menu key 6 is pressed, the value
in Ry, is 5 when Ry is recalled to theX-register.) Add the current value inR (the counter) to the current value
in the X-register (line 52). (The value
in the X-register after execution ofline 52 is the value ofthe flag to be set
or cleared.)Jaoon n i

[an]
)

]

=~

[

T M
r

oA

I

=W0

SF IND ST ¥
GTO A

>

T
Iy
T
T
I
I
[np)

0 g R OT00

T O N Cnon

=)

[n}
T

SF 25
FC?C IMD ST =Lines 53 - 56 build the set/clear toggle
and error trap: Set the Error Ignore
flag (line 53). Testif the flag (whose
numbervalue is in X) is clear, thenclear 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 theflag was set, and the clear operation
does not cause a Restricted Operation
error, return to the menu-label routine to update the flag status (line 56).
Lines 57-61: If the branch to label 09
was caused by a Restricted Operation
error, go to label 10 (lines 57-59). If
the branch to subroutine 09 was executed because the flag was clear, thenset it, and return to the menu-label
routine to update the flag status (lines
60-61).
Lines 62—-69: Decrement R , by6.
(Thus, when [¥] is pressed, the toprow menu keys are each relabeledwith the numberthat is six /ess than in
the previous menu. If R, has thevalue 12 when (V] is pressed, R, takes
the value 6, and the menu keys are
relabeled 6-11.) Testif the new valueof Ry is less than 0. If yes, store 96 in
R (lines 66 —-68). (Menu keys 1-4
will be labeled 96-99.)

1: Programming

55

00
T

x]

—
ol
G

=] =l
o=
=]
[
-]
0

GTO A
} GTO "FCAT"

Lines 70-73: Increment R i, by 6 using
the ISG function. (Rememberthat the
number in Ry, is the loop counter; it
has the initial value 0.09906. When [A]is pressed, the top row menu keys areeach relabeled with the number thatis
six greater than in the previous menu.
When the counter test value exceeds
96, program execution transfers to

n N

=)
)
=)
=)
00
00
00
Q0

00
Q00
Q0
00
00
OO
II'

=

o)

GTO
wER

",
oo g 1T N Q0 Do o0
I D 000 =)LEL 18
FS?C 21

l:r'u

FCAT, restoring the counterto its initial value; the menu keys are thus relabeled 0-5.)

56

11
12

GTO A
LEL 11nmER 12
SF 21
GTO A
LEL

12

EEEF
"REestricted "F'Operation”
AYIEHN
FSE
RETH
EHD

1: ProgrammingLines 74-89: Execute the BEEP function, display the Alpha message
Festricted Operation, andtransfer program execution back tolabel A. If flag 21 is set, clear it before
displaying the Alpha message, thenreset it. (Program execution continues,
redisplaying the flag menu, and thestatus offlag 21 is maintained.)Example: The Flag Catalog Program. Use FCATto setflag 01.
Check the status of flag 38. Attemptto set or clearit.

Start FCAT.
ECATFLAG CATALOG(o1213415

Set flag 01.
FLAG CATALOG[o] 1o|2|3|4|5|

Check the status offlag 38.

v (v [v)V) V) V)lFLFlG CATALOG__I

36 37« 38 39 Yom 41

Flag 38 is clear. Attemptto setit.
FLAG CATALOG
36[ 37w|38|39| 4om|41|

The calculator beeps, displays the message Restricted Operation,and returns to the state before the error. Exit from FCAT.
EXIT

v: 42.0961
x: 6.0800

1: Programming

57

The Triangle Solutions ProgramThis section contains the complete set of equations for the triangle solutions, instructions for keying in TRIX , an annotated listing of TRIX., andinstructions for using TRI X .

Ay

Ag

A2

Program Equations. The following equations are used in the program:m Condition 1: S;, S, and S5 (three sides) are known:
VP(P

_Sz)

(S1+S2+S3)

A=2= ———~~
3arc cos[ —(s, 53)]wwhereP
ere>A,

VP(P -sl)]

2=2arccos ————

(S2S3)

A, =arccos[ -cos (Az + A3)]

58

1: Programmingm Condition 2: S, S, and 4, (two sides and the adjacent angle) are
known:|

Agz = arcsin

[S2]
S

.

[—| sinA,|*

A, = arccos [ -cos (A; + A3)]
The problem has been reduced to the A5, S, A, configuration.
m Condition 3: 43, S, and 4, (two angles and the included side) are
known:Ag = arccos[ -cos (Az + A;)]
<

<
27+

SinA3
SinA2

S3=8,c0sA3 + S,c0s A,

m Condition 4: §,, 4, and A, (one side and the following two angles)
are known:
Az =arccos|[ -cos (4, + A3)]
The problem has been reduced to the A3, S, A4, configuration.
m Condition 5: S, S, (two sides and the included angle) are known:
S3 = \/Slz + S22- 2S1S2COSA1

The problem has been reduced to the S, S, S3 configuration.
m For any triangle, the area is:

AREA = -;—5153 sinA*

Two possible solutions exist if S, is greater than §; and A3 does not equal 90°. Bothpossible answersets are calculated.

1: Programming59

To key in TRI X :1. Create variables S1, S2, §3, 41, A2, A3, P, and AREA before pro-gram entry.
2. Create labels RESULTS and SSASUB when you begin program
entry.

Here is an annotated listing of TRIX .
Program:
I'l"

!
[y

BE £

Comments:

S7V3-Bute Pram

LEL "TRIZ"

Bz SF 21@z nsogea4 KEY
XE® A
BHa

Lines 03-12: Build the menu key
assignments.

"SSRY

Be KEY 2 BEQ B
gy "ASR"HER D

MEHMLI

Lines 13-16: Display the menu keys.

4 STOFo HER"RESULTS""TRISY

b

]

b

00

FCL
RECL+

r':_'lO3r'l_:lN[r'l_.l

r'l_"

b

LEL A
IHFUT "S1

o0

GTO

=

=

IHPUT "s2"
IHFUT "S53r'l_:l

m

>
m
[

7

n

N o m

—_
[
ek

BEQ C

[

Pt

4

m
w D=L

A

.
=

.

B[S KEY 2|3 "SHA"

60

"S1t
"S52M

RCL+ "53v—

1: Programming

Subroutine A, lines 17-59: Calculate
the SSS solution.

5
0 0 O3 o) 00 0 00 o [ D O
a o o 0D QO Q0-] i
on Lo 00 O e o0 00 =g To £ W My = oD 0

STO

“po

H*E

LAST
"sz2©

RCL»x

FCL

"S1v
wgav

RCL»x

SORT
ACOS
—

sSTO "A3"
SIH
RCLx "S1*STO @8RI:L

n Fl "nre
LASTX
RCLx "S1*

HCOS

RETH

"RAZ"

5TO "AL"
LEL E

Subroutine B, lines 60—100: Calculate

IHFUT "5z
IMFUT

"R2"

I

"Z1v

T

IMFUT

T
S

=

N
I

COs
4+ -

=)

RCL+

w0

R

: 5TO “"A2"

i
D

1T

on Jnoon CnoCnoan ooM

RCL+ "32"
RCL+ "S3"
SORT
ACOS

the SSA solution.

1: Programming

61

N S 03 D e W0 OO =J O N 00 O = ooy 0 nof

0 w0 D Ok D D D 00 00 00 00 03 0 00 0D Q0 00) s )]) T T T T

SIH
RCL=

"52"

» RCL+
ASIH

"51"

STO
SIN

"R3"

RCLx "S1"STO 68
HER "SSASUBM
RCL "S1
RCL "Sz2"
ney?
RTH
#ER
RCL
cos
+./—

"RESULTS"
"R3"

"R3"

RER
FETH

"SSASUBYLEL"SSARSUBM

[

RCL

"AR3"

RCL+
cos
+./—

"R2"

ACOS
STO "AL"
RCL "mRz2"
cos

w0
=)

RCLx "s2"
RCL "R2"
cas
RCL=

g,L
—
Voo 00M

STO

n AWM = @0 03

ARCOS

+

STO

"S1*
5o

13 RETH62

1: Programming

ek

I
O e

ek
b

T
oo 00

+.=

o0

-~
o)

late the ASA solution.

HCOS

5TO "AZ"
RCL “AZ"

o

ek
et

b

© RCL St

0

ek
e

b
—

00

ek
ek

Cos

S
150

RCL+ "AL"Pk

Subroutine C, lines 101 - 126: Calcu-

RCL "A3"

ek

ek

F_F
1o 150 15
=g T
T

ek

LEL C
INFUT "AZ"
IHPUT "51"
IHFUT "AL"

v

+RELC

114 Hwy
115 =

11e
117
11z
113
128
121

STo

122

Ft

oo

S

124

+

el

STO

s

oo

126 FTHv LEL DT N elIHFUT "51"
IHFUT "A1"
IHFUT "AZ"
RCL+ AL

Subroutine D, lines 127 -150: Calculate the SAA solution.

+ .=
ACOS
STO "AEM
FCL "s1t

1: Programming

63

b b
Q0
o0 )
ek
03
w0
ek
fao
T

ECL "R2"
1

Pt b
Foo Fa
Vo

STO

B8

145
144
145 STO "San146 Ft147 =148
143 =TO ngav
156 FTH
ek

e
O

ek
ek

0l
e

ek
ek

=
i

ek

ek
ek

=
A

o3
=H

LEL E
IMFUT "s1"
IHFUT "AL"IHFUT "=z
RCL ALY
M+RELC

RCL "S1t
+FoL

ek

T

RCL+ "S1"
RCL+ v5zv

ek

T
e

T

ek

tocle

ek
ek

T
)
T
00

bk
ek

= T
D0

b

=] =)
o

b

ek

"po

LAST:

=]
D0

Pt

=T
L4 =
—

=]
Joo

ek

T
e

T
LN

ek

ek

vgoo

T
Ta
[0

STO

1T
0l

o=

e

ek

)

bk

O

znoon ocnoon

—
ke

+

64

RCLx "5zm
RCL "ste
FCL=

wgov

SEET

1: Programming

Subroutine E, lines 151 -194: Calculate the SAS solution.

ek
ek
ek
ek
ek
ek
pek
ek
ek

STO
SIH

"R3"

RCLx

"S1"

STO B8RECL "P"

Ktz

"S1"

RCL+

"=

ECL+

"S5

SERET

s
et

X

RCOS

sTo "A2"
RTH
LEL "RESULTS"

Subroutine RESULTS,lines 195 -208:

RCL &&

Calculate AREA and display the initial

RCLx "S2v

known values and the results.

='.lll I Elr'j" E; 1

VIEW

"AL"

VIEMW

"S2¢

M2

=
o

P O P Pl[xn] T
oao=J |‘_T‘I an

-~
[

Pl

PO

=

STO “"ARER"

-~
e

P3O

[l
o

o =
W00

oo WO
o0 Py S0 00 =) O N

P et b
ooWO

ek
w0

0l Do

ek

ek

RCLx

bk
OO
=y

LAST:

pd
0D
00

ek

¥

b b
o0 00
o0

o0 00 0D 00 00 00 00 ) )] ] =I:I"- 2Nof 0 o= oD ) lTI on

ACOS

"

VIEW "R2"
VIEM "S2"VIEM "AZ"
VIEW "ARER"
FTH
EHD

1: Programming65

To use TRI % :1. PressTR

2. Select a solution by pressing the corresponding menu key.
3. Input values as prompted. You can name any side §;. A, is theadjacent angle. You can enter values in a clockwise or counterclockwise order. The values are displayed in the same order as they wereentered.

66

1: Programming

2
Enhancing HP-41 Programs
In chapter 11 of your owner’s manual, you keyed in and executed a program originally written for the HP-41 calculator. That program, named
QUAD,solves for (real number) roots of quadratic equations. Two programs Q2 and Q3 in this chapter use HP-42S features and functions toenhance QUAD. A third program QSHORT uses only 11 lines to solvefor quadratic equation roots.

Using Named Variables
In the HP-42S, data may be stored in and recalled from data storage
registers or named variables. Programs that use named variables for data
storage and recall can be easier to write and read.
In QUAD, the values of coefficients a, b, and ¢ are stored in and recalledfrom data storage registers. In Q2 these values are stored in and recalledfrom named variables a, b, and c. (Q2 also stores the values of the tworoots r, and r, in named variables R1 and R2. In QUAD,these values arecalculated and displayed, but not saved.)

2: Enhancing HP-41 Programs

67

Using HP-42S Data Input and Output
Functions

Prompting for Data with INPUTThe HP-42S INPUT function enables programs to prompt for data in one
program line.

[0-" -3=.?' 1"

FROMFT

T

150

%
N
oo

QUAD prompts for the value ofa, then stores the value 2a in a data
storage register with the three-instruction sequence

STO B8Q2 uses INPUT (and the named variable a) to replace these three
instructions with one.
B2

"a"

IHFUT

Displaying Data with VIEW
The HP-42S VIEW function enables programsto display data in one program line.
QUAD displays the labeled value of ; with the three-instruction
sequence"ROOTs="28

ARECL =

=1

AVIEW

ot

29

Q2 uses VIEW (and the named variable R1) to replace these three
instructions with one.
22

68

VMIEW

"REL"

2: Enhancing HP-41 Programs

Operations with HP-42S Data Types
Programs written for the HP-41 calculators can operate on only two datatypes: real numbers and Alpha strings. Programs for the HP-42S, however, can also operate on complex numbers and matrices.
In QUAD, complex-number roots cannot be calculated; instead,if thevalue b2 - 4ac is less than 0, the calculationis halted and the message
ROOTS COMPLEX is displayed. In Q2, complex number roots are calculated, stored in variables, and displayed.

Using the Two-Line Display
Programs can effectively show longer messages in the HP-42S two-line
display. In Q2, the two-line message
Zero Imput Inwalid.
Fress E<S to continue.

is displayed if 0 is supplied for variables a or c.
To key in Q2: Create variables a, b, ¢, R1, and R2 before program
entry.

Here is an annotated listing of Q2.
Comments:

Aa £ 132-Bute Pram X

Lines 01-05: Display the 0-input error

a1
B2
a2
84

message.

nProgram:
LEL B84"Zero Input Inwa"
F"lid.4%Fress RsSY
F" to continue.”
FROMFT

2: Enhancing HP-41 Programs

69

W

[ e
o0

e
D0

e
=g 1T

—
2Nofe

—
0

—t =
P o0 00

™
]
=g

[]
T

> LBEL "Rzt

CFHRES
SF 21
IMFUT "a"H=@7
GTO @@IMFUT "h"IMFUT "
H=E7
GTO @3

ROL b

Lines 06— 15: Set the program to calculate complex numbers, prompt for
the values of @, b, and c, and test if 0 is
supplied for a or c. (Flag 21 is set inline 08 so that VIEW results are
displayed in PROFF mode, or printed
if PRON has been executed.)Lines 16 —24: Calculate+.=

EMTEF:
M2

Vb? - dac

4

RCLx "a"RCL="e”

30 o0 [l o o
Pt o0 00— l:r'l n

SRET
FECL "BZIGH

Lines 25-31: Calculate either-b + Vb2 - 4ac
2aor-b - Vb2 - 4qc
2a

00
o [

depending on the sign of b. Lines 25—
27 ensure that the root that has thegreatest absolute value is calculated
first. This improves the accuracy of
the results.

70

STO "RLM
VIEW "RE1M

Lines 32-33: Store the calculated

value in R and display R1.

2: Enhancing HP-41 Programs

34 RCL "c25 RCL+ "aLines 34-38: Calculate the second
root, store the value in R2, and display

26

R2.*

RCL+

"R1“

a7 STO "R2"
28 YIEM "R2"
39 GTO "mz¢Line 39: Return program execution tolabel Q2.

48 EHND

Using Menu Variables
Q2 uses the INPUT function to prompt for the values of the program
variables a, b, and c. Q3 uses a variable menu to prompt for these values.
The corresponding program lines are highlighted in the following annotated listing.

*

The quadratic equation ax? + bx + ¢ = 0 can be divided by a (since a cannot equal 0)
yielding x2 + bx 4 € _ 0. Tnis equation can be factored as (x - R,)(x - R,) whereaR, and R, are the roots of the equation. By definition of the factoring process,CC(Rl)(RZ) = z‘ Thercfore,R2 = za——R—l—)-

2: Enhancing HP-41 Programs71

To key in Q3: Create variables a, b, ¢, R1, and R2 before program

entry.

S
S
S
T
=

b o
o= o0 00 =n Fo 03 O o= I

Program:£Comments:

143-Byte Pram

LEL @&
"Zero

Input

Inuwa"

F'lid.%Press R-S"F"

to continue. "FROMFPT» LEL "nRa2r.‘l".IHF‘:

n 3 1]

F‘ l."IHF:" t| "

b bk
W0

b
)

b ek
TN

ek
B

s
0w Ml

MYAR "CPXRESSF 21
2 YARMENU "G3"
} STOP

Lines 06 —-13: Declare menu variables
a, b, and c, set the program to calculate complex numbers, set flag 21, anddisplay the variable menu.

RCL

"a"

H=@7
GTO 6@RCL “c"
W=@7
LTO a8
RCL "b"
+./=
EMTER

W2

4
RCLx "g"
FECL=

00 [
P w0

oo

72

"ot

SRET

FECL "b"SIGH

2: Enhancing HP-41 Programs

|

0l

2N 03

o0

F I::L_:_"n-ne STO "E1IM
a7 MIEM “"RE1"=22 RCL"M

32 ROL+ "a"
48 RECL+ "RE1"
41 =TO "R2"

42 YIEW "R2"
4=z GTO "=t

44 EHD

Assigning a Program to the CUSTOM Menu
When you created the global label Q3 in program line 06, that label was
automatically placed in the HP-42S program catalog. You can now execute Q3 by pressing
XEQ

Lz(requiring a minimum of two keystrokes, depending on where label@2 1sin the program catalog).

Alternately, you can assign Q3 to the CUSTOM menu by pressing

M(ASSIGN] FGHM

RE

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.

2: Enhancing HP-41 Programs

73

Example: Executing an Enhanced HP-41 Program from the
CUSTOM Menu.
Part 1. Execute Q3 from the CUSTOM menu to find the roots of theequationx2+46x +1=0(a =1,b =6,c =1)
Assign Q3 to the CUSTOM menu using the keystroke sequence justdescribed. If you wantto print the results, execute PRON.Start the program from the CUSTOM menu.

(B[PRINT] (A]“an)BCUSTOM) &g3%: 0.0000
TIN ..

IRI— 5.8284
6 |B|€||1|

e r_T_'I I

E_nc)_;

Enter the values for a, b, and c. Then calculate R1. (If you are printing theresults, you won’t see this display.)

R1 is calculated and displayed. Now check R2.

2

R2=-8.1716
T CE OD N.

5Return to the start of the program for new data.

74

x: -8.1716

a& ¢1]

2: Enhancing HP-41 Programs

Part 2. Find the complex roots of the equation

2x2+x +3=0(a =2,b =1,c =3)
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 thisdisplay.)

B(MODES] RECTY

E =-0.2500 -i1.1990(oeT¢l1[

1. B

3g

[R/S)
R1 is calculated and displayed. Now check R2.
R/S

R2=-0.25808 il1.1990&|&|¢|11|

Exit from Q3.
[EXIT]

v: -8.2508 -11.1998
x: -0.2508 i1.19906

i=x]

LEL "@SHORT"

26-Bute PramL

X
ENTER
EMTER

L HtE
RCL- ST T
SORTsTO+ ST 2

ke
Pt

e
oD

AIT
00 g

i
T

otT
LN

i
e

o v
OO

+

[acx]
—

A Short Quadratic Program. In conclusion, here is an 11-line, 26byte quadratic equation solver.

EHD

2: Enhancing HP-41 Programs75

To use QSHORT:

1. Set the calculator to Rectangular mode and to Complex Resultsmode.
2. Key in the value £ then press [ENTER].
a
3. Key in the value b .

a

4. Press

76

QEHO.

2: Enhancing HP-41 Programs

The Solver
The material in this chapter builds on concepts introduced to you inchapter 12 of your owner’s manual.
The following topics are covered:m Basic use ofthe Solver.
m Providing initial guesses for the Solver.
m Emulating the Solver.
m Using the Solver in programs.
m More on how the Solver works.

Basic Use of the Solver
The general procedure for executing the Solveris:
1. Create a program that:a. Uses MVARto define the variable(s) in the equation.
b. Expresses the equation such thatits right side equals 0. (Notethat each variable in the equation must be recalled to the Xregister.)
2. Apply the Solver to the program:a. Press M(SOLVER],
b. Select the program by pressing the corresponding menu key.
c. Enter the value for each known variable by keying in thevalue, then pressing the corresponding menu key.
d. Optional: Supply one or two guesses for the unknown variableby keying in the guess(es), then pressing the corresponding
menu key.
3: The Solver77

e. Find the value of the unknown variable by pressing thecorresponding menu key.
Example: Basic Use of the Solver. The equation ofstate for an
ideal gasis
PV =nRT

where:

P is the pressure of the gas (in atmospheres).
V is the volume of the gas (in liters).
n is the weight of the gas (in moles).
R is the universal gas constant (0.082057 liter-atmosphere/Kelvin-mole).
T is the temperature of the gas (in Kelvins).
Part 1. Create a program for the Solver that declares the variables andexpresses the equation.
First, set the right side of the equation equalto 0.
PV -nRT =0

Now write the program.
Program:
BE C

Comments:

42-Bute Pram

@1 LEL "GAS"
gz MVAR "PME1 :E:

I-,'I I'."HF:

11 |..II 1

B3 MVARE"nLines 02-05: Declare the variables.

B3 MVAR T

A& RCL "R
BY RCLx= "y
B2

RECL

"m

B3 RCLx "T"
18 8,832a857v
11=

12 1= EHD

78

3: The Solver

Lines 06— 12: Express the equationsuch thatits right side equals 0.

Part 2. Use the Solverto find the solution to the following problem.
Calculate the pressure exerted by .305 mole of oxygen in .950 liter at
150 °C (423 K), assuming ideal gas behavior.
Select the Solver application.

B(SOLVER]

Select Solve Program
TN I I DD

Select the program you just created.
GRS

x: B.8800
p v N7|

Enter the values for the variables you know.
T=423. 08080
I TT I

Solve for the pressure.
sP=11.1438
I I TOPart 3. Given the same volume and weight of oxygen, whatis the temperature 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.

15 F

P=15.08600
PvNT[|

Now solve for the temperature.
T

T=569.3763
p v N7 1 |Exit from the Solver application.
EXIT]

[EXIT

v: 969.3763
x: 969.3763

3: The Solver

79

Providing Initial Guesses for the Solver
For certain functions, it helps to provide one or two initial guesses for the
unknown variable. This can speed up the calculation, direct the Solver to arealistic solution, and find more than one solution,if appropriate.

Directing the Solver to a Realistic Solution
Often, the Solver equation that describes a system may have solution(s)that are mathematically valid but that do not have physical significance.
In these cases, it may be necessary to direct the Solver to the realistic
solution by providing appropriateinitial guesses.
Example: Directing the Solver to a Realistic Solution. The
volume of the frustum ofa right circular cone is found by

V= %wh(a"’ +ab +b?)
where:

V is the volume ofthe frustum.
h is the height of the frustum.
a is the radius at the top of the frustum.
b is the radius at the base ofthe frustum.

80

3: The Solver

Part 1. Write a Solver program that declares the variables and expresses
the equation such thatits right side equals 0.
45-Byte Pram *LEBL

MYAR "yMYAR "h"MYAR "3
MYAR “b"T=

N f WM

#1
=23 S

g8 {

By
B2
@9
18
11
12
12
14
153
e
17

"COHE"RCL "a"wt2
LASTX
RCLx "b"+RCL "b"K2+
RCLx "h"
PI
x
3

18 +

19 RCL- "W\"
28 EHWD

For the purposes ofthis example, assume that you have already createdvariable @ and used it in a previous program. Assume that the value—3.7765 is currently stored in a (Go ahead now and store that value in aby pressing 3.7765)

3: The Solver81Part 2. For a frustum of volume V' = 119.381 meters®, heighth = 6
meters, and radius b at the base of the cone = 3 meters, use the Solver tofind radius a .

Select the Solver application and then program CONE.
B(SOLVER) (COHE:

X: =3. (69vHAE||

Enter the values for the known variables.
119.3816b=3. 086808
vHsB||

Solve for a.
.{:Ii':f.;:..: M

a=-5.8000

TTIN.

The Solver uses the current value ofvariable @ (—3.7765) as an initial
guess and finds the solution @ = -5 meters. The answer is mathematicallyvalid. However, a negative radius clearly has no physicalsignificance. Try
guesses of 0 and 5.
a=2. 800¢ H aB||The value 2.0000 meters for radius a is mathematically valid and has physical significance.

EXIT)

[EXIT

82

3: The Solver

X=<

Exit from the Solver.
: 2.00800: 2. 0800

Finding More Than One Solution
The equation of motion for an object experiencing constant acceleration
due to gravity 1s

Y =Yotvol + %gtz
where:y is the total displacement.
Yo 1s the initial position.
Vv, 1s the initial velocity.
g is the acceleration due to gravity (- 9.8 meters/second?).
t is the time.
In your owner’s manualin section "More Solver Examples" in chapter 12,
you solved several problems in which an object was dropped from an initial position; v, was equal to 0 and the direction of the object’s motion was
down at all times. The object attained a given displacement y at only one
time t. However, an object thrown upwards attains a given displacement y
at two different times—once on the way up, and again on the way down.

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.
Example: Using the Solver to Find Two Real Solutions. A boy
throws a ball with an initial vertical velocity v, = 15 meters/second, froman initial height y, = 2 meters. Use the Solver to find the two times¢, andt> when the ball has a height y = 5 meters.
Part 1. Create a Solver program that declares the variables and expresses
the equation such that its right side equals 0.

B3 { S3-Bute From 3@1 LEL "MOTION"
B2 MYAR "yA3 MYAR "y@"B4 MYAR "u@"85 MYARA "t
BE RCL "g@"a7 RCL "w@"
B2 RCLx "t@3 RCL "t"
18 K2
11 -9.8
12 x
13 2
14 +
15 +
e +

17 RCL- "y
12 EMD84

3: The Solver

Part 2. Execute the Solver to find the first time ¢, . Since you know that
this time is close to 0 seconds, provide initial guesses of 0 and 1.
Select the Solver application and then program MOTION.

B(SOLVER] MOTIOEnter the values for the known variables.

vB=15. 0000
ITTAI

Solve for time ¢; using initial guesses of 0 and 1.
t=0.2151[yTwe[ww|1T[1The Solver finds the value of t; = 0.2151 seconds. Now find the second
time ¢, by providing two initial guesses that you can expect to bound thesecond solution. Guesses of 1 and 20 seem reasonable. (You need notenter values for the other variables since they have not changed.)
t=2.8461
vvowo v1|

The Solver finds the value of ¢, = 2.8461 seconds.
Exit from the Solver.
EXIT)

[EXIT

3: The Solver

85

Emulating the Solver in a Program
For certain types of functions, the Solver algorithm cannot find solutions.
For example, the Solver cannot solve for complex numbers. However, forsuch functions, you can write a program that finds explicit solutions andacts like the Solver during program execution.
First, consider the following simple circuit.

=lllll-i-mM)

Ohm’s law defines the relationship between the voltage potential E, resistance R, and current / for this circuit as
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

Example: Using the Solver for a Simple Resistive Circuit. Fora simple resistive circuit, use the Solver to find the resistance R when thevoltage E = 10 V, and the current = 5 A.
First, create a Solver program that declares the variables and expresses
the Ohm’s law equation such thatits right side equals 0.
aa £ 29-Bute Pram
81 LEL "CIRCUIT"
A2

MVYAR

"E

#2

MVYAR

"I

34

MVYAR

“R"

a5

RCL

He

RCLx

X

"I
"R

a7 RCL- "E"
82 EHD

Select the Solver application and then program CIRCUIT.

B(SOLVER] CIRCU%: 8. 0000

Enter the known values for E and 7, then solve for R.
R=2.00080
ITAD

Exit from the Solver application.
([EXIT] (EXIT]

Y: 2.0000
x: 2.00008

3: The Solver

87Now consider the following circuit.
R

W
T~ €

Application of Ohm’s law to this circuit results in the following expression.
E=1Z
where:
E is the circuit voltage.
I is the circuit current.
Z is the circuit impedance.

]

The impedance Z is the complex number (in rectangular form)

where:

R is the circuit resistance.
w is the circuit frequency (in radians/second).
C is the circuit capacitance.
Because the voltage, current, and impedance are complex numbers, you
cannot use the Solver to find their values. However, the HP-42S can perform arithmetic operations on complex numbers. (Refer to chapter 6 inyour 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. (Refer to the section "Using a Variable Menu"
in chapter 9 of your owner’s manual for a discussion of variable menus.)88

3: The Solver

Here is an annotated listing of the program.

o’

Pt

L

Comments:

9e-Bute Pram

LEL

"EIZ"

r,‘l.l.IHE:

n E£ "

MYAR "<
MYAR "Z&"VARMEMU "EIZ"T- FOLARCPHEES
CLA= T
o=0 03 =)
M

=

o

150
Nofe 00 0=

A-

Program:

STOF

ALEHG
n=at

z GTO "EIZ"

12 ASTO ST =14 HER IHD ST =15 STO IHD ST Y%

16 YIEW IHMHD ST %17 GTO "EIZ"

Lines 02-05: Declare variables E, I,
and Z and build the variable menu.

Lines 06 —12: Setthe calculator to
Polar mode and to calculate complex
results. Suspend program execution
for data entry. If a variable to solve forhas not been specified, return to thestart of the program.
Lines 13- 17: Recall the current Alphastring to the X-register and executethe corresponding subroutine. (Thecurrent Alpha string is the name ofthe variable for which no value is supplied.) Store the calculated result fromthe subroutine in the Y-register andview the result. Then return to thestart of the program.

LBL "E&L"
RCL "I&"RCL= "ZaM
ETH

Subroutine E X, lines 18 —21: Calculate EX. in terms of /X and RAX..

22 LBL "I&M

Subroutine 1.4, lines 22-25: Calculate /X interms of EX and Z X..

12
1%
o8
21

22 RCL“"EZM

24 RCL+ "Z4"25 RTH

3: The Solver

89

26 LBL "Z2&"27 RCL "E&

28 RCL+ "I4"

Subroutine Z X, lines 26 —-29: Calculate ZX interms of EX. and IX..

29 ETH
28 EHD(Line 06 sets the calculator to Polar mode. Multimeterstypically display
complex voltage, current, and impedance values in polar form, that is, as amagnitude and phase angle.)
Example: Calculating Complex Values In an RC Circuit. A
10-volt power supply at phase angle 0° drives an RC circuit at a frequencyof 40 radians per second. A current of .37 A at phase angle 68° is measured. Whatis the resistance of the circuit? What is the capacitance of thecircuit?

Begin program EIZ.

sE1Z

x: 8.080008
E& 14 24|2|

Enter the known value for the voltage.

10 [ENTER] 0 B(COMPLEX

E<=10.08000 <0.0000
I N Y.

Enter the known value for the current.

.37 [ENTER] 68 M[COMPLEX

1£=0.37880 £68.0000
E& 142|| |Solve for the impedance.
Z24=27.0278 £-68.0000
E<L12 |||

90

3: The Solver

The impedance ofthe circuit (in polar form) is 27 Q at phase angle —68°.
Convert the impedance to rectangular form to find the circuit resistanceand capacitance. (Remember,R is the real term and C is one factor in theimaginary term ofthe rectangular form of the impedance Z.)%[MODES] :RECT

x: 10, 1245 -129.0590
Immm———lThe circuit resistance is 10 €. Now calculate the capacitance.

40 [xJBMOPFCN] 1/

X: 8.0010

E< 1a Leal 1

1

The circuit capacitance is .001 F.
If, at the original input voltage, the impedance is now varied and measures
20 2 at phase angle —45°, whatis the current?
Return to polar mode. Then enter the new value for the impedance andsolve for the current.

B(MODES] FOLAR
45
20
BM(COMPLEX]

1<=0.5000 £45.0000
Im——-lol

The current is 0.5 A at phase angle 45°.
Exit from EIZ.
EXIT

v: "IL"
x: 8.5008 <£45.0000

3: The Solver91Using the Solver in Programs

Using the Solver and Explicit Solutions in a
Program
The Solver uses an iterative method to find solutions for the variables inan equation. You rmust use an iterative method to find the solution for avariable that cannot be isolated (cannot be expressed uniquely in terms of
the other variables in the equation). However,in cases where theunknown variable can be isolated by algebraic manipulation, an explicit
solution for that variable is always faster than an iterative solution using
the Solver.
Some functions may contain a variable whose value must be found iteratively, and other variables whose values can be calculated explicitly. In
your owner’s manual, in the section "More Solver Examples” in chapter
12, you worked an example in which the Solver was used to find the solutions to time-value-of-money (TVM) problems. The TVM equation is.

= -PV + (1 +ip) PMT

1'!1+i!—Ni-\+FV (1 +1i)-Nwhere:

N is the number of compounding periods or payments.
i is the decimal form of the periodic interestrate.
PV is the present value. (This can also be an initial cash flow or the
discounted value of a series of future cash flows.) PV always
occurs at the beginning ofthe first period.
PMT is the periodic payment.
FV is the future value. (This can also be a final cash flow or thecompounded value of a series of cash flows.) It always occurs at
the end N* period.
p is the payment timing. Ifp = 1, payments occur at the beginningof the period. Ifp = 0, payments occur at the end of the period.

92

3: The SolverIn the example in your owner’s manual, you wrote a program TVM thatdeclares 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 isolated. For example, PV can be expressed as

PV = -1 +ip)pmr |1

-

-\

H!

-N

] -Fv(a+i)™¥l

Only the variable i cannot be isolated; you need to use the Solver only
when you wantto find the value of i.
The following program, TVM2, calculates the solutions to PV, N, FV, andPMTexplicitly, and calls the Solver to find the solution for i. The program uses a programmable menu and flag 22, the Numeric Data Input
flag, to simulate the external appearance of the Solver application.
To key in TVM2: Create variables P/YR, p, CNTRL, N, FV, MODE,
PMT,i, I%YR, and PV.

Here is an annotated listing.
Program:Comments:

aa L 53zZ-Bute FPram >@1 LEL "TWM2"@2 FREALRES

Lines 02— 15: Ensure results are realaz CF 21
a4 12
a5 SF 25
& RCL "PoYR"
a7 HER 21
B2 SF 25
@3 RCL "p"numbers. Display AVIEW messages
and continue program execution. Callsubroutine 21 to set the default payments per year to 12. Set the default
payment mode to End mode. Call subroutine 20 to display the payments per
year and the payment mode.

18 CF 25

11
12
=
14

1
H=y'?
0
STO "p*

15 HER 20

3: The Solver

9316 LBL 29

Lines 16 —35: Build the main menu,

17 CLMEHU
13 "H"
19 KEY 1 XKER® a1

display it, and wait for data input(lines 17-31). Display the value of theentered or calculated variable (lines

z2a "IXYR"
21 KEY 2 HKERQ B2

32-34).

zz "Ry22 EEY 2 HEQ @3

24 "PMT"23 KEY 4 RER 84

26 FY

03
o=

03
0

Moo
w0 00

27 EEY S HKER @5"MODES"
KEY & GTO 88
MEHLI

STOF

HIF

Q0
=)
Fa
T
o
o=
Fooo
o

1=
44
453
4
47
42

94

2

display the payments-per-year andpayment-mode message.

0

Subroutine 20, lines 36— 48: Build and

CLA
RCL "FoYE"i

LEL 2603
00

GTO 29

00
o0

030
nof

00
Mg

H=TO "CHTREL"
22 STO IMD "CHTEL"=4VIEM IMD "CHTEL"

Ft PR
RCL “p"n=aT"
EHD MODE"==a7
K"
EBEGIH MODE"
AVIEW
CLMEHLETH

3: The Solver

l':Il.l'.'..
T CnCnoCn Cno
nNoon on i
w0
= 0 o0 00 =] M on Ou NI I ke
fod

T

T
T

KEY 1 HER 21"BEG"
KEY 2 HER 22"EMD"
KEY 2 HER 23
TN
KEY 4 GTO "TwmMz"
MEMU
RCL "PrYR"STOF

GTO &6
Subroutine 21, lines 63— 73: Check if

T B 0|_'_|".

n F."’,l.l"F-: "Lines 49 -62: Build and display thepayments-per-year and payment-modemenu.

the specified number of payments per
year is valid. If not, substitute 12 payments per year.

STO "FoYR"

n Ja

P-

o0 =]
— w0

=)
00

= =
=4
-

Subroutine 22, lines 74-77: Set payment mode to Begin by supplying 1 for

I_T'l

=]
03

=] =]
oo

=] IJ'l
o0

Iy
00 )

T

LEL @&HER 28Subroutine 23, lines 78 -81: Set payment mode to End by supplying 0 forP

3: The Solver

95

s
s
e

3 PO ISs

L)

w00 W00.ﬂ

JyioooW0

WO 00 00 00 QO 00 0D 00: 0O== 2R 2 D 0 N R WMo 3000 IRY

Pt

LEL &1

Subroutine 01, lines 82-107: If"M
FS?C 22RETH
1
STO "H"numeric input is made for N,return tothe main menu and display the valueof N. If not, calculate N in terms of
the other variables. If i = 0, go to label
00 to calculate N (lines 93-95).

“EQ 18
RCL "FW"
RCL+ "MODE"+/=
RCL "PMT"
RCL "i1"=87
GTO aa+LASTY
RCL "PY"
RCL+ "MODE"
+

LH
RCL

" 1 "

=J

T

ot
[xn]

RTH

b ek ek b s= %— . e hone’
03 o= I3 W0 00

e

—n

i

185 LH1+x

LEL @@

96

3: The Solver

RCL "PY"
RCL+ "FY"
RCL+ "FMT"+/ETHLines 108 - 113: Calculate N if i is 0.

114 LEL &2
115 "IEYR"
11e FS7C 22
117 RTH
112 PGMSLY "i"
119 %)
I

03 e
NoF o

ek
b
ek
ek
ek
ek
b
Pt
ek

)
00

ek

=

W0

O

o0
T

00

ek
ek
ek
b
ek
b

-

£ o0

00D
=]

ek

G o PO D D PO T
™ oo -] i[—y (]
T N b

—
M

M

—

128

STO " I%YR"
26
SOLVE "I%YR"
RTH
LEL "i"
KEG 16RCLx "PHT"
KO

Solver to calculate I1%YR. Specify the
Solver subroutine "i". Supply initial
guesses of 0 and 20 for I%YR.

Subroutine "i", lines 124-131: Express
the TVM cquation for the Solver.

RCL:x "Fy™
+

RCL+ "FY"FETH

LEL 82n Fll'l" 1

FS?C 22
RTH#ER 18RCLx "PMT"

Subroutine 03, lines 132-142: If
numeric input is made for PV returnto the main menu and display thevalue of PVIf not, calculate PV interms of the other variables.

nory
RCL= “Fy"
+
+=

[

z RTH
143 LEL B4
144 "PMT
145 FS?C 22
145 RTH147 HEQ 1@
148—

Subroutine 02, lines 114-123: Use theSubroutine 04, lines 143 -154: If

numeric input is made for PMT,
return to the main menu and display
the value of PMT. If not, calculate

PMT in terms of the other variables.

LYV S
S

3: The Solver

97

ek
ek
ek
ek
ek
Pk
ek
ek
ok
ek
ek
ek

TN onoon on onooan oon onoCn b
00 -] Ton
S 00 T e w0
0oo0

T
T

00

ek
b

o=

b

T
T

ek

O

T

Pk
e

" F"." nFS?C 22
RTH
HER 18
RCL "PHT"
ROL+ "Fy<>ySubroutine 05, lines 155-165: If
numeric input is made for FV, returnto the main menu and display thevalue of FV. If not, calculate FV interms of the other variables.

+. =
FTH

0]

ek

LEL &5Tek

ETH

on the value of 1%YR. Calculate i; the

T

ek
ek
ek
ek

+ .-"- -FCL+£ 00 Mg e oun 0O =) T

b

RO

"FW"
n F'I'.'l nlate terms of the TVM equation basedo s] =]

ke

=)
=)

T

n

b

F‘EL+

LEL 1@RCL "IxvR"

ek
ek
ek

e

ke
P

oL

O

—

o000
-~
ike

=) =)
oD

P

RCLx

98

136

"P-YRE"

Subroutine 10, lines 166 —188: Calcu-

STO Uitdecimal form of the periodic interest
rate (lines 167-171). Calculate
MODE (1 + ip) (lines 172-175). Cal-

RECL=

culate the FV coefficient (1 + i )™V

“"p"

1
+
STO "MODE"
1
EMTER
RCL+ "i®
RCL "M
+.=

LR
STo

FCL=

=T

2

"MODE"SF 25
RCL+ "iv

3: The Solver(lines 176 - 182). Calculate the PMT
cocfficient. If i = 0, go to line 189(lines 183 -188).

wn]
=)

—

Do
oo

FETH

e
L oo
LoD
1 o

FS?C 25

1
RCL "H"
EHD

Lines 189-191: If i = 0, then the FV
coefficient is 1 and the PMT
coefficient is N.

To use TVM2:

Press

TWHME .

Supply values for the known variables. For example, press 60. H.
Solve for the unknown variable by pressing the corresponding menu
key.
TVM2 uses the variable /%YR to prompt for and display theinterest rate. /%YR is the percent form of the annualized interest
rate.

The default payment period is one month (12 payments per year).
The default payment timing is the end of each period. To specify adifferent payment period or payment timing, first select the MODE
menu. Then, for example, to specify six payments per year, press 6

AR

To specify payment timing at the beginning of each period, press

BEG .
To return to the main menu, press

T4HM .

Example: Executing Algebraic Solutions for TVM Problems.
In the section "More Solver Examples" in chapter 12 of your owner’s
manual, Penny of Penny’s Accounting wants to calculate the monthly payment PMT for a 3-year loan financed at a 10.5% annualinterest rate,compounded monthly. The loan amountis $5,750.
In that example, you executed the program TVM to calculate the value
PMT = -186.89. TVM uses the Solver to calculate PMT. The calculation
takes about three seconds with initial guesses of 0 and —500.
Part 1. Use TVM2 to calculate the value of PMT explicitly.

3: The Solver99Set the display format to FIX 2. Then execute TVM2.
FlIx® 2i

12 P/YREND MODE
N _Ji=vR PV PMT] FY [MOCE]Enter the known values.
5750 F10.5

Fv=0.80
N Ji=vRPY PHT FY[HODE]

spyre

PHT=- 186,69

N[ =RPY PMT FY|MODE]

The explicitly calculated value is —186.89 (the same as when you usedTVM) and the calculation takes less than one second. Also note that thecalculation 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.)
Part 2. Another bank has offered to loan Penny’s customer $5,750, to be

paid in monthly installments of $200. Whatinterest rate is this bankcharging?
1%YR=15.24
TNTTNTS200

TVM uses the Solver to 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.
Exit from TVM2 and return the display format to FIX 4.

EXIT

v 15.2393

BDisP)

100

4

3: The Solver

x: 15,2393

Using the SOLVE and PGMSLYV Functions with
Indirect Addresses
In the previous section, you used the SOLVE function in TVM2 to findthe value of the interest rate i in the TVM equation:

122 SOLVE "IXYR"
You used the PGMSLYVfunction to specify the routine that expresses theTVM equation:
112 PGMsLY "1

In TVM2, the SOLVE and PRGSLYVinstructions directly address the variable and the subroutine. Such use of direct addressing enables you to
specify only one Solver routine and, within that routine, only one variable.
However, the use of indirect addressing expands the utility of the Solver byenabling you to specify any of multiple routines, and any of multiple variables.
Example: Using SOLVE with an Indirect Address. Restating theideal gas equation ofstate:
PV - nRT =0

The "van der Waals" equation ofstate refines the ideal gas equation to[P+ ";;’ ](V—nb) -nRT =0
where a and b are constants characteristic of the gas in question.
Part 1. Write a program that enables you to solve for the value of any ofthe variables using either the ideal gas or van der Waals equation ofstate.

3: The Solver

101Here is a flowchart for the program, named GAS2.
GAS2

4

Y
DECLARE MENUVARIABLESv

DISPLAY VARIABLE MENUFOR DATA INPUT
KEY 1
v IlPIl

iKEYZ

¢KEY3

¢KEY4

iKEYS

IIVII

Hnll

'ITII

“all

KEY 6
V llbll

STORE NAME OFUNKNOWN VARIABLE
FROM ALPHA REGISTERTO VARIABLE CONTROLSPECIFY SOLVER
PROGRAM WAALSSOLVE FORUNKNOWN VARIABLE
i

VIEW SOLUTION
,

WAALS

EXPRESS THE
VAN DER WAALSEQUATION
RTN

102

3: The Solver

Here is an annotated listing of the program.

Program:E”’:“

N

Comments:

15_";‘—E:I=|feo1 LEL "GASz"

F' =g

::

BZ MYAR P
B2

MVYAR

Lines 02 - 08: Build the variable menu.

"y

B4 MYAR “n
B3 MVAE "T™

A& MYAR “a"a7 MYAR b

B2 YARMEMU "GASZ"
a2 CF 2118 EEALEES
11

STOP

12 ASTO "COMTROL"S PGMSLY "WAALS"
14 SOLYE IMD “"COMTROL®
15 VIEW IHD "COMTROL"
16 GTO "GARS2"

17 LEL "MHAALS"
12 RCL P
19 RCL "n"
26 K2
21 RCLx "a"22 ROL "4
23 M2

Lines 09-16: Clear flag 21 to continue
program execution after a VIEW
instruction. Set to calculate real results
only. Display the menu. Store thename of the unknown variable in
CONTROL (line 12). Specify Solver
routine WAALS (line 13). Indirectly
specify the variable to be solved (line14). View the solution and return tolabel GAS2 (lines 15-16).
Lines 17-34, the Solver routine

WAALS: Express the van der Waals
equation such that its right side equals
0.

o o
=)

"y

FCL

"B

FECL=

"h"

|

03 O
o0

FCL

o
0

25 +

3: The Solver1031 B.82z2857
RCLx

"m"

22 RCLx

"T"

=2

24 -

35 EHDPart 2. Use the van der Waals equation of state to calculate the pressure
exerted by 0.250 mole of carbon dioxide in 0.275 liter at 373 K, and compare this value with the value expected for an ideal gas. For CO,,a = 3.59 liters? - atmosphere/mole?, and b = 0.0427 liter/mole.
Execute GAS2.

GR=Z

x: @. 0000

T T.

Enter the values for the known variables.
b=0.06427¢
I U TO R

0427B
Enter guesses of 10 and 30 for P, and solve for P.
10F
30 g

P=25.9816
Ill]lllﬂllﬁﬂlll]lIlﬂlll!lUsing the van der Waals equation of state, the predicted pressure is
25.9816 atmospheres.
Now use the ideal gas equation to predict the pressure. Simply supply thevalue 0 for @ and b and solve for P. The previously calculated value for P
serves as an initial guess.
0 H
B
0O

104

3: The Solver

P=27.8248[P]v|N1T|A|E|

The ideal gas equation predicts a pressure of 27.8248 atmospheres. (Theactual observed pressure is 26.1 atmospheres.)Exit from GAS2.
EXIT

v: 2

X: 2

More on How the Solver Works

The Root(s) of a Function
To use the Solver, you have learned that you first create a program that
expresses the equation such thatits right side equals 0 (by subtracting theterms on the right side from both sides of the equation). If the equation
has more than one variable, you must, after selecting the Solver application, supply values for all but the one unknown variable. At this point,
your equation has taken the form f(x) = 0, where x is the unknown variable, and f(x) is a mathematical shorthand for the function that defines x.
Consider the equation
2x2+xy + 10 =3xz + 2z
Setting the equation equal to 0 by subtracting the terms on the right sidefrom both sides gives
2x%2+xy +10 -3xz -2z =0
To use the Solver, you now write a program that declares the variables x,¥, and z and expresses the equation. When you sclect the Solver application and, for example, supply the value 2 for y, and 3 for z, by substitution
the equation becomes
2x2-7x -2=0

where x is the unknown variable and f(x) = 2x2 - 7x — 2. Each value x
for which f(x) = 01is called a root of the function. The Solver iteratively

3: The Solver105seeks a root for f(x) by evaluating the function repeatedly at estimates ofx, and comparing the results to previous estimates. Using a complex algorithm, the Solver intelligently "predicts" a new estimate of where the graphoff(x) might cross the x-axis. Here is a graph of the function
f(x) = 2x2 - Tx - 2. The graph shows two roots. (The example on pages
110-112 calculates these roots.)f(x)AAll except one of the functions in the examplesin this section are functions of one variable x only. Remember, though, that the situations
described in the examples apply equally to multivariable functions,sincemultivariable functions become single variable functions when,in the
Solver application, you supply values for the known variables.

106

3: The Solver

The Solver’s Ability to Find a Root
For the Solverto find a root, the root has to exist within the range of
numbers of the calculator, and the function must be mathematicallydefined where the iterative search occurs. The Solver always finds a root
if one or more of the following conditions is met:m Two estimates yield f(x) values with opposite signs, and the function’sgraph crosses the x-axis in at least one place between those estimates(figure 3-1a).
m 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).
m 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)

f(x)

|

B

T
f(x)

y

N/

Voo

Figure 3-1. Functions for Which a Root Can Be Found

3: The Solver107

In most situations, the calculated root is an accurate estimate of thetheoretical, infinitely precise root of the function. An ideal solution is one
for which f(x) exactly equals 0. However, a nonzero value for f(x) is often
also acceptable, because it results from approximating the root with limited (12-digit) precision.

Interpreting the Results of the Solver
The Solver returns datato the stack registers on completion ofits iterative
search for a root of the specified function, and in four conditions, returns
a message to the display. These messages and data can help you interpretthe results of the search:m The X-register contains the best guess. This guess may or may not bea root of the function.
m The Y-register contains the previous guess.
m The Z-register contains the value of the function f(x) evaluated at thebest 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 thecurrent display mode;in FIX 4, code 0 is displayed as @.@33a.).

108

3: The SolverCode inT-register0
1

Interpretation
The Solver has found a root.

The Solver has generated a sign
reversal in f(x) at neighboringvalues of x, but f(x) has beenstrongly diverging from 0 as x
approaches the two neighbors
from both sides.
The Solver has found an approximation to a local minimum or
maximum of the numerical absolute value. If the solution is

Extremum+9.999999999999 x 10%%, itcorresponds to an asymptotic
extremum.
One or both initial guesseslie outside the domain of f(x). Thatis,f(x) returns an error whenevaluated at the guess points.
f(x) returns the same value atevery point evaluated by the
Solver.

Bad Guessi{es)Constant?

When a Root Is Found. There are two cases in which a root is found:m In case 1, the calculated root sets f(x) exactly equal to 0 (figure 3-2a).
m In case 2, the calculated root does not set f(x) exactly equal to 0, but isa 12-digit number adjacent to the place where the function’s graphcrosses the x-axis (figure 3-2b). This occurs when the final two estimates are neighbors (they differ by 1 in the 12th digit) and f(x) is positive for one estimate and negative for the other. In mostcases, f(x)will be relatively close to 0.

3: The Solver

109

f(x)

f(x)

/

/

o

a

>X

b

Figure 3-2. Case When A Root Is FoundIn both cases, the code in the T-register is a 0 and no message isdisplayed. You can differentiate between the two cases by:m Viewing the contents of the Z-register (the value off(x) at the calculated root). For a case 2 solution, it will be a nonzero number.
m Comparing the best guess (the contents of the X-register) and theprevious guess (the contents of the Y-register). For a case 2 solution,
the guesses differ by 1 in the 12th digit.
m Immediately solving again for the variable. For a case 2 solution, theSolver will return the message Zian Eewersal on the second
attemptto find the root.
Example: A Case 1 Solution with Two Roots. Find the two rootsof the equation
2x2-7x -2=0

- .._.,_ol 1). o= 2.
o o 3Express the function in program AA.

110+ 25-Bute Fram
LEL "HA"FMWHRE "=t
FCL Met3: The Solver

-

-

I

1

O
I

|
|

3

— S
v o0 00 )Set the display format to ALL. Select the Solver application and then program AA.

BDIsP])AL L

B(SOLVER
AR

%: B

BIN .

Enter guesses of 1 and 5 for x. Solve for x.
10 A&rX=3., 76556443708
II RIR

Roll the stack contents down to see the previous guess.
X: 3. 76556443708
IIIIS
The estimates are the same in all 11 decimal places. Roll the stack contents down to see the value off(x) at the root.
x: 8
III

f(x) 1s exactly 0. Now enter guesses of —0.1 and -1 for the second rootand solve.
1oA

X=-2.65564437075E- 1
IlﬂlllllllllllllllllllllJ

3: The Solver

111

Roll the stack contents down to see the value off(x) at the root. Again,f(x) is exactly 0.

x: 8
Ce|[1||
Exit from the Solver and return the display format to FIX 4.

BDisP] :4v 0.0000

x: 9. 0000

Example: A Case 2 Solution. In the example on pages 101-105 inthis chapter, you found the value of the pressure P in the ideal gas equation ofstate given values for the other variables V, n, and T.

Using the same values for the variables V, n, and T, solve again for P.
Set the display format to ALL.
Select Solve Program[T I I I I .

Start program GAS2. (Reenter the program if you have cleared it fromthe calculator.)
X: @|ﬂ“l§..§l“|Enter the values for the known variables and solve for the pressure.
P=27.8247827273(P|¥|N|7|#|E]

Roll the stack down to see the previous estimate.
X: 27.8247827272
P ¢N7T &B

112

3: The Solver

The estimatesdiffer by 1 in the last decimalplace. Roll the stack down to
see the value off(x).
x: 8. 08080080001
P vNTfE

The value off(x) at the rootis a very small nonzero number. The rootis
not an exact root, but it is a very good approximation. Exit from the program and return the display format to FIX 4.

EXIT
BDISP] FI#¥ 0.0000
x: 1.0000E-11

4 (ENTER

Problems That Require Special Consideration. Some types ofproblems require special consideration. The following function has a
discontinuity that crosses the x-axis.

1T~

>x

The Solver will return an x-value adjacent to the discontinuity. The value
off(x) may be relatively large.

3: The Solver

113

Example: A Discontinuous Function. Find the root of the equation
IP(x) -15=0
Express the function in program BB.
B8 {12-Byte Pram2

3o 00 M
N
I-T'I
.
=J

=

=

@1 LEL "EB"MVAR "RRCL "X"IF
1.5
EHD

Select the Solver, select program BB, provide guesses of 0 and 5, andsolve for x.
B(SOLVER] iEE

X=2.0000The Solver finds a root at x = 2.0000. Now check the value off(x).

%: -8, 5000
TINNN
The value off(x) seems relatively large. This indicates that you should
further evaluate the function. By plotting the function, you find that theroot atx = 2.0000 is in fact a discontinuity, and not a true zero crossing.
Exit from the Solver.

EXIT) [EXIT

v 0
X -

Finally, consider the following function. This function has a very steep
slope in the area of the root. Evaluation of the function at either neighbormay return a very large value even though the function has a true root
between the neighbors.

114

3: The Solver

fx)

>X

Use care in interpreting the results of the Solver. The Solver is mosteffective when used in conjunction with your own analysis of the function
you are evaluating.
A Sign Reversal. The values ofthe following function are approaching
infinity at the location x, where the graph changes sign.

/—_———— e e — -f(x)AThe function has a pole at x,. When the Solver evaluates such a function,
it returns the message Sian REewver=zal.

3: The Solver

115

Example: A Pole. Find the root of the equation_x(x* - 6)
As x approaches Ve, f(x) becomes a very large positive or negative
number.

£ 23-Bute Pram

LEL "CC"
MVAR "RRCL "R"
RCL "=R"
IJ'I

WA

—

— = T
—W0

T
00

T
s
=) T

[I

.
u
I T I IN e 00 O e 1=

Express the function in program CC.

EHD

Select the Solver and then select program CC.
B(SOLVER]ix: 0. 0000
INIIN

Provide guesses of 2.3 and 2.7, and solve forx.

23¥
27

116

3: The Solver%=2.4495

Sign Reversal

The initial guesses yielded opposite signs for f(x). The interval between
successive estimates was then narrowed until two neighbors were found.
These neighbors made f(x) approach a pole instead of the x-axis. The
function does have roots at —2 and 3, which can be found by entering
better guesses.
Exit from the Solver.
EXIT]

[EXIT

An Extremum. When the Solver returns the message E:xtremum, it
has found an approximation to a local minimum or maximum of thenumerical absolute value of the function. If the solution (the value in the

X-register) is +/— 9.99999999999 x 10%%, the Solver has found an asympfotic extremum.
f(x)

A

N\
Relative minimum

Asymptote»X

Relative maximum

3: The Solver

117

Example: A Relative Minimum. Find the solution of the parabolic
equationx2-6c+13=0(It has a minimum atx = 3.)+

23-Bute Pram*

LEL "DD"
MYAR "=

]

AT

"="

—

W

-

RECL

+

= M
o0

T
00

T
=)

T
s N B

I
03 [

.,.
=
—
T
o= 15

Express the function in program DD.

Select the Solver application and then program DD.

B(SOLVER] |x: B, 0000[«11111|

Provide guesses of 0 and 10 and solve for x.
X=3.080080
Ex tremum

Exit from the Solver.

[EXIT] [EXIT)

118

3: The Solver

v: 3.0000

x: 3.00080

Example: An Asymptote. Find the solutions for the equation
1
10 - ==0
X

Express the function in program EE.
88
@1
82
a3
84
83
86
a7y

{ 17-Bute Pram 2
LBL "EE"
MVYAR "R"18
RCL "X"
1-¥
EHND

Select the Solver application and then program EE.

&

x: 0.0000(+1111[Enter guesses of 0.005 and 5, and solve for x.
x=0.1000IETIIRB.

The Solver finds a root at x = 0.1000. Now enter guesses that have negative values.
%=-1.000ODESOD
ExtremumThe Solver finds an asymptotic extremum. (Press Jj[SHOW] to verify thatthe solution is actually —9.99999999999 x 10%%° ) It’s apparent from
inspecting the equation that ifx is a negative number, the smallest thatf(x) can be is 10; f(x) approaches 10 as x becomes a large negative number.
Exit from the Solver.

EXIT) [EXIT]

v: -5.9246E498

x: -1.0000E500

3: The Solver

119Bad Guess(es). The Solver returns the message Ead Guess(es)when one or both initial guesseslie outside the domain of the function. (Ifa guesslies outside the domain of the function, the function returns amath error when evaluated at that guess point.)
Example: A Math Error. Find the root of the equationX\/(x vo03) =0
.,_
15!
1
!

2e-Bute Pramo

ROL+ "x"elo— o0 1)
KN] oo-T

N

LEL "FF"
MYAR "R
[
i3

™ T T
oo

£

T
e O3 ol

Express the function in program FF.

SEHET
B.5

EHL

Select the Solver application and then program FF.
B(SOLVER]

FF

x: 0. DPPDTA INFirst attemptto find a positive root, using guesses 0 and 10.
0
100

120

=
=

3: The Solver

x=0.1860[#|1111|

The Solver finds a root at x = 0.1. Now attemptto find a negative root
using guesses of —0.1 and —0.2. Note that the function is undefined forvalues ofx between 0 and —0.3, since those values produce a positive
denominator but a negative numerator, causing a negative square root.
Although the HP-42S can execute arithmetic operations with complex
numbers, the Solver cannot find a complex number solution. If evaluation
off(x) returns a complex number, the Solver considers the function
undefined at that x-value.
A

X=-0, 2000
Bad Guess(es)

2 7]
[*[]
Exit from the Solver.
EXITJ

[EXIT

v: -@. 1080
x: -0.20080

A Constant. The Solver returns the message Constant? when it
finds that f(x) returns the same value at every sample point x. Such asituation can occur if guesses are confined to a local "flat" region of afunction.
Example: A Local Flat Region. Find the root of the equation

1 _10-=0X

17-Bute Fram
LEL "G
MWAR "=
RCL

"=

18

[
A

e

,._
.,_
10 15l
i
T
[
e
™
=] T
e N o 1;_13 [ )Express the function in program GG.

"

EMD

3: The Solver

121Select the Solver and then program GG.
[SOLVER]:GG

x: 8. 00008

E

BDID

Supply guesses of 10% and 10% .
(E] 20

X=1.0000ES08
Constant?

In this region of the function, the value off(x) is, within the 12-digit precision of the calculator, the same at every sample point. Here is a graph ofthe function.

f(x)—Try guesses of 0 and 10.
0

X=0.1000[&11111|_The Solver finds the root atx = 0.1. Exit from the Solver.
EXIT]([EXIT

122

3: The Solver

v: B. 18008
x: 8. 10008

Round-Off Error and Underflow
Round-Off Error. The 12-digit precision ofthe calculator is adequate
for almost all cases. However, round-off errors can sometimes affect

Solver results. For example,[(]x] +1)+10®°P -10¥=0
has no roots because f(x) is always positive. However, given initial guessesof 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 equation|x2-7] =0
has a root at V7 . However, no 12-digit numberexactly equals V7, s0 the
calculator can never make the function equal to 0. Furthermore, the function never changes sign. The Solver returns the message E:xtremum.
However, the final estimate of x is the best possible 12-digit approximation of the root when the routine ends.
Underflow. Underflow can occur when the magnitude of a numberis
smaller than the calculator can represent; in such a case, it will substitutethe number 0. This can affect the Solver’s results. For example, consider
the equation

1
X

2=0

whose root is infinity. Because of underflow, the Solver returns a verylarge (finite) value as a root. (The calculator cannot representinfinity,
anyway.)3: The Solver

123Integration
In this chapter, the following topics are covered:m Basic use of the Integration application.
m Approximating an integral that has an infinite upper or lower limit.
m Using Integration and the Solver interactively.
m More on how Integration works.

Basic Integration
The procedure for execution of the Integration application is:
1. Create a program that:a. Uses MVARto define the variable(s) in the integrand (thefunction to be integrated).
b. Expresses the integrand. (Note that each variable in the
integrand must be recalled to the X-register.)
2. Apply the Integration application to the program.

a. Select the Integration application (press B[/f(x)]).
b. Select the program by pressing the corresponding menu key.
c. Specify the values for any known variablesin the integrand.
Select the variable of integration.
d. Specify the values for LLIM, ULIM, and ACC.
e. Press

124

4: Integration_to begin the calculation.

Example: Basic Integration. The angle oftwist in a round shaft
under torsional loading is calculated by evaluating the following integral.

where:

g is the angle of twist of the shaft (in radians).
L is the length of the shaft (in meters).
T is the torque applied to the shaft (in Newton-meters).
J is the polar moment of inertia of the shaft (in meters*).
G is the shear modulus of the shaft material (in Newtons/meters?).
Torque T increases along
the length of the shaft

as a function of x .

Consider a solid steel shaft (G = 83 x 10° N/m?) that has a constantdiameter of 0.03 meters (J = 7.9521x 10" m*) and a total length L of 2
meters. Find the angle of twist in the shaft when loaded by a torque thatvaries along the length x of the shaft as a function of x:
T =13x* + 8x3 + 15x2+9x + 6
For programming purposes, use Horner’s method to expand the polynomial.
T=(((13x +8)x +15)x +9)x +6

4: Integration

125Substituting this expression for T, the equation becomesP ((1Bx +8)x +15)x +9)x +6 dx
’= !;

JG

Express the integrand in the program TORQUE.

A

el

—

53-Bute FPram

LEL "TORGUE"MVAR "Xr,1 I:||' H F:

1 |_I nr|1 I|'ll HF_:I" I:'I. n

FECLx vz

Lines 02-04: Declare the variables.

s the integrand.

Lines 05-19: Expres

+

RCLx

"e"

15
+

RCLx>

"wn

3
FECL=

"sY

pk
=]

+

ek
00

ECL+

et
o0

RCL+ "G

[
1

m

ek
Iy

bk ek ek ek b b = T T
n Jo O3 O e o0 00— N

=

DRI

Y

L

Comments:

[an
Ju

I

—
1)
Y
il

Program:"d"

Select the Integration application.
B0

Select Sff(x)> Program
TN I AN

Select program TORQUE.
TORR

126

Set Vars; Select Jvar |'N

4: Integration

Supply the known values for J and G, and specify the variable of integration X.
7.9521 [E] 8 [+e|x: 83,6860, 868, 000.0
I
IR YD G N

83 [E]

Specify the lower limit (0), the upper limit L (2), and an accuracy factor of
0.01.

OLLIM

ACC=0.01060(eeijueid]wee||o0

2 UL

Start the calculation.

e

S=0.6281
LLijucif wee| o

The shaft twists through an angle § = 0.0281 radians (1.6077 degrees).
Exit from the Integration application.

v g.ggg?
x:-

Approximating an Integral That Has an
Infinite Limit
It is often ofinterest to evaluate an improper integral (an integral that has
an infinite upper or lower limit). An improper integral with an infinite
upper limit[ o) axo0

is calculated "by hand" by evaluating the equivalent expression

lim,oo [, f0¢) d

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.
Example: Evaluating an Integral That Has an Infinite Upper
Limit. Calculate the integral
©

":’

dx

1+ x2

by hand. Then approximate the integral with the HP-42S.
Part 1. The result is calculated by hand as follows.

° v
l 1+ x2. M, oo o dy

0 1+ x2

lim,_, (arctana)r
2
Use the HP-42S to calculate 7/2 to 12-digit precision.

x: 1.5707963268

B 235

Part 2. Use the Integration application to evaluate the same integral,using the value 1,000 to approximate the upper limit. First, express theintegrand in the program INFIN.
TS
v
150

0o e N B 0 O e

B8 { 28-Bute FPram

128

LEL "IMFIH"
MYAR "\RCL "x"
Atz
1
+

178
EHMD

4: Integration2

Select the Integration application and then program INFIN.
]

IHFIH

Set Vars; Select Jvar
ND D D

Select the variable of integration.
x: 1.5707963268
IlmnﬂlmmﬂlﬂﬁllllllllllllJSpecify the lower limit (0), the upper limit approximation (1,000), and an
accuracy factor of 0.01.
ACC=0.081
NNTN BTI.

Calculate the integral.
F=1.57020935993
TNTTIN
Using an upper limit of 1,000, and an accuracy factor of 0.01, the calculator returns the result 1.57020935993. The calculation takes about 36
seconds and is correct to three decimal places.
Exit from the Integration application and return the display format to FIX
4
EXIT]([EXIT][EXIT

B0DISP) i FI% 4

v: 8.0156

x: 1.5702

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.
FactorULIM

ResultCalc. Time(seconds)( % actual) 1.5707963268
0.01

0.0001100

1.57518831857

5

1,000
10,0001.57020935993
1.57088603739

36
140

100
1,000
10,0001.5607891695
1.566979476064
1.57069673168

18
69
279

Note that the principle determining factor in the accuracy ofthe result isthe value of the upper-limit approximation, not the accuracy factor. Also
note that the calculations using an accuracy factor of 0.0001 require about
twice the time of those using an accuracy factor of 0.01.
In general, when you are approximating an integral, assess the extent towhich you are constraining the accuracy of the true integral with theapproximation ofthe limit, and choose an accuracy factor wisely. If thelimit that you substitute results in only a rough approximation of the true
integral, it makeslittle sense to calculate the approximation to a highdegree of accuracy.

130

4: Integration

Using the Solver and Integration
Interactively
In the first example in this chapter, you found the twist angle 6 at the endof a shaft by integrating the applied torque with respect to x. (The torquevaried as a function of the position x along the shaft.) You were limited, inthat example, to solving specifically for the twist angle 6. In general, forthe equation
ULIM
I = LM f(x) dx (calculated to accuracy ACC)
the Integration application enables you to solve only for the value 7 of theintegral. To solve for 7, you:m Write a program P that defines the integrand f(x).
m Specify values for the known variablesin the integrand.
m Specify the variable of integration.
m Specify values for the variables LLIM, ULIM, and ACC.
However, by writing a program S for the Solver that declares each variable in the equation and invokes the Integration application on program P,
you can solve for any of the variables in the equation:m/

m The variables in the integrand f(x).
m LLIM,ULIM.

In the following example, you’ll solve for the length L of a shaft (the variable ULIM in the Integration application) in the angle-of-twist equation.
Example. Using the Solver and Integration Interactively.
Restating the equation for twist in a shaft under torsional loading:

4: Integration

131

Consider again the solid steel shaft of the first example in this chapter.

Forthis shaft, G = 83 x 10° N/m? andJ = 7.9521 x 10"® m*. The shaft
is subjected to the same torsional loading T asin the first example. That
loading varies along the length x ofthe shaft as a function ofx.
T =13x* + 8x3 + 15x2+ 9x + 6.
Find the length L that resultsin a twist angle 6 of 0.1396 radians (8degrees).
The variables in the equation are , L, T, J, and G. The unknown variable

L is the upper limit ofintegration ULIM.
Part 1. Write a Solver program SHAFT that:m Declares each variable in the equation.
m Expresses the equation such thatits right side equals 0.
LT—dx -0=0
0 JG
Program:Comments:

88 { eB-Bute Pram >@1 LEL"SHAFT"

82 MVYAR “"THETR"
a2 MYAR "G

Lines 02-08: Declare the variables inthe equation.

a4 MYAR "J"
a3 MVAR"LLIM®

@5 MYAR “ULIM"@7 MYAR "ACC"
B2 MYAR "R
8% PGMINT "TORGUE"
18 IHMTEG "=x"11 RCL- "THETR"

Lines 09-11: Express the equationsuch thatits right side equals 0. First,
calculate the first term of the equation(the integral) (lines 09-10). The
value of the integralis returned to theX-register. Subtract the second term

(THETA)(line 11).

12 EHD132

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.
Note that the specified integration program is TORQUE from thefirstexample in the chapter.If you’ve deleted this program, you need to key it
into the calculator now.
Part 2. Select the Solver application and then program SHAFT.
B(SOLVER] SHAFT

x: 8. 0000

TOIT

(The variable X is on the second line of the menu.) Enter values for the
known variables.
.1396 THRACC=0.0100
THETH] G JfLLIMULIM]ACC

7.9521 [E] 8

0.01

Now solve for the upper limit L, providing initial guesses of 1 and 10.
ULIM=2.9528
DOITR

The shaft must be 2.9528 meters long to twist through an angle of 0.1396
radians.
Exit from the Solver application.
EXIT]

[EXIT

4: Integration

133More on How Integration Works

The Accuracy Factor and the Uncertainty ofIntegration
The Integration algorithm calculates the integral of a function f(x) bycomputing a weighted average of the function’s values at many values of x
(sample points) within the interval of integration. The accuracy of theresult depends on the number of sample points considered; generally, themore the sample points, the greater the accuracy. There are two reasons
why you might wantto limit the accuracy of the integral:
1. The length of time to calculate the integral increases as the numberof sample points increases.
2. There are inherent inaccuracies in each calculated value off(x):a. Empirically-derived constants in f(x) may be inaccurate. If, forexample, f(x) contains empirically-derived constants that are
accurate to only two decimal places,it is of little value to calculate the integral to the full (12-digit) precision of the calculator.
b. Iff(x) models a physical system, there may be inaccuracies in
the model.
c. The calculator itself introduces round-off error into each com-putation off(x).
To indirectly limit the accuracy of the integral, specify the accuracy factorof the function, defined as
ACC =

134

true value of f(x) - computed value of f(x)computed value of f(x)4: Integration

The accuracy factor is your estimation of the (decimal form of the) percent error in each computed value off(x). Thisvalue is stored in ACC.
The accuracy factor is related to the uncertainty of integration (a measurement of the accuracy ofthe integral) by:uncertainty of integration = accuracy factor x f | fx) ] ax

f(x)

A

The striped area is the value of the integral. The orange-shaded area isthe value of the uncertainty of integration. It is the weighted sum ofthe
errors of each computation off(x). You can see that at any point x, theuncertainty of integration is proportional to f(x).
The Integration algorithm uses an iterative method, doubling the numberof sample points in each successive iteration. At the end of each iteration,
it calculates both the integral and the uncertainty of integration. It thencompares the value of the integral calculated during that iteration with thevalues calculated during the two previous iterations. If the difference
between any one of these three values and the other two is less than theuncertainty of integration, the algorithm stops. The current value of theintegral is returned to the X-register, and the uncertainty of integration isreturned to the Y-register.
It is extremely unlikely that the errors in each of the three successive calculations of the integral —that is, the differences between the actual
integral and the calculated values —would all be larger than the disparity
among the approximations themselves. Consequently, the error in the
final calculated value will almost certainly be less than the uncertainty of

4: Integration135

integration.
Example: The Accuracy Factor and the Uncertainty ofIntegration. Certain problems in communications theory (for example,
pulse transmissions through idealized networks) require calculating an
integral (sometimes called the sine integral) of the formt.

ﬂ0=L$?@x
Find Si (2).
First, write a program that expresses the function.
B8 £1&6-Bute PramX

a1 LEL "SI
8z MYAR "X
a3 RCL "X
84 SIH83 RCL+ "X
a5 EMD

Set the display format to ALL. Set the angular mode to RAD.

WO SALL:g@(MODES] RADx: B

Select the Integration application and then program SI.
B81

Set Vars; Select JSvar&11111|

Select the variable of integration X, then enter a lower limit of 0 and an
upper limit of2.

0LLIM

2ULIH

136

4: Integration

ULIM=2
TN TWTENATI.

Since the functionfx) = sinx
X

is a purely mathematical expression containing no empirically-derived
constants, the only constraint on the accuracy of the function is theround-off error introduced by the calculator. Itis, therefore,at least
analytically reasonable to specify an accuracy factor of 0.00000000001(1x10711),[E] 114]

ACC=0. 0880080800081(eeidjucidlwce |oCalculate the integral.
f=1.6054129768[LLIMJOUMAeC|&
Check the uncertainty of integration.

(xy]

X: 2. 10942218026E-11
NTRTNIThe uncertainty ofintegration is significant only with respect to the last
digit of the integral. The calculation took about 19 seconds. If you can
accept a less accurate answer, you can shorten the calculation time. Try an
accuracy factor of 0.001.

001 ACC|I=1 . 68541531589

TN TSN AT I.

I

Check the uncertainty of integration.
[xzy)

x: 1.68608822892€-3
ISNTEN TN BTSNI .

4: Integration

137

The error of 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
4EXIT)[EXIT]

B(DisP) |v: 1.6054([EXIT

x: B.0016

4

Example: A Problem Where the Uncertainty of Iintegration Is
Relatively Large. In the previous example, the uncertainty of integration was relatively small compared to the value ofthe integral. Thisis
because the value of the function was always positive within the interval of
integration. Now consider the simple functionfx) = sinx
Integrate the function from x = 0 tox = 6 (radians).
f(x)A

By inspection, you can see that the value ofthe integral is a small positive
number, since the area with positive value from 0 to = is almost cancelledby the area with negative value from = to 6.

138

4: Integration

Write the program that expresses the function.
B3
a1
a2
B3
B4
85

¢ 14-Bute Pram 2
LEL "SIH"
MVYAR "RRCL "=&"SIH
EHND

Set the angular mode to RAD. Select the Integration application and thenprogram SIN.
B(MODES] | FRl}

B/X)]

Set Vars; Select Jfvar&[[11T|

EI

Select the variable ofintegration X, enter the lower and upper limits (0and 6), and an accuracy factor of 0.01. Then integrate with respect to x.

=

7=0. 0398

6 ULIM.01 ALNow check the uncertainty of integration.
(xxy]

x: B.0398[LLijuiimfacc] o

The uncertainty of integration is large compared to the value of theintegral.
Exit from the Integration application.
EXIT][EXIT](EXIT

4: Integration

139

Conditions That Can Cause Incorrect Results
Although the integration algorithm in the HP-42S is one ofthe best available, 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 behavior is there any substantial risk of obtaining an
inaccurate answer. Such functions rarely occur in problemsrelated toactual physical systems.
Example: A Condition That Causes an Incorrect Result. Consider the approximation ofj;ooxe" dx

o3 =IO
W~ O Al B WMo I

Since you’re evaluating this integral numerically, you might think that you
should represent the upper limit of integration with a large number, say
100,000. Try it and see what happens. First write a program that expresses
fx).
£

17-Bute Pram

2

LEBL "HE=XR"
MVAR "E"RCL "X"
EMTER
+/Etx
®
EHD

Now select the Integration application and then program XEX.
B

.BER

Set Vars; Select Sfvar
ETN D D DN e

140

4: Integration

Select the variable ofintegration X, then enter the lower and upper limits
and an accuracy factor of 0.001.

ACC=0.0010
NTNTIN

Integrate with respect to x. (Stay in the Integration application after executing this calculation. You will integrate this function again in the next
section.)
J=0.00800
NNTNTR IN

The answeris clearly incorrect, since the actual integral off(x) = xe ™% ,evaluated from 0 to oo, is exactly 1. But the problem is not that you
represented oo by 100,000, since the actualintegral of this function from 0
to 100,000 is very close to 1. The reason you obtained an incorrect answer
becomes apparent if you look at the graph off(x) over the interval of
integration.
f(x)

A

—

)x

The graph has a spike (illustrated here with a greatly exaggerated width)very close to the origin . Because no sample point discovered the spike,the algorithm assumed that f(x) was equal to 0 throughout the interval of

4: Integration141

integration. Even if you increased the number of sample points by specify-

ing an accuracy factor of 1 x 107! | none of the additional sample points
would discover the spike when this particular function is integrated overthis particular interval.
Subdividing the Interval of Integration. If you suspect the validityof the approximation of an integral, subdivide the interval of integration
into two or more subintervals, integrate the function over each subinterval, then add the resulting approximations. This causes the function to beevaluated at a new set of sample points, more likely revealing any previously hidden spikes. If the initial approximation is valid, it equals the sumof the approximations over the subintervals.
Example: Subdividing the Interval of Integration. Consider
again the integral
j:oxe" dxApproximate the integral by subdividing the intervalof integration into
three subintervals, one from 0 to 10, the second from 10 to 100, and thethird from 100 to 100,000.

First, integrate between 0 and 10. If you arestill in the Integration application, simply supply the new value for ULIM.

10 ULIMs

7=08.9995
ATATTIThe answeris very close to 1. Now integrate between 10 and 100.

10 LLIM
100 TUCTHE

f=0.0808085
OTT IIThe answer is very close to 0. The sum of the 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.)
100LLIM
100000 UL IM

142

4: Integration

J=0.0000[LLijuiif wec | oThe integral over the third subinterval is 0. The sum ofthe integrals over
the three subintervalsis 1.

Conditions That Prolong Calculation TimeIn the first example in the preceding section, the algorithm gave an
incorrect answer because it never detected the spike in the function
f(x) = xe ~* . This happened because the variation in the function was tooquick relative to the width of the interval of integration. In the second
example, you obtained a very good approximation by subdividing theinterval of integration into three subintervals between 0 and 100,000.
However, for this function, there is a range ofintervals that is smallenough to obtain the correct answer, yet result in a very long calculation
time.
Example: An Upper-Limit Approximation That Prolongs
Calculation Time. Consider again the integral
fooxe T dx

0Approximate the integral by calculating it over the interval (0, 1,000).
Enter the new values for LLIM and ULIM. Then integrate with respect to
S=1.0800
ISR TNTS I.N

This is the correct answer, but it took a long time to calculate. To understand why, compare the graph of the function betweenx = 10 andx = 10°(which looks about the same as that shown on page 141) with the following graph ofthe function betweenx = 0 andx = 10.

4: Integration

143

O

f(x)

>
10

You can see that the function is "interesting" only at small values of x. At
greater values of x, the function is not interesting since it decreases
smoothly and gradually in a predictable manner.
The algorithm samples the function at increasing numbers of sample
points until it has sufficient information about the function to provide anapproximation that changes insignificantly when further samples are considered. In the previous section, when you evaluated the integral between
0 and 10, the algorithm needed to sample the function only at values
where it was interesting but relatively smooth. The sample points,after
the first few iterations, contributed no new information about the

behavior of the function and the algorithm stopped.
In the last example, most of the sample points capture the function in theregion where its slope is not varying much. The algorithm finds that the
few sample points at small values of x return values of the function thatchange appreciably from one iteration to the next. Consequently, the function has to be evaluated at additional sample points before the disparity
between successive approximations becomes sufficiently small.

144

4: Integration

Forthe integral to be approximated with the same accuracy overthe larger
interval as over the smaller interval, the density of sample points must be thesamein the region where the function is interesting. To achieve the samedensity of sample points, the total number of sample points required overthe larger interval is much greater than the number required over thesmaller interval. Consequently, several more iterations are required overthe larger interval to achieve an approximation of the same accuracy, andthe calculation requires considerably more time.

4: Integration

145

S
Matrices
This chapter builds on material introduced to you in chapter 14 of yourowner’s manual. The following topics are covered:
Using the matrix editor and indexing functions.
Vector solutions.
Solving simultaneous equations.
Using the Solver with simultaneous equations.
Matrix operations in programs.

Using the Matrix Editor and Indexing
Functions
In the following example, you’ll:m Create a matrix.

m Use the matrix editor to manipulate data.
m Use indexing functions and statistics functions interactively.
Example: Accumulating Meteorological Data. Dr. Steven
Stormwarning, noted meteorologist, has accumulated the following data
and wishesto store it in a matrix in the HP-42S.

146

5: Matrices

Day #

Temp

Wind

Humid

1
2
3

67
69
74

8
14
4

54
36
72

Creating a Named Matrix
Create a 4 X 4 matrix "WTHR".

4 [ENTER] B(MATRIX] (W] DIH
ENTER] WTHR

x: 4.0000
C007JCROSSTUNEC] DM[INGEREDITN

Using the Matrix EditorEnter the matrix editor and select the matrix you just created.

ERLITH HWTHRE

1:1=0.060800

Fill element 1:1 with the Alpha string DAY #. (Remember, to execute[ASTO], press
in ALPHA mode.)

B(ALPHA] DAY #U

1:1="DAY ¥"Fill the remaining elements in row 1 with the corresponding Alpha strings
from the table. (The keystrokes for element (1:2) are shown here.)

B(ALPHA] TEMP

1:4="HUMID"[EXT) ...

5: Matrices

147

Now fill the remaining elements with the corresponding data.

4:4=72_ITIT

Stormwarning finds that his assistant has incorrectly recorded the temperature on day 1; it was 77, not 67.
GOTO2 [ENTER] 2 ([ENTER] 77 [EXIT]

X: 77. 00080
00TJEROSS]UMEC]DIk[INDER[EDITN]

Several days later the doctor has more data to add: on day #4, the temperature is 77, the windspeed is 5, and the humidity is 76. First, set the calculator to Grow mode to create a new row in the matrix.

EDITH WIHE =¢W &l 3515 ATy

5: 1=0. 0000[€(o[+|+[coto]»»

2:4=76_
IST SO (TStormwarning 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 thehumidity was 41. First change the value in element 5:1 to 5.
S:1=5_[€Jow|+|+|Goto]=+|Now insert the new row.

(V] IHER

148

5: Matrices

5: 1=0, 000D
[IN:R|_[CELR| |WRAP)GROS]

Enter the actual data for day #4.

@45

a1

5:4=41_ITN[TExit from the Matrix application.

v: 4, 0000

x: 41.0800

Using Indexing Utilities and Statistics Functions
Interactively
Dr. Stormwarning now wants to execute statistical operations on segmentsof his accumulated data. He would like to find the mean temperature andwindspeed for the five days. He’ll execute GETM to create in the Xregister a 5 X 2 submatrix that contains the temperature and windspeed
data. He’ll then execute X+ to store the data from this submatrix in thesummation (statistical) registers, select the STAT menu, and find themean. (Remember that the £+ function automatically stores the datafrom an n-row X 2-column matrix into the currently defined summation
registers. Refer to the discussion of the £+ function in chapter 15 of yourowner’s manual for more information.)
Specify WTHR as the indexed matrix.

BMATRIX] (V)IHDEY WTHR

x: 41.0000
00TJEROSSJUVEC|DIt[INDER[EDITN]

Set the index pointers to element 2:2 (the first temperature data entry).
2 [ENTER] (V] =TI J

x: 2.0000

Now get the 5 x 2 submatrix that contains the temperature and windspeeddata.
5 [ENTER] 2 GETH

x: [ 5x2 Matrix 1(ST0I[RCLI[STOELRELEL]PUTH[GETH)

5: Matrices

149

Clear the summation registers, then store the data from the matrix in thesummation registers. (If the calculator returns the message
Monexi=stent, the current SIZE allocation is insufficient.)
B(CLEAR]il
BOOPFCN) :=%x: 5.0000

Select the STAT menu and find the mean of the temperature data.
BISTAT] MEAH

Ix: 73.0800|[Z+|SUM[MEAN]MN]Z0EV]CFIT|

Find the mean of the windspeed data.
X%x: 8.68008
I+ SUMJMEAN]MMNS0EVCFITThe mean temperature for the five days is 73. The mean windspeed is 8.6.
Exit from the STAT menu.
EXIT

Y:
x.

Matrix Utilities
The following routines use existing matrix functions to build useful matrix
utilities.
Finding the Column Sum of a Matrix. CSUM calculates thecolumn sum of the matrix in the X-register. (The column sum of a matrix
A is a row matrix, each element of which is the sum of the elements of thecorresponding column of matrix 4.) The resultant matrix is returned to
the X-register.
a8
a1
B2
A2

150

L 14-Bute Pram X
LBEL "CsuM"
TRAMS
RSUM

5: Matrices

a4 TRAHS
a3 END

Finding the Column Norm of a Matrix. CNRM calculates thecolumn norm of the matrix in the X-register. (The column norm of amatrix A is the maximum value (over all columns) of the sums of theabsolute values ofall elements in a column.) The result is returned to theX-register.
88 {

81
A2
B33
84

12-Bute Pram 2

LEBL "CHEM"
TEANS
RHEM
EHD

Finding the Conjugate of a Complex Matrix. To find the conjugate of a complex matrix:
1. Place the matrix in the X-register.
2. Press l[COMPLEX].
3. Press [*/-].
4. Press B[COMPLEX].
The conjugate is returned to the X-register.
Finding the Matrix Sum of a Matrix. MSUM calculates the matrixsum (the sum ofall the elements) of the matrix in the X-register. The
result is returned to the X-register.
A8 {

a1
Az
B3
B4
A5

18-Bute Pram

LBL "MsSUM"
XKER "CsuUM"
RSUM
DET
END

5: Matrices

151

Finding the Maximum and Minimum Elements of a Matrix.

MINMAX finds the maximum or minimum element of the rea/ matrix in
the X-register. The element is 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 element. Clear flag 09 to find the minimum element.

T
S W0

I

+

Comments:&61-Byte Pram

STO "MIMMAX"IMDEX "MIHMAR"RCLEL
GTO 8=LEL ©1
RCLEL
FS7? @9
[]

ETO

82

44

=

M o=

—

Lines 02-05: Store the matrix

currently in the X-register in
MINMAX, index MINMAX, andestablish element 1:1 as the current
maximum or minimum element.

Lines 06—12: If flag 09 is clear,test if
the current elementis greater than thecurrent minimum. If yes, go to label 04(to maintain the current minimum). If
no, go to label 03 (to make the current
element the new minimum).

a7
GTO
2 GTO 45

on Fo D.

LEL "MIMMAX"

-~

P

0
|l'|
1=
o)

1=
o

RN
= AN LU
an $ 00

I

=

,.
e’
o

Program:

LEL @2
HLYTLines 13-15: If flag 09 is set,test if
the current element is less than thecurrent maximum. If yes, go to label
04 (to maintain the current maximum). If no, make the currentelement the new maximum.

GTO G4

12 RCL ST
19 EMTER

r-J

Lines 16 -19: Make the current element the new maximum or minimum.

8 LEL B4
21 E4
22 J+

152

5: Matrices

Lines 20 —24: Maintain the current
maximum or minimum element.

23 FC? 7 v
24 GTO 81
23 EMD

Sorting a Matrix. SORT sorts the rows of the matrix in the X-registerin ascending order by the values in column 1. The sorted matrix isreturned to the X-register.

Program:
A8 {21-Bute Pram

Comments:
2

A1 LEBL "SORT"A2 STO "SORTHAT™
B2 IHMDEX "SORTHMATY

a4 LEL 91
as I+
a5 F5? T
a7 GTO G4
a2 RCLI
a9 KOy18 RCLEL

Lines 07-10: Establish the row
numberto sort. (On the first pass, row
2 is the row to sort, against row 1. On
the second pass, row 3 is the row tosort, against rows 1 and 2.) Continue
until all rows are sorted.

1 LEL B2
12 I12 RCLEL
14 F57 V&

Lines 11-24: Successively move the"sort row" up the matrix until its
column 1 value is greater than thecolumn 1 value of the previous row.

15
16
17
12
12
28
21
22
23
24

GTO 83Rey'?
GTO B3R4
RCLI
RCL+ ST Y
R4XE
F+
FEu
GTO @82

5: Matrices

153

25 LeBL @z

Lines 25-32: Increment the "sort-row”

26 R4
27 R+
22 1

number. If the increment causes theindex pointer to wrap, return thesorted matrix to X and end the pro-

23
28
21
22

STOILJ
GTO a1
LBL B84
RCL "SORTHMAT"

gram.

o)
k]

EHD

Vector Solutions
Vectors are a special subset of matrices. You can describe a vector witheither 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
A = Frobenius norm (magnitude) of (V'V; xV;)
where (' V; X V,) is the vector cross product V; and V.

154

5: Matrices

Example: The Area of a Parallelogram. Find the area ofthe following parallelogram.

(0,0,0)Create vectors V; and V.

BMATRIX]

1 [ENTER])3 (V] [IH1

x: 3.0000
00TJCROSS]UMEC]DIM[INDER[EDITN]

Vi
3DINM
V2

Enter values for each element in V; .
X: 2. 9@99
00T |CROSS

2 [EXITEnter values for each element in V.
x: 3.00008
B [UVEC] DMJINDERJEDITN
3 [EXIT
Calculate the area.

5: Matrices

155

The area of the parallelogram is 15.0000.
Exit from the Matrix application.
EXIT

Coordinate Transformations
It is often necessary in dynamics or mechanical design problemsto perform coordinate transformations. Coordinate transformations require youto:m Calculate a unit vector.
m Add vectors.
m Calculate a vector dot product.
m Multiply vectors.
m Calculate a vector cross product.

156

5: Matrices

ORIGINALSYSTEM

-

\\

\

PX
\\

.

(Tr_.7 ) \

--

§7

X 7

W~ NEWSYSTEM

f

AN
_\
Notes: AXIS (the rotation axis vector)

o7
7

P

is pointing out of the page.
atpointT.
The rotation is relative to thetranslated origin.

The equation for a coordinate transformation of a point from the old system to a new system is
P =[(P-T)'n]n(1-cosf) + (P -T)cosd + [(P - T)xn]sinf
The equation for a coordinate transformation of a point from a new system to the old system is
P=[(P" *n)n(1-cosf) + P cosf+ (P xmn)sin(-6)] +T
where:
P’ is the coordinates of the point in the new system.
P is the coordinates of the point in the old system.
T is the origin of the new system.
n is the unit vector of the axis about which the rotation is to be done.
g is the rotation angle.

5: Matrices

157

Note that the translation occurs before the rotation. The rotation is rela-tive to the translated origin.
The following program, COORD, enables you to fill the vectors P,(or P"), T, and AXIS with data by programmatically invoking the matrix
editor and enables you to specify either an old-to-new or new-to-old
transformation. (AXIS is the rotation axis vector. COORD stores the data
you supply for AXIS in the variable n, then calculates the unit vector n.)
To key in COORD: Create variables P, T, P’, n, and X before program entry.

Here is an annotated listing of COORD.

,_
150
[N

Comments:
Fo

215-E 8 t=

EXITALL

Lines 02-11: Build the main menu.

CLMEHML00Ul

sEQ B3[}i

EEY1] T I" KEY
g "AXI
3 KEY

= T
0
— o0

—_

M

HER @2

=

GTO 8

T
=g

1 Fl 1"1.

o"COORD"

I
00

=
wl

T
1)
ab

LEL

2N 0 g

'::

-~
't
e

Program:

KEY 4 XEQ B4

12 LBL 2=

Lines 12-15: Display the main menu.

=to0 =] T

LEL @1"p
HER 93[l b=to0

12 MEHU
14 =STOF
1 o GTO 28

EEY 2 GTO 8%

158

5: Matrices

MH

Lines 16 -22: Display the submenu toedit vector P (or P” ) and choose thedirection ofthe transformation.

LEL 37

Lines 23-27: Display the submenu.

MEHL
CF B8

M
WO 00
0
T

GTO

0
o=

LEL
"

LEL 299

Lines 33-46: Create a 1 x 3 vector P,

CLMEHUASTO ST L
1

T, or n and openit for editing. Build
matrix editor menu labels and promptfor data input.

|‘_T'-

on

5

LEL

O3
M

=]

GTO

vL

STOP

Fa

—

r [a
M

KEY & GTO B85

fu o Ja 0 [N OO 00 G0 0

[ P Td P [-] i nL
L 0e

Lines 28 —32: Place the vector names

T and n in the Alpha register to create
the vector.

iw0
o W0

"

0=

ENTER

o0

LIM IMD ST
L

fod3

=

50

EDITH IND ST L

'

KEY

1

r'l:l

s

a
2
LN e

LEL 11
&

n
n

il
Ja

L0

S
T
T

EEY

noon o b b[ = &0 W 0y o=

KEY
ETH

N

¥ER

11

1" _} nFETHLELRER 12
GTO "COoRD"

Lines 47 -52: Execute the matrix editor functions.

12

FTH

LEL &4

Lines 53 -55: Prompt for the value of

IMFUT "FTHA

5: Matrices

159

n

[

-~
ol

|'_‘I".

o

=]

n n

= =

=] =) ==] =l I T Ty [y T i (i) non
KX
lTl o Fao 00 O e't
wOOd = T QN B Q0 d o000

=)
~J
=) =)
g0

LEL @&EXITALL
RCL “P"
FC? @aRCL- "T"STO "pro

RCL "n"UVEC

5TO "n"Dot
1
RCL "&"
cos
FECLx

"m"

RCL "acos

RCL3x "p'®
<+RCL "p'"
RCL "n"CROSS

RCL "«

Q0

on £
T

OO0
00
00

|
i

QD
=~
00 Q0
WJOoD
o0

GTO &1—

FS7 oaRCL+ "T™

EMD(YLines 56— 57: Set flag 00 for a new-toold transformation.

00
My

Q0 00
o=

EL
F &

STO P

5: Matrices

Lines 58 —90: Evaluate the transfor-

mation equation. If flag 00 is clear,calculate the old-to-new transforma-tion. If flag 00 is set, calculate the
new-to-old transformation.

To use COORD:

1. Press

COORD.

2. PressT, then supply values for the elements of T using thematrix editorlabels in the menu. Press [EXIT] to return to the mainmenu.
3. Press H&IES ,then supply values for the elements of the rotation

axis using the matrix editor labels in the menu. Presstoreturn to the main menu. Note that COORD stores the rotation
axis in variable n, calculates the unit vector of the rotation axis, andstores the unit vector back in n. If you press H?
after executing

a three-dimensional transformation, you will see the newly calculated elements ofthe unit vector, not the original rotation axis.
For a two-dimensional transformation, set the rotation axis to0,0, 1).
4. Press1, then supply a value for % and press [R/S].

5. PressF , then supply values for the elements of P (orP)using the matnx editor labels in the menu. Then press
convert from the old system to the new system, or press = M=+convert from the new system to the old system. The calculatlon is
now executed.
Example: A Three-Dimensional Translation with Rotation. A
three-dimensional coordinate system is translated from (0, 0, 0) to (2.45,
4,00, 4.25). After the translation, a 62.5° rotation occurs aboutthe (0, -1,—1) axis. In the original system, a point had the coordinates (3.90, 2.10,
7.00). What are the coordinates of the point in the translated, rotated system?
Forthis problem:

P = (3.90, 2.10, 7.00)
T = (2.45, 4.00, 4.25)
AXIS = (0, -1, -1)
A = 62.5°

5: Matrices

161

Set the display format to FIX 2. Set the angular mode to Degrees. Execute program COORD.
x: B.008
I ITS.

Enter the elements of T.

X: 2449|l[lllllllﬂﬁll!!llllllllJ

EXIT |
Enter the elements of the rotation axis.
x: B.080
P TJeiis] &2| |Enter the value of ..

X: 62,00
NT.

62.5
Enter the elements of P.

1:1=3.90
N N BCEYEETE

1:1=3.59
BNTRT
Element 1:1 of P is 3.59. Check element 1:2.
1:2=0.26€» |[N30[03N]162

5: Matrices

Check element 1:3.

1:3=0.59
e>|[N3D|0+N
The coordinates of the point in the new system are (3.59, 0.26, 0.59). Exitfrom program COORD and return the display format to FIX 4.

1.00090
vx: B.5891

4

BDISP] :Solving Simultaneous Equations
Evaluation of an electrical circuit by the technique of loop currents generates a system of simultaneous equations. The number of equations inthe system is equal to the number of loops in the circuit. The first example
in this section finds the currents in a four-loop, purely resistive circuit (thetermsin the system of equations are real numbers). The second example
finds the currents in a four-loop circuit that has complex impedances (thetermsin the system of equations are complex numbers).
Example: Solving Real-Number Simultaneous Equations.
Consider the following four-loop circuit.

R4

R3

M—W

Rs

Rz

Apply the technique of loop currents to find the currents I, 15,15,14.

5: Matrices

163

The equations to be solved are (in variable form):
1. (Ri+R3)(11) - (R) (1) =V
2. -(R2)(I;) + (Rz+R3+Ry)(I2) - (Ry)(I3) =0
3. -(Ry)(I2) + (R4+ Rs+ Rg)(I3) - (Rg)(14) =0
4. -(Rg)(I3) + (R¢+ R7; + Rg)(14) =0

of

|I

-1
0

2 -1

3-1 0
-1 3 -1

0

I,
I,

0

0 -1

I,

3

OOO%

Put the equations in matrix form, substituting the following values for thevariables: V' = 34 V and R, through Rg = 111.

Select the Simultaneous Equation application, and specify the number of
unknowns.

BMATRIX] SIMG4 [ENTER

x: 8.080008[(MATRIMATE[MATHR]]|Enter the values for the elements of the coefficient matrix MATA. (Thekeystrokes for the entering the first row data are shown here.) After
entering all the values, return to the main menu.
x: 3.00800(MATA[MATE[MATR]| |EXITEnter values for the constant matrix MATB.

x: 0.008008(MATA[MATEIMATR]|] |164

5: Matrices

Calculate the unknowns.
MAT =1:1=21.0600008€jop]+|4|GOTOf+|

I,1s 21 A. Now check 7, .
2:1=8.08000
ISTIT[TCheck I5.
3:1=3.06000[€Joww]+|4[cOT0f3|

4:1=1.080080[€jotp| +|4|GOTO|-|

Leave the matrix editor. (Stay in the Simultaneous Equation application
for the next example.)EXIT

x: 1.0800(MATAIMATEIMATR]||]

5: Matrices

165

Example: Solving Simultaneous Equations That Have Complex Terms. Now consider the following circuit.

)|

J1
C,

AY

I

C,

AY

/1

Cg

AY

/1

Cy

The capacitor in each loop ofthe circuit introduces a complex term into
each loop equation:

1 |(Ry+ Ra) = (5| (1) = (Ra)(Ja) = ¥2. = (Ra)(Ia) + Ry + Ry + Ry = i(25)| (1) = (Ra) (Is) = 0
3. - (RO)(I3) + Ry + Ry + Re =i (25| (Ia) = (Ra) (1y)= 0
4. - (Re)(I3) + —Re + Ry + Rg - i(w(%).(h) =0

166

5: Matrices

Put the equations in matrix form, substituting the following values for thevariables: V' = 34V, R, through Rg = 50, w = 100 radians/second,and C; through C, =1F.

10 - i0.01

-5

0

0

I,

34

-5

15 - i0.01

-5

0

I;

0

0

-5

15-i001

-5

I.]

0

0

-5

15-i001|

|f,

=

|o
0

Set the coordinate mode to Rectangular. Make MATA a complex matrix.

B(MODES]

0 [ENTER

x: 0.0000 10,0000(MATAlHRTEIMATE]] |(x]
Enter the values for the elements of the matrix. (The keystrokes for theentering the first row data are shown here.) After entering all values,
return to the main menu.

10 ENTER] .01 [+x: 15.0000 -10.0100
CHRGEIE GN

B(COMPLEX

5[4

EXIT

Solve for MATX. (MATB has the same value as in the previous example.)
1:1=4.2600 i0.0061[<fote]+|4[GOTO[3|I, is 42000 + i0.0061 A. Now check I, .
2:1=1.6000 i0.0037

5: Matrices

167

Check I5.

e

3:1=0. 6000 10,0019

Check I, .
4:1=0.206800 i8.0008

Exat from MATX.
x: B.2000 i8.06808(HaTh[MATE[MATR]|]

EXIT

Make MATA and MATX real matrices. Exit from the Matrix application.

_MATHB(COMPLEX]

v: [ 4x1
4x1 Matrix
Matrix ]]X:[

B(COMPLEX

Using the Solver with Simultaneous
Equations
In the examples in the previous section, you found the loop currents I
through 7, by dividing the constant matrix MATB by the coefficient matrix
MATA. You were limited in that example to solving specifically for theloop currents in the solution matrix MATX.
In the following example, you’ll use the Solver and matrix divisionto findthe value of one element ofthe coefficient matrix, MATA, given:m Values for the other elements of the coefficient matrix.
m Values for the elements of the constant matrix.

m A specified relationship between two values of the solution matrix.

168

5: Matrices

Example. Using the Solver to Find the Value of an Elementof the Coefficient Matrix. Consider again the circuit from the previous section in this chapter.

y—

R4

Rg

W

Rz

W

+

Iy

=S

I

v =

Find the resistor value R; such that loop current I, is 20 A greater thanloop current I, (I; = I5+20), when V' = 40 V, and R, through Rg = 1 Q.

R

-1

-1

3 -1 0-1 3 -1
0 -1 30000I, + 20

I,
I,
I,

OOOS

These conditions generate the following matrix equation.

5: Matrices

169

Part 1. Write the program for the Solver.
Program:#8 {#1Comments:

S2-Byte Pram

LEBL

"SIMUL"™

B2 MVAR
22 MVAR"R""ROW"

A4 MVAR83 MVAR"CoL""D"#5e IMDEX "MATA"
87 RCL "ROW"A2 RCL "coL"
B9 STOIJ
14 RCL "R"
11 STOEL

Lines 02-05: Declare the variables R,
ROW, COL, and D.

Lines 06— 11: Index the coefficientmatrix, and set the index pointer tothe elementspecified by the current
values of ROW and COL (lines 0508). Store the current value of R (supplied first by you as initial guesses, andthen iteratively by the Solver) in thespecified element (lines 09 - 10).

12 RCL "MATE"
12 RCL+ "MATAH"
14 STO "MAT="

Line 12-14: Solve for MATX. MATA
has the current value of R in the15Lines 15-20: Index the just-calculated
solution matrix (line 14). Calculate
I, - (I; + D) (lines 15-20). The
Solver iteratively supplies values for R
until7, - (I; + D) = 0.

IHDEX

"MATH"

16 RCLEL
17 I+
12 RCLEL
19 RCL+ "D"
28 21

170

EHD

5: Matrices

specified element.

Part 2. Enter the Matrix application, and specify a system of equations
with four unknowns.

BMATRIX] SIMi4 [ENTER)%: B, 0000
[MAThMATEAT|||

Fill MATA with the known coefficients. Element 1:1 contains theunknown resistor value R. You can leave this element atits current value.

(The keystrokes for the first two rows are shown here.) After entering all
the data, return to the main menu.

MATA
1%[MATHIMATE[MATR]]|3. 8000

EXIT

Fill MATB with the known constants, then exit from the Matrix application.

0
EXIT]

(EXIT][EXIT

Select the Solver application, and then program SIMUL.
"[SOLVER] #)|x: 40. 8000
I
I AT TTISpecify element 1:1 of the coefficient matrix.
COL=1.06080608
R [RroMfcoLo]|
Enter 20 for D.
D=20.8000
ITNTTI.

5: Matrices

171

Enter guesses of 0 and 10 for R and solve for R.
R=1.6190
G TTTI

Verify that element 1:1 of the coefficient matrix (R) is 1.6190.

B(MATRIX](V]
EDITH MATH

1:1=1.6190

R; = R - R, = 0.619 Q. Check the values for I; and I, .
1:1=32.30677[¢«Jote]+|4|GOTOf&|I, is 32.3077 A. Check I,
2:1=12.307°7

I,is 12.3077 A. Exit from the Matrix application.

Matrix Operations in Programs
All matrix functions except GOTO are programmable. The programs foradvanced statistical operationsin the following chapters use matrices
extensively.
The program LIST on pages 176 —178 enables you to accumulate statistical data in a matrix with the same keystroke sequence that you use in normal 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 independent variables. MLR creates a coefficient matrix MATA and a constant matrix

MATB.1t executes matrix editor functions to fill them with data, then executes matrix division to calculate the solution matrix MATX.

172

5: Matrices

The program PFIT on pages 218 - 222 plots thestatistical data from thematrix currently in the X-register, then fits and plots a curve to the datausing the current statistical model. It plots the curve and the data points
using x-y data pairs from complex matrices.

5: Matrices

173

6
Statistics
This chapter presents five programs for statistical operations. The programs use 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.
m Three programs enable you to accumulate data in a matrix for subsequentstatistical operations:m LIST enables you to fill an n x 2 matrix 2LIST with x- y data
pairs with the same keystroke sequence that you use to enter data
into the summation registers.
m YFORM stores an n X m matrix in £LIST and redimensions
LLIST to nm x 2. Each element of the original matrix becomes
an element of column 2 of XLIST. Column 1 is filled with zeros.
m XVALS fills column 1 of XLIST with x-values 1, 2, 3,..., n for

linear or exponential curve fitting.
m MLR calculates a multiple linear regression for two or three independent variables using the £+ function and matrix operations.
m PFIT plots the x-y data pairs from XLIST and uses FCSTY to plot a
curve to the data according to the currently selected statistical model.
(The annotated listing of PFIT is in chapter 7 on pages 218 -222.)

174

6: Statistics

List Statistics
To supply a set of x-y data pairs to the calculator for subsequentstatisticaloperations, you use the keystroke sequencey-value [ENTER] x-value
for each data pair. The summation coefficients in the 6 (or 13) summation

registers are automatically recalculated each time you press [Z+]. The calculator 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:
1. Create a 2-column matrix.

2. Use matrix editor functionsto fill the matrix with the data pairs.
3. Place the matrix in the X-register.
4. Exccute X+ to accumulate the data in the summation registers.
(You did this in chapter 5 in the section "Using Indexing Utilities andStatistics Functions Interactively".)

6: Statistics

175

The LIST Program. The following program, LIST, enables you to fill a
1- or 2-column matrix XLIST with x-y data pairs using the keystroke
sequencey-value [ENTER] x-value LIS T+(for each data pair).
where L15T+is one of three menu keys built by LIST. Note thatthis is

the same keystroke sequence that you use to enter statistical data into thesummation registers.
To key in LIST:
1. Create variable XLIST before program entry.
2. Assign functions J+ and J - to the CUSTOM menu before program
entry.
3. Create labels LIST, LIST +, LIST —, and CLIST when you begin
program entry.

Here is an annotated listing of LIST.
Program:Ba £Comments:

197-Bute Pram>

A1 LBL "LIST"
A2 CLMEHU

Lines 02-11: Build and display thea3 "LIST+"
g4 EEY 1 HEQ
Ba "LIST-"

menu keys.
"LIST+"BE KEY 2 HER "LIST-"gy"CLI=T"

B2 KEY & XEQ#3 MEHLU"CLIST"

18 STOF
11

176

GTO

"LIST"

6: Statistics

=t

._l—

=

J+

WERF

LEL @&a
STOEL
F5? @1

M
W0
03
=

naey
STOEL
waey

VIEWM
ETH

=

[—y

ke

J

1%

']

DIM
“ER

Lines 29-31: View the ¥LIST matrix.

"ZLIST™

LEL @z1
M M= T

Lines 32-42: Create the 1- or 2column matrix XLIST.

“"ZLIST"
I

F4
F4
GTO

15
2t

[y

Lines 21-28: Store the x-value into
the matrix. If flag 01 is clear, then also
store the y-value.

J+

LEL &1

Foop B 00 0 0 O 0 00 00 0r‘l_'l —t T w0 0 =] on £ 2 M

Lines 12-20: If ZLIST exists, index itand make it grow by one row. If it
doesn’t exist, create and index it (inlines 32-42).

GTO &10

M P T PO O [D I N B 0T ebbt

GTO @2
GROW

MO
=

et

e

oo g I N £ 0

12 LEL "LIST+"SF 25
HEQR IFC?C 25

6: Statistics

177

LEL "LIST-"
-

-

SF 25

43 RER T» FC? 25
> RTH

Lines 43 -53: Recall the element(s) in
the last row of XLISTto the X- (or Xand Y-) register(s).

J

RCLEL
Fs? 81
GTO 83
o

00

()]
£

e

T

[

|:T'-

0

oW

T N oCn

FCLEL

178

LEL &3DELR
FS7C 25
GTO 81
LEL "CLIST"
CLY "ELIST"
RTH
LEL I
INDEX "ZLIST"
RTH
EHND

6: Statistics

Lines 54 -57: Delete the last row of
YLIST.

Subroutine CLIST, lines 58 - 60: Clearthe variable XLIST.
Subroutine I, lines 61 -63: Index

YLIST.

To use LIST:

1. For two-variablestatistics (x- and y-values), clear flag 01. For onevariablestatistics (x-values only), set flag 01; the program makes
LLIST a 1-column matrix.

2. Press (XEQ] LIST .
3. Clear XLIST bypressing
4. Enter data pairs by pressing
y-value [ENTER] x-value LIST+(foreach data pair).
5. You can delete the last data pair by pressing LI

Example: Accumulating Statistical Data in a Matrix. Use program LIST to accumulate the following x-y data pairs in the matrix XLIST.
Then find the mean of the x- and y-values.
x-valuey-value

6
5
9
12
21
7

2
3
5
6
11

4

Clear flag 01 for two-variable statistics. Start LIST.

BFLAGS] .cF01ex: 9, 0000

NED ED N N .

Clear LIST.
CEISTE

Ix: 0. 0808008
ListeuisT-] |1JCLIsT)

6: Statistics

179Enterthe first data pair.

2 [ENTER)6LIST+SLIST=L 1x2 Matrix 3
CEreluist=]1[[eLisn

Key in the next data pair.
3

SLIGST+ZLIST=L 2x2 Matrix 1
LisTejLisT=] ]| [cLIST]

Key in the remaining data pairs (the keystrokes are not shown here). Exitfrom LIST.
EXIT

v: 4.0800
x: 7. 80008

Clear the summation registers. Recall ZLIST to the X-register.

BCLEAR] cLZ[RCL]) ZLISTT.

x: [ 62 Matrix 1

Accumulate the data from LLIST into the summation registers.
v: 7. 8008
x: 6.08008

Find the mean of the x- and y-values.

B(STAT] MEAH%: 10. 0000
|mlmmmmam|

The mean ofthe x-values is 10. Check the mean ofthe y-values.

(xzy]%: 5. 1667
Z+ SUM [MEAN[IEN SDEY CRIT

Exit from the STAT menu.
EXIT

180

v: 18,8000
X: D. 1667

6: Statistics

Redimensioning the XL/ST Matrix to nm x 2. In the previous example, you used LIST to create a 6 X 2 matrix LLIST. You then recalled
LLIST to the X-register, and executed £+ to accumulate the x-y data
pairs from the matrix into the summation registers. To execute £+ when amatrix is in the X-register, that matrix must have a column dimension equal
to 2. If, for example, you use LIST to create an n x 1 matrix XLIST (bysetting flag 01), you must redimension it before executing X +.
The following program, XFORM,redimensions any matrix XLIST of
dimension n X m to dimension nm X 2. All of the elements in the input
matrix are moved to the second column. Thefirst column is filled with 0’s(zeros).

oo S 3 =T N Fo O3 [aa £ S52-Bute Pram
@1 LEL "ZEZFOEM"o—

RCL “"ELIST"
LIM?

in

e

T
£ 03 MY o o

=
W0 00

=~

> DIM "ELIST"
IMDE® "ZLIST"
1
ENTER
2
R<>R
FCL "ELIST"TEAMSST “ELIST"
EHD

Filling Column Two of ©L/ST with Evenly Spaced Integers.
You may wantto fit a linear or exponential curve to a set of one-variable
statistical data. The following program, XVALS,fills the first column of
the ELIST matrix with integers 1,2, 3, ..., n. If ELIST is a 1-column

matrix, XVALS automatically creates the new column.

6: Statistics

181

Program:
g8 ¢A1

Comments:

46-Bute Fram

LEL

2"=®VALS"

a2 RCL "ZLIST"
Az DIM?
a4 1

Lines 02—-08: Recall ZLIST. If itis a
1-column matrix, execute ZFORM to
make it a 2-column matrix. Then index

HS -

it.

HE wLl?
a7y =EQ
A2"EFOREMMIMDES"ZELISTM

a9 LEL B418 RCLIJ
11 =YyLines 9- 14: Fill column 1 withintegers 1, 2, 3, ..., n. Continue to theend of the column.

12 +12 FC7 76
14 GTO B815 EHD

Using the Summation-Coefficient Functions(x+, X, and CLY) in Programs
The program MLR in this section uses the £+ function and matrix operations to calculate a multiple linear regression for three independentvariables.
For a set of data points { (x; ,y; ,2;,4),i = 1,2,..,n }, MLR fits alinear equation of the form
t=a+bx+cy+dz

by the least squares method.

182

6: Statistics

Regression coefficients a, b, ¢, and d are calculated by solving the following set of equations.

n

g

Yy

Xy

¥

o Z()? Iy Ixz

a
b

Lx; ¢

o Zyixi TO)? Zyiz

c

Ly

EZ,'

d

EZ,' tl'

EZ,‘ X

EZ" YiE (Z,') 2

The coefficient of determination R?2is defined asR? =aXt;, +b¥x;t; + cEy,- ;;, +dXz; t; - %(Et,')2£ - o (B6)*

Here is a flowchart for MLR.

6: Statistics

183

Crus

Chw
13S vivd 1SV13HL
LOVHLENS OL-XANV|HLIHV MOVLS 3SN

SH31SIO3YNOILVWWNNS 11V
Hv310 Ol X170 38N

!

1

D

@

sonsnes 9

12:1

Crs)

!

|'44300 TvOILSILVY1S
31vaddN OL+X ANVHLIHV MOVLS 3Sn>

L)| SLEBX I &iax " LL23X1

uO-]VOn A//Z-]O w“w A

€A

€A

F AIX

¢ AIM

++<., A//"Z//A

1NdNI HO4 dO1S ANVNN3IN NIVIN AV1dSId!
SAIM NNINW
NIV aTing
00
1971
13S v1vd M3N
HLIM SIN3I0144300
IVOILSILVLS 31vddn
01 00 V14 V31OA

XLYW ‘GLYW VIVS3DIHLVN aling

41N

FILL MATA, MATB
WITH SUMMATION
COEFFICIENTSv

CALCULATE MATX
AND R2v

BUILD SOLUTIONMENUDISPLAY SOLUTION MENU
AND WAIT FOR DATA INPUT

6_@2 &xmﬁ
A
.

&xmé
oo

&
LOAD ALPHA REGISTERWITH VARIABLE NAME
AND X-REGISTER WITH

&xmf
0"

KEY 9 @

e KEY 5
“Ro"

KEY 6

—

oL

DISPLAYR2
CALCULATEAND DISPLAY T

CORRESPONDING COLUMNNUMBER OF MATX'INDEX MATX ANDDISPLAY VARIABLE

6: Statistics

185

To key in MLR:
1. Assign functions —, 1, +, |, I- and J+ to the CUSTOM menu

before program entry.
2. Create variables MATA, MATB, MATX, R2, and T before program
entry.
Here is an annotated listing of the program.
Program:Comments:

LEL 86
CF 21
CLMENU

s

eS

S
o

S

S

S

M - =0 00 T N B 00 M

FEALRES
4M
N MMM NN M Pt b b b b ek b=-Jo e W o=@ OO~ W

aa { 460-Bute Pram 2
a1 LEL "MLR"

186

EHTER
1
CIM "MATA"
LIM "MATE"
4

Lines 02-12: Setto calculate real
results only. Create 4 x 1 matrices
MATX and MATB. Create 4 x 4matrix MATA. Clear flag 00 (set to£+ mode). Set to Linear (statistics)
mode (calculate six summation
coefficients).

ENTER
DIM "MATA"
CF oa
LINE

" E+ 1

KEY 1 XKER 11" E__ "KEY 2 XKE& 12
n CLE nKEY 3 XEQ 13" CHLC n

KEY & GTO 14
MENU
CLD
STOP
GTO B8

6: Statistics

Lines 13-27: Build and display the
menu
keys
E——

r-J

Q0
O
00
O
Q0

Ry

1T

00

n oo 03 [ e w0 00

ing coefficients: £z in Ry, 222 in R gg,¥ in Ry, %t2in Ryg, Y2t in Ry, 1 inB

l_‘.—"P OO0 Q0
o0 00—~

00

Subroutine 11,lines 28 — 58: Emulate

X+ (or - if flag 00 set) to update thefollowing summation coefficients: Lxz
in Ry3, Bt in Ryg, Tyz in R4, Tyt inR 6. Execute £+ to update the follow-

A aan anodnonon anon b010 =] £ r-._'l e W0

-t

-l

43

ZREG @7
FS? baRTH=+

6: Statistics

187

T i T T T
N W frao— W0

LBL 12
SF g
AER 11

LEL 12ZEEG 11
CLE
ZREG @7
CLE
EZREG 81
CLZE
RTH

Subroutine 13, lines 76 - 83: Execute

LEL 14

Lines 84— 147, calculation of"Calculating"

AYVIEHN

coefficients a, b, ¢, d, and R? : Fill
MATA with x, y, z summation=

coefficients. Fill MATB with t summa-

FETH

AER &1

Subroutine 12, lines 69 —-75: Emulate

Y- (set flag 00) to update thecoefficients calculated in subroutine
11. Execute £- to update the remaining coefficients.

FETH} STOx "MATA"
IMDE:= "MATH"

w0
03

g0
o

WO
M g

=]

T

00

0D

Q0

0

~)

=~

=

=]

~J sg s = |'_T'-|'_T'-To==+n £ 03 Mo = [¥u]

ZREG 81
FS?C 8aETH

coefficients: £x in Ry, 22 in Ry, Ly
in R, Ly2in Ry, Lxy in Rgg, and 1 in
Ry . (Note that n is also calculated insubroutine 11.)ol M = o W0 o= (g

1T

F4
R4

Subroutine 01,lines 59 - 68: Execute

L+ to update the followingn oN

LEL &1CLA
LAST®

6: Statistics

CLEX to clear all defined summation

registers.

tion coefficients. Calculate MATX

(MATB +~ MATA). Calculate R2.

e

L1
L o
- bt b b bk b b b b b e e 0 L0 O
ooT o0 00 = I_T‘l N Jau—_ oS S o
=
=

n_l +

14

O

2 RCL
4

RCL "MATAR"TEAMS» STO+ "MATAR"RCL @2

)

CL

4

=
M

34+
o
F‘

>

A

g0

4:_

>+

b
b

o1 T=

b
Pt

114
115
11e
117
112
112
128
121
122
122
124

4+

+

=)

LN
.

B

00

T

RCL 85STOEL
IMDEX "MATE"
RCL 894

ECL 15+
FCL 1&+

125 FCL 11
r'l_.l

O
O
O3
O
O
Fo

ek
Pk

i

Pt
ek

03
e

ek

LE s e
SN ST

ek
ek

03 PO1
oo 00 -"

ek

LASTA
TEAHS

ke

> STOELRECL "MATE"
RCL+ "MATA"
STO"MAT="FHEM

6: Statistics

189

b

)

e

My = I

-~

A

— ra

-b‘d-

B33

:.f. -'

Ao= I Neee

FJao D0 QO Q0 g Q0

i

2

+ BE

LASTH
RCL 18KO

1-

L

solution menu.

nEn

EEY

M2

—

ek
ek
ek
ek
ek
ek
ek

Lines 148 -164: Build and display the"H"
KEY 1 RER 21

HER 22" I:: "

KEY

=ERN 232

n ['I "

KEY 4 HED 24"R
KEY 5 XER 25

ek

ek@ LBL &8z

oo N nonoc[ N N in N Jau S(T
00 a0 0 =) T N e O O I W0 )

=

143 +
144 STO "R2"
145 CLD
146 FS7 S5147 SF 21

ek

n T'-_,l n

b

b
ek

n

(T
i
T
i
0

T
=)

ek
ek

oW
[y

ek

=g =T

Pk

GTO 82

B

4

ek

b

STOF

U".

MEHMU

e

KEY 9 GTO &bek

KEY & HEQ 2

190

LEL 21

1

Subroutines 21-25, lines 165-192:

Display the calculated coefficients a,

gtb, c,d, and R2. If PRON has been exe-

GTO B3
LEL 22

cuted, print the coefficients (lines 187
and 191).

[
1 t' "

6: Statistics

waedle’

o3

.,.

oo

M

]
2

[ 5
AN
00

GTO
LEL :
4
lldll

LEL B
1
IMDER "MAT=A"
ol

ek
ek

ek

Pk

ok

ek

ek

ek

ok

ek

ek

ek

ek

ek

ok

ek

ek

ek

ek

ek

o o0 QD Q0 Q0 00 o 000D 00 QD Q=g = )My = = O~ TN b 03 PO e = o =y T N fa 03 [g

Pkev |_£|
et
oo
e e
oo
o et
goWa
P3O P )
M S
D

g
1)

-~
ek

oo 0 o 30 03 ) T N 0D

PO

GTO
LEL

STOIJ

RCLEL
'_II___II

ARCL ST =AVIEW
RTH
LEL 25
RCL "Rz2"
VIEW "R2"
RTH
LEL 26INDEX® "MAT="“EG 84

Subroutine 26, lines 193 -205: Forecast T based on the calculated
coefficientsa, b, c, and d. Display T

HER 04and, if PRON has been executed, print

AER B84

T.

+
+
I -—

RCLEL
+

STO wT™

VIEW "T"RETH

6: Statistics

191

-

EHD

Ma

late termsbx, cy, and dz.

RCLEL
RCL= ST T
RTH—

Subroutine 04, lines 206 -210: Calcu-

I-e

My P T g T
T=o T
Coou 0D ) i% LEL 64

To use MLR:
Press

SMER

Press

_to clear the summation registers.

Enter each data set, using the keystroke sequence t-value [ENTER
Z-value ([ENTER] y-value [ENTER] x-value @ ZPress CHLC.

. Press the corresponding menu keys to see the values ofvariables a,b, c,d, and R2.

To forecast 7, use the keystroke sequence z-value [ENTER] y-value
ENTER] x-value @17 .
7. To return to the main menu, press [EXIT].

Example: A Linear Regression For Three Independent Variables. Find the regression equation for the following set of data.
i11]12|3|4]|5

x| 7| 1|1nf11] 7
y 25|29 |56 |31]52
z| 6|15| 8| 8| 6
t, |60 |52|20|47 |33
Execute MLR.

x: 4.0800
Z+ E-JoE]| JeRLo]

192

6: Statistics

Clear the summation registers. Enterthe first data set, starting with thet-value.

EpETE
60 [ENTER] 6 [ENTER] 25 [ENTER]

7=Enter the second data set.
52 [ENTER]J 15 [ENTER] 29 ([ENTER]

x: 2.0800
I TS.TEnter the remaining datasets (the keystrokes are not shown here). Now
calculate the regression coefficients and the coefficient of determination.

CRLC

x: B. 9989

GG TS

Check the value of a.
a=103.4473
GN A
Check the value of b.
b=-1.2841
I BAO T
Check the value of c.
B

Check the value of d.

s

d=-1.3395
HFHEEFREESEEEEECE

Check the value of R2.

s[R2=8.9589

T GGTT

6: Statistics

193

Calculate T (the forecasted value of ¢ given values for x, y, and z). Use thevalues from data set #4.

8s -f T "‘-31

1(The actual value of ¢ in data set #4 is 47.) Return to the main menu andclear the statistics registers for new data.
CLE

x: 46.4616
Z+ Z- JCLE]JCALCH

Exit from MLR.
EXIT

Curve Fitting in Programs
The curvefitting functions FCSTX, FCSTY, SLOPE, YINT, CORR,

LINF, LOGF, EXPF, PWRF, and BEST are programmable.
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 plottedwith the 110 data pairs.

194

6: Statistics

Graphics and Plotting
The following topics are covered in this chapter:m Building graphics patterns.
m Multifunction plotting.
m Plotting statistical data from a complex matrix.

Graphics
The program HPLOGO in this section uses the XTOA and AGRAPH
functions to build the Hewlett-Packard company logo in the center of thedisplay.
To key in HPLOGO:
1. Assign the functions XTOA, CLA, ARCL, and XEQ to the
CUSTOM menu.
2. Create the variable BLOCK.

7: Graphics and Plotting

195

Here is the annotated listing.

Program:Comments:

CLLCD

Lines 02-04: Clear the display forgraphics. Clear flags 34 and 35 so thatgraphics placed in the display with
AGRAPH are merged with any
graphics alreadyin the display. (The
top and bottom halves of the logo arebuilt separately and merged in thedisplay.)

CF 34
CF 35

. o=

HER "TOP"
1
ENTER
46
AGRAFHwEG "BOT"

—

™
]
WO

oo
0o =goLn.E.

|'_-;3|

[0

™
1T

p—

[ax]

A6 * 441-Bute Pram >.11
LEL "HPLOGO"AGREAFHFTH-

2 ENTER

T
=J

=
=
o=
P
PP
FJ

P P [0 T

2NoF O [d e o0 20 =)

[y

on £

13 48

196

LEL "TOP"
CLA
e
et

“TOA
“TOA
“TOA
“TOR
“TOA
“TOR
H=ZTO

"BLOCE"

CLA

254

7: Graphics and PlottingLines 05-09: Call subroutine TOP tobuild the top half of the logo. Thendisplay the top half of the logo, starting at pixel (1, 40).
Lines 10-15: Call subroutine BOT tobuild the bottom half of the logo.
Then display the bottom half of thelogo, starting at pixel (9, 40).

Subroutine TOP,lines 16 —91: Build

the Alphastring that represents the
top half of the logo. (Begin by building
the Alpha string that represents an 8 x
6 block of on-pixels and storing thatstring in the variable BLOCK.)W oyW W W W W W M M
o =R WM 00D

ATOR
ARCL "BLOCK"
235
®TOA
63
“TOA
15
“TOA
v
“TOA
*TOA
3
ATOA
1
ATOA

129
RTOA
224
» »wTOR128

T

Jv @ I ™A ananan

T Nof W 00N R W» RTOA

62
XTOA
39
XTOR
161
KTOR
224
XTOA
96
HTOR
B
HTOA
1
HTOR
129
XTOR
225
XTOR

7: Graphics and Plotting

197

T
0D

00

00

00

00

00

0D

00

00

00

)

)

)

)

]

)

]

N

)

T
oD

o0 00 = M N 00 O e o0 00 =) M N f WM o= @ o0 00 )

WO

e

=
e
[0

O

- b e e 000 o0 0 O O
I 3 0 00 ) I N R O3 P

=
Fo

198

a7
“TOA
a3
“TOR
“TOA
35
*TOA
ez
“TOR
221
“TOA
1832
ATOR
15
“TOR
21
ATOA
53

“TOA
ARCL

"BLOCE"

2350
“TOA
254
“TOA
FETH
e

LEL "BOT"
CLA
127
“TOA
ARCL "BLOCK"
235
“TOR
232
»TOA
2408
»TOA
224
“TOA

7: Graphics and Plotting

Subroutine BOT,lines 92— 156: Build

the Alpha string that represents thebottom half of the logo.

185
185
187
188
189
116
111
112
113
114
115
116
117
118
119
128
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

“TOR
192
“TOA
198
®TOA
135
»TOR
129
XTOA
XTOA
“TOAR
XTOA
xTOAR
129
®TOA
224
®TOAR
126
XTOA
30
XTOR
XTOA
xTOR
122
XTOA
®TOR
xTOR
198
XTOR
199
*TOR
225
xTOAR
224

7: Graphics and Plotting

199

144 XTOA
145 248
146 XTOA147 243
148 HTOA
149 252
156 XTOA
151 ARCL "ELOCK"
1 C; oo coSt

53 HTORA
4 127
S WTOA
S& RTH

1537 EHMD

Example: Building a Logo. Display the Hewlett-Packard logo. If you
have a printer, modify HPLOGO to print the logo. Then printit.
Execute HPLOGO.
[ﬁa

HFELO

Insert the instruction PRLCD after line 14 of HPLOGOto print the logo.

@(PRGM] B(GTO] (] 14(V] FRLECD

Print the logo.

BPRINT] (A] FOH

Y: 9. 0000

x: 48. 08800)

I[%@il

HFLD
Using Binary Data to Build a Graphics Pattern. To build thelogo in the previous example, you had to calculate the column print
number for each of 91 columns - a time-consuming effort. The following
program, BINDATA, calculates the column print number when you input
the equivalent sequence of binary numbers in a column pattern.

200

7: Graphics and PlottingProgram:{Comments:

68-Byte Pram

2

I
Uv
2I

D
S
DT
e
e
e
e

e 0 o= S20 = O On

CF =4
CF 35
EIHM

Lines 02-04: Clear flags 34 and 35.
Set the calculator to Binary mode.

LEL 8@
CL¥
STOP

Lines 05-15: Clear the X-register andsuspend program execution for binary
data entry (lines 06—07). Build an
Alphastring of five spaces (line 08).
Testif the binary data (converted todecimal form) is greater than 126. If

126
KO
WY
GTO &1
XTOR}_ nn

corresponding HP-42S Alpha character in quotes and append two spaces
to the Alpha register.
Lines 16 -25: Append the number inthe X-register (the decimal equivalentof the binary data) to the Alpha register and display the current contents of
the Alpha register (lines 17-18). (TheAlpha register contains the decimal
number equivalent ofthe binary data.
If that number is less than 128, the0
JaoAlpha register also contains thecorresponding HP-42S character,enclosed in quotes). Build theequivalent column pattern and display
it, beginning at pixel (1, 66) (lines
20-24). Return to label 00 for the
next data entry (line 25).

MPso, go to label 01. If not, enclose then

LEL &1AHIF
AYIEHN
CLAH
ATOR
1
EHTEFE

PO
00

[
[0

Tl ) o
—w0

=
00

e
=] T

e

Foo 03 [0LEL "EIMDATAR"

EHL:

7: Graphics and Plotting201

To use BINDATA:

1. An on-pixel has value 1. An off-pixel has value 0.
2. Enter digits beginning at the bottom of the column.
3. If, for example, you enter only six digits, the bottom two digits areinterpreted to be zeros.
4. Press
after data entry to see the calculation. After the calculation is displayed, simply key in the next sequence of numbers when
you are ready.

Column # 16

cOONEEERQO

O
O
O
a
a
n
u
n

JOEBEEROOO

Example: Using Binary Data to Build a Logo. Columns 16-18 of
the Hewlett-Packard logo in the previous example have the following pixel
patterns.
Last Digit EnteredFirst Digit Entered

Use BINDATA to calculate the column print number for each column.
Start the program.
x: @#...F[HEXM[DECH[OCTH] EINe [LOGICEnter the binary data for column 16.
11100000

202

7: Graphics and Plotting

224

The column print number for column 16 is 224. There is no equivalent
Alpha character. The column pattern is at the right of the display. Now
enter the binary data for column 17.
01111000 (R/S]

"x"

128

The column print number for column 17 is 120. The equivalent HP-42S
characteris "x". (You can therefore either accumulate 120 in the Xregister and execute XTOA, or accumulate character "x" in the Alpharegister. The column pattern is at the right of the display. Enter thebinary data for column 18.
00111110 (R/S]

"Toe2

I

The column print number for column 18 is 62. The equivalent HP-42S
Alpha character is ">". Now exit from the program.
EXIT

v: 1.00800
x: @.0000(Referto the character table in your owner’s manual (appendix E) andnote that five of the first 127 characters cannot be typed from the HP-42S
keyboard. The character codes are 4, 6, 13, 27, and 30. Program

BINDATA shows you the character corresponding to each of these codes,
but because these characters cannot be typed, you must accumulate thecorresponding character code in the X-register and execute XTOA.)Multifunction Plots
The program PLOTS3 in this section enables you to plot up to three functions concurrently on the HP 82240A Infrared Printer. It is based on the
program PLOTin the section "Example Programs" in chapter 10 of yourowner’s manual. As in PLOT, you supply to the program the name of theroutine that defines the function you wish to plot. However, in PLOTS3,
you can supply up to three routine names.

7: Graphics and Plotting203

Here is a flowchart for PLOT3.

&

PLOT3

USE VARIABLE MENU TOSTORE PLOT PARAMETERS(YMIN, YMAX, AXIS,XMIN, XMAX, XINC)v
INPUT FUNCTIONROUTINE NAMESv

PLOT HEADER INFOAND INITIALIZEv
SET INITIAL x-VALUE
LBL
00
CLEAR DISPLAYYNO|LABEL AXIS

<«
@ YES

;

NO

204

7: Graphics and Plotting|DRAW AXIS

OR EACH PIXEL ROW(1TO 16)v

A

PRINT DISPLAY

v

|
|
|
|
|
|
|
|
|
|
|
|
|

FOR EACH FUNCTION+AEVALUATE f(x)INCREMENTX - VALUE

PLOT PIXEL|PRINT FINALDISPLAY

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

¥

-——=(

NEXT FUNCTION-=—(NEXT PIXEL ROW

To key in PLOT3: Create variables YMIN, YMAX, AXIS, XMIN,
XMAX, XINC, FCN1, FCN2, and FCN3 before program entry.

Here is an annotated listing of the program.
Program:Comments:

B8 £ 424-Bute Fram
@1 LEL "FPLOTZ"
BE_'

H'-.-'HF:" -.I.-H I H n

B3 MYAR YA
B4 MYAR "AXIS"

Lines 02-07: Declare the menu vari-ables.

A5 MYAR "sMINY

BE MVAR HMAR"
a7 MVYAR "RIHCY

7: Graphics and Plotting

205

.

CF 33
> CLA
STOF
“ITALL

LToCn

-

=

CF =24

Lines 08 - 14: Display the menu andsuspend program execution for data
input.

03
£

s
M

=
o

=
00 00

LEL A
VARMEWLD "PLOTE""FCH1"HER @717 "FCHzZ"

Lines 15-20: Promptfor the function
names (the subroutine labels).

& HER @7

"FCHE"HER 87
AL"Flot of:"
PRA
FI [,I "l"

on
()

O

o=

Ju O Oo0 00—

G

D

D0
Lo

O
0

Dl
[0

0
e

e O
50

[
0

SF 12
RCL "FCHL®
HER B8206

FECL"FCHZ"HER B8
RCL "FCHE"HER B8ACY
CF 12
PRY "MIN"
FRY "YHAR"
PRY "AHIS"
PRY "HMIN"
FRY "HMAR"
FRY "HINC"
ADY" YMINYke
PHA StFRA

7: Graphics and PlottingLines 21-43: Print the header information. (In line 42, there are sevenspaces in the Alpha string before
YMAX.)

1200~ O O G0 O e

LEL 86
CLLCD
FC? B0®ER B3
FC? &1RER B&
1.81:
sSTO @2

Lines 51-58: Clear the display. If flag
00 is clear, label the x-axis. If flag 01 isclear, draw an axis. Build a loop
counter corresponding to the 16 rows
in the display.

LEL @1
43,851
ST0O Bz

Lines 59-61: Build a loop counter forthe three possible functions. (Thekee’Lines 49— 50: Store the first x-value.

—

RCL "s®MIN"
STO 81on ononoonodn on onoon

Lines 44 -48: Calculate the relative yvalue of one pixel.

T n
L
w0
ke

43 RCL “YMAX"» RCL= "YMIH"

character codes for characters "1", "2",

2N

O3

o

LEL &2"FCH"
RCL 62+TOR
ASTO ST X
RCL

STR?
HER
120G

IMD ST =

....
1= I
T 30

e

O N e O3T
T T T T T
=gg
o0 00 )and "3" are 49, 50, and 51 respectively.
Routine 02 uses these numbers tocreate the variables.)GTO
RCL "HIMC®
16
STO+

81

Lines 62-83: Create the Alpha strings
FCN1, FCN2, and FCN3 successively.
Call each string to the X-register, thenrecall to the X-register the variable
that matches that string. Test if thevariable has an Alpha string (a function program name) in it (lines 62—68). If so, plot a pixel for each function. Increment the x-value. If the plotis complete (if x-value > XMAX), go
to label 03. If the current display iscomplete (if rows 1-16 are filled),
then print the display and start a newone.

7: Graphics and Plotting207an) 00 03 0~
Wra -3 w00 -l T

) 0O O 0=~

LEL B2FRLCD
RETH

W ou o WO w0 ooD 0 WO 0D Q00 =] T n Fo0d Mo W0 00

LEL o4
RCL 81HKER IND ST ¥

=
—

+

CF 24
RCL 82
nlxy

W @7

ek
1ol

n

ek

1T

SF 21
RTH

ek

ARCL &1
AVIEW

o=

.

CLA

= =

Subroutine 04, lines 88— 101: Evaluate
the function at x and plot theappropriate pixel.

SF 24
RCL- "YMIH"
RCLx B8
1

2 LEL a5
2 CF 21Pt

Lines 84 -87: Print the final display
and stop. (Line 87 enables you to restart the program by pressing [R/S].)

GTO A= = W00

RCL "xMAR"
RCL &1
wey?
GTO &3
ISG a2
GTO &1
FRELCD
GTO aa7: Graphics and Plotting

Subroutine 05, lines 102 - 108: Labelthe x-axis.

LEL 8&
1
RCL "RRIS"RCL- "YMIHN"
RCLx @&+./=
1

Subroutine 06, lines 109 - 123: Draw
the axis. (In line 120, the Alpha string
is five "multiply” characters: press

B(ALPHA] (] (x] (x] (] (x] (ENTER].)

FIXEL
+/_

=
—

"aesnena !
AGREAFH
RTH
LEL &7
CF 21» ASTO ST L
CL¥
AVIEW
FZE
CLA
-t

Lines 124 -146: Prompt for an Alphastring (function name). If the variablealready contains an Alphastring, thatstring is recalled to the Alpha registeras the default.

e
e

SF 21
SF 25
RCL IHD =
CF 25
STE?
ARCL ST =
ACOH
CLD
STOR

[N ]
-

b
d
b
b
ek
ek
ek
ek
ek
ek
ek
ek
ok
ek
ik
ek
ek
ek
ek
pk
Pk

-

£ oo Q3 00 Q0 0 O O 0 0 O 0 O M) M My M
M = o0 00 =g 1T on Fo 00 O o0 00 =) T n £MY PP g o
0 g e W0'

AOFF

£ HLEHG
143 nEAT
144 AZTO =7: Graphics and Plotting

209

STO

IMD =T L

FETH
LEL &=» CLA

STR?
ARCL ST ¥
STR?
z FRA

Subroutine 08, lines 147 -153: Print
the function names.

FTH
EHD

To use PLOT3:. Execute PRON and turn on your Infrared Printer.
Write a routine for each function that you want to plot. The current
x-value is in the X-register when the program calls the function routines. The routines need not recall the current x-value to the Xregister.
. Set the display format to ALL.
Start the program (press

FLOTZ).

Supply the plot parameters. For example, specify 20 for YMIN bypressing 20 WMIH .
. After supplying values for the plot parameters, press [R/S].
a. As prompted, store the name of each function routine in afunction variable. For example, to supply the name TAN for
FCNI1, press TAN
at thefirst prompt.
b. If you have already supplied a routine namefor a function
variable, that name is displayed at the prompt. If you want toleave that name in the variable, simply press (R/S].
c. If you want to plot only two functions, supply names for only
two variables. Leave the Alpha register clear for the third
variable (just press
when prompted). If a name isdisplayed for the third variable, press
to clear the Alpharegister, then press [R/S]. If you wantto plot only one function, supply a name for only one variable and leave the Alpharegister clear (or clear it) for the other two variables.

210

7: Graphics and PlottingExample: Plotting Multiple Functions. Use PLOTS3 to plotthe following functions.
1. y = sinx
2. y = 0.35(Inx) (cosx)

1203

Do o| =g=

First, write routines to describe the functions.
£

9-Bute Pram

2

LEL "SIHE"
SIN
EHD

.._
v

Comments:

L 27-Bute Praom
LEL "LHCOz"

Lines 04-05: Ensure that the program
does not attempt to execute In (0).

—

e’

Pt

o

e’
-

-

T+AN]

oyI

o|

o~

[I

o]

[

1o

o)

1L

™
T LN e O3 O ]00 =] io oD

Program:

EHD

Set the Display format to ALL. Execute PRON. Clear flags 00 and 01 to
draw and label the x-axis. Start PLOT3.
ALL@FRINT) @) FOH< 0

ITRIR BRIB LT

BFLAGS) WFLAGS)FLOTZPlot y-values between —3 and 3, and set the axis aty = 0.
3YMIH
3 VYMAR

0 AXIS

AX1S=0I ETIFS IRBRI ETRTETS

7: Graphics and Plotting211

Plot x-values between 0 and 720 in increments of 60 per display.
XINC=68
IEICTSETRYICRIEBTNETREE ECTSupply the program name SINE for the first function variable.

SINE

SINE_
[RECOE]FGHI LMNOPi: [RETUN]bit2)

Supply the program name LNCOS for the second function variable.
LNCOS

212

7: Graphics and Plotting|LNCDS_ITSITSTR(T[Leave the Alpha register clear for the third function variable and start theplot. The printer output is shown here.

RS] R/S)

Plot of:ﬁ‘\:>\

SINE
LNCOS
YMIN=
YMAX=
AXIS=
XMIN=
XMAX=
XINC=
¢ YMIN

-3
3
8
9
728
60

@

YMAX 3J s\\-.

68

T

128

o

T /

158 (A
240

f-.T

388

N T

350

T

420

TN

;}

sek
6o T
668
_
728

T e
L

N

Exit from the program. Return the display format to FIX 4.

EXIT
B(DisP]ENTER

v: 720. 0000
x: 723. 7500

7: Graphics and Plotting

213

Plotting Data from a Complex Matrix
In previous programs, you have used:m PIXEL to turn on individualpixels in the display. You specify the
pixel number in the X- and Y-registers (row number in Y and column
numberin X).
= AGRAPH to display a graphics pattern. You specify the location of
the pattern in the display by placing a pixel number in the X- and Yregisters (row number in Y and column numberin X).
PIXEL and AGRAPH operate on the numbers in the X- and Y-registers.
The efficiency of these functions is enhanced by enabling them to operate
on a complex matrix in the X-register, where each element of the complex
matrix has the form
x-value + iy-value
When such a matrix is in the X-register, PIXEL turns on each pixel in thedisplay as specified by the elements in the matrix. For example, consider
the following complex matrix.
1+i10

5+:i2010+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.

214

7: Graphics and Plotting

Similarly, AGRAPH places the graphics pattern that is encoded in theAlpha register at each position in the display as specified by the elementsin the matrix.
Note that PIXEL and AGRAPH operate on the rectangular form of thecomplex matrix. Before entering numbers into the complex matrix, set theangular mode to Rectangular.
The program PFIT in this section plots the individual data pairs from thereal n X 2 matrix in the X-register, then fits and plots a curve to that datausing the currently selected statistical model. PFIT creates one complex
matrix and executes AGRAPH to mark each data point with a "+" character. PFIT then creates a second complex matrix and executes PIXEL toplot the forecasted curve.

7: Graphics and Plotting

215

PFIT
STORE THE (DATA)MATRIX IN DATAMTXvv

INDEX DATAMTX

XEQ MM TO FIND MIN
AND MAX VALUES, THENCALCULATE SCALINGFACTORS

v

PLOT
AXES

v

STORE DATA FROMDATAMTX IN SUMMATIONREGISTERSv
BUILD PLOTTING
MARKER216

7: Graphics and Plottingv
SCALE EACH
X AND y VALUEv

CREATE COMPLEX MATRIXOF x AND y VALUESv[ PLOT THE DATA POINTS |ICREATE 1 X 22 TEMPORARY
MATRIX AND FILL IT WITH
x -VALUES 1-22

FOR EACH SET 1-6
OF 22 x -VALUESA!

PRINT THEDISPLAY

|

:|
|

I

|

&
(END)
.
|
|
|
|

!

|

|[FORECAST 22 y -VALUES |[SCALE EACH x, y VALUE |YCOMBINE x, y MATRICESINTO A COMPLEX MATRIXv
PLOT 22 PIXELS(DRAW THE CURVE)

To key in PFIT:
1. Create variable DATAMTX before program entry.
2. Create label MM when you begin program entry.

7: Graphics and Plotting217

Here is an annotated listing of PFIT.
Program:Comments:

G2 CF
B4
5
&
av
a3
a9
18
11
12
13
14
15
1e
17
18
19
2a
21
22
23
24
23

218

— W w

Bae { 295-Bute Pram X
a1 LEL "PFIT"

4

CF 2
REC
STO “"DATAMT="INDEX "DATRAMTR"

Lines 02-06: Clear flags 34 and 35.
Store the matrix thatis in the X- register in DATAMTX and index
DATAMTX.

#“EG@ "MM"STO B2

Lines 07-13: Call subroutine MM tofind the minimum and maximum xvalues. Then calculate the x-value scal-

128

ing factor.

STO a1
STO+ @z

REQ MM"oy
STO 8413
ney
STO @3
STOx 84
2
STO- 84
STO- B2

7: Graphics and PlottingLines 14-25: Call subroutine MM tofind the minimum and maximum yvalues. Then calculate the y-value scaling factor.

O
O
00

I_T'l
-]

0D

CLA
EI

XTOR
7
XTOA
HE>Y
“TOR

[

o
00

oD

IREG 11
CLE
RCL "DATAMTAH"
I+

Ja
Fo

e P P 03 00

O3

b

O3 0 0 O P D P Ma
W rao= 0=~ i» CLLCDFCL a4nra?
RCL= ST =RCL &2
nra?
CL*
FI=EL

45 RCL "DATAMTH"
46 TRAMS
47 STO "DATAMTH"
48 IHDEX “"DATAMTH"
49 DIM?
56 1
51 N>
52 GETH
53 DELR
54 RCL+ @1
55 RCL- @2

Lines 26 —33: Plot the axes.

Lines 34-37: Store the data in

DATAMTX into the summation registers.

Lines 38 —44: Build the "+" character(used to mark each data point in theplot).

Lines 45-55: Make the matrix 2 X n
and index it (lines 45-48). Make two
1 x n matrices, where the matrix in theX- registeris the x-values, and thematrix in DATAMTX is the y- values(lines 49 -53). Convert the x-values toscreen coordinates for plotting (lines
54-56).

7: Graphics and Plotting

219

56
57
52
59

RCL "DATAMTE"
RCL® @3
RCL- &4
COMFPLEX

Lines 56— 59: Convert the y-values toscreen coordinates (lines 56— 58).
Convert the matrices in X and Y toone complex matrix in X, each element of which is: x-value + iy-value(line 57).

68
&1
&2
63
&4

1
EMTER
COMPLEXAGREAFH

Lines 60— 64: Subtract 1 + i1 fromeach value (to set the center of the "+"character at the data point) (lines
60-63). Place the center of the "+" atthe coordinates defined by each element of the matrix (plot the data
points) (line 64).

&3 RCL "REGS"
65 1&7 EMWTER

Lines 65-69: Recall the registers
matrix to the X-register, and redimension it to a 1 X 22 temporary matrix.

B2 22
23 DIM "REGS"e 21
71 LBEL 81
72
ra
¥4
Yo

STO
DSE
GTO
STO

IHD =T
ST W
@1
&8

TE Rt
77 RCL "REGS"TE OHOEY

79 5TO "REGS"=8 Clw

220

Lines 70-75: Fill the temporary
matrix with values 0 through 21.

7: Graphics and PlottingLines 76 —80: Store the data from theregisters back into REGS, then clear
the X-register.

T

+ =

o0 OO Q0
O

n
|:I".

00
D0
Q0

Joooo

o0

O

0D

00

T N e O3 [ o o0 0D =~OO

LEL @&z
EHMTER
RCL+ @z
RCLx

@1

FCSTY
RCLx

Lines 85-102: Forecast y-values for aset of 22 x-values, make a complex
matrix ofx-y data pairs, and plot eachdata pair. Repeatfor five more sets of
x-values.

832

RCL- B4COMPLERFIXELCOMPLE®RF+soyI o]
M -

=G0
o0 00
1

s
=~

o

Lines 81 -84: Establish a loop counter
6.00000 in the Y-register. Change thevalues in the temporary matrix to 1
through 22. (These values represent
the first set of 22 x-values.)

DSE ST ¥GTO @2PRLCD
CLY "DATAMTH"eindex pointer at the top of a column.
At the end of the subroutine, theoSS
LN B OeFs? V&

TO
0 0D =]T

Subroutine MM,lines 103 -120: Find

= =
T

—
—

[

LEL "MM"
RCLEL
ENTER
- LEL @9I+[e

2 RETHRTH
RCLEL

the maximum and minimum elementsof one column of the matrix for scal-

ing. At the start of the subroutine, thematrix DATAMTX is indexed with theminimum element of the column is in
X, the maximum elementis in Y, andthe index pointeris at the top of thenext column.

7: Graphics and Plotting

221

11e
117
118
112
128

ROEY
R+
RCL ST 2
GTO @9RTH

121 EMD

To use PFIT:

1. Select a statistical model. For example, press B[STATF.
2. Place a 2-column real matrix of data pairsin the X-register.

3. Press

FEIE

Example: Plotting Data from a Compression Process andFitting a Power Curve to the Data. Many compression processes
can be correlated using the power curve
P =qV?
where:

P is the pressure.
V is the volume.
-b is the polytropic constant.
Enter the following pressure-volume data in the £LIST matrix.
Then use PFIT to plot the data and to plot a power curve to the data.

222

7: Graphics and Plotting

v

P

10
30
50
70
90

210
40
12
9
6.8

Execute program LIST. (If you've deleted the program, you need to key it inagain. The listing is in section "List Statistics" in chapter 6.)%: 0. 0000
(N(VYI..G
Clear the XLIST matrix, then fill it with the data.
210 [ENTER] 10

SLIST=[ 5x2 Matrix J(Y[IN.T

40 [ENTER] 30
12 ([ENTER] 50

9 [ENTER] 70 |6.8 [ENTER] 90 |Exit from LIST. Recall £LIST to the X-register.
v: 98, 60600
x: [ 9Sx2 Matrix 1]

BSTAT)(B(PRINT] (4]B(TOPFCN(

Set the statistical model to a powerfit. Execute PRON if you have aprinter. Execute PFIT.

Exit from PFIT. Check the correlation coefficient for the data.

EXIT] CORR

x: =@, 9939
(R(STNT[TThe correlation coefficient is —0.9939. Check the value of —b.

SLOFE%: -1.6152(ISRTSIIX

The value of -b is —1.6252. Exit from the STAT menu.
EXIT]

[EXIT

y: -0.9939
x: -1.6152

7: Graphics and Plotting223

IndexSpecial Characters¥+ function
emulating in LIST program, 176
in programs, 182
stores data from 2-column
matrix to summation registers, 149, 181, 175
LFORM program, listing of, 181
YLIST matrix
filling column 2 with evenly
spaced integers, 181
in curve fitting example, 220
in LIST program, 176
redimensioning to nm x 2, 181

addressing
AGRAPH functionin HPLOGO program, 195
operates on complex matrices,213

Algebraic solution. See Explicit
solutionsAngle of twist equation, 131, 125
Approximating an integral that has
an infinite limit, 127 -130

Asymptote, Solver results with,117

Ead Gues=s{=s) message, 120A
ACC variable. See Accuracy factor
Accuracy factor
affects Integration calculation
time, 130

definition, 134
effect on calculation time, 137

in basic integration, 124related to uncertainty ofintegration, 135
Addressing. See Indirect

224

Index

Binary data, building a graphics
pattern with, 200-203
BINDATA program,listing of,201
Branching, 21 -39
conditional, 22 -25

emulating a multirow menu with
KEY GTO, 34-37
emulating a nested menu with
KEY GTO, 37-39
menu-controlled, 29 -39

types of, 21

C

Controlled looping, 39-43
definition, 39
DSE function in, 39
GTO function in, 39

Calculation time
for an explicit solution, 100
for Integration approximations,indirect addressing with, 43

129-130
for the Solver, 99

Integration conditions that prolong, 143 -145
Case 1 and 2 (Solver) solutions,
how to differentiate
between, 110

Case 1 (Solver) solution,
definition, 109
Case 2 (Solver) solution,
definition, 109

CIRCUIT program, listing of, 87
CLEAR program, listing of, 44
Cocfficient matrix. See MATA
Column norm of a matrix, 151
Column sum of a matrix, 150-151

Complex numbers. See Emulating
the Solver; HP-41 programs,enhancing with HP-42S datatypes; Simultancous equations, complex-number
Compression process equation,
220
Conditional branching, 22 -25
based on a number test, 24

CONE program, listing of, 81
Conjugate of a complex matrix,
151

Constant matrix. See MATB
Const ant ? message, 121Constant velocity equation, 39
Controlflags, 47
definition, 47

INPUT IND in, 43
ISG function in, 39

STO IND in, 44

XEQ IND in, 45
COORD program, listing of,
158 -160
Coordinate transformations,156-163
Correlation coefficient, 221
Curve fitting in programs, 194
CUSTOM menu, executing programs from, 73, 19

D
Data input, prompting for in a
program, 68, 15

Data output, displaying in a program, 68, 16

Declaring variables. See MVAR
function
Directing the Solverto a realistic
solution, 80— 82
Discontinuous function, Solver
results with, 113 -114
DISPL program
flowchart for, 40

listing of, 41
Displaying program results. See
Data output
DSE function, in a controlled
loop, 39

flag 21 used to control VIEW
and AVIEW functions, 47,

16

Index

225

E

trapping, 50

EIZ program, listing of, 89—-90
Electricalcircuits. See Simultaneous Equations; Emulating
the Solver
Emulatinga multirow menu, 34-37
a nested menu, 37-39
Y+ function, 176
the Solver, 86-91
END function, 15

Error trapping, 49-50
Examples, displays in the manual
may differ from yourdisplays, 10
Executing a programfrom the CUSTOM menu, 73,

19from the program catalog, 19with the XEQ function, 73, 19

Explicit solutions
calculation time, 100
faster than iterative solutions, 92

Enhancing HP-41 programs, 67—
76
Equation(s)angle of twist, 131, 125
asymptote, 119

compression process, 220
constant acceleration due togravity, 83
constant velocity, 39ideal gas, 101, 78

localflat region, 121loop current, 166, 169, 163
math error, 120

multiple linear regression,
182-183
Ohm’s law, 86, 88

pole, 116
relative minimum, 118setting equal to O for the Solver,
105, 77
sine integral, 136
SSA (triangle solution), 22
SSS (triangle solution), 13
time-value-of-money, 92
triangle solutions, 58 - 59
van der Waals, 101

volume ofthe frustum ofa rightcircular cone, 80

Error Ignore flag, used in error

226

Index

for complex numbers, 88
using with the Solverin programs, 92 -100
E:t remum message, 117
F

FCAT program
flowchart for, 52
listing of, 53-56

uses programming concepts discussed in chapter 2, 51
Finding more than one solution
with the Solver, 83 -85

Flag 21and PROFFfunction, 16
and PRON function, 16

effect on VIEW and AVIEW
instructions, 47, 16

Flag 25, used in error trapping, 50
Flag 77, used in MINMAX program, 47

Flag tests, follow do-if-true rule,46
Flags, 4657
control, 47

current status maintained byContinuous Memory, 47

Error Ignore, 50
general purpose, 46 —47
have unique meanings for the
calculator, 46

listing of in appendix C ofowner’s manual, 46

Matrix End-Wrap, 47
Numeric Data Input, 93
Printer Enable, 47, 16
system, 47 —48
user, 46 —47

Flat region, Solver results with,
121

Flowchart
definition of, 13
for DISPL program, 40
for FCAT program, 52
for GAS2 program, 102
for MLR program, 184
for PFIT program, 214-215
for PLOT3 program, 204 - 205
for SSA program, 23
for SSA2 program, 27
for SSS program, 15
for TRIA program, 30-31
symbols for, 15

G
GAS program, listing of, 78
GAS?2 program

flowchart for, 102listing of, 103 -104
General purpose flags, 46 -47
definition of, 46

in LIST program, 47
in MINMAX program, 48
Global label, defines start of aprogram, 15

Graphics, 195-203
binary data to build, 200-203

GTO function, in a controlled
loop, 39

H
Horner’s method, 125
HP 82240A Infrared Printersome examples include optional
instructions for, 11
HP-41 programs, enhancing, 67 76
with HP-42S data types, 69
with INPUT function, 68
with menu variables, 71-73
with named variables, 67 — 68

with the two-line display, 69
with VIEW function, 68
HPLOGO program, listing of,
196-200

Ideal gas equation, 101, 78

Improperintegral, definition of,
127

Incorrect results in Integration,
140-143
Indexing (matrix) functions, 146 154

Indirect addressing, 43 45
clearing storage registers with,
44
controlled looping with, 43
executing subroutines with,45
initializing data storage registers
with, 43
INPUT function with, 43

SOLVE and PGMSLYVfunctions with, 101-105
STO function with, 44
XEQ function with, 45

Index

227

Infinite limit, approximating an
integral that has an, 127 130
Infrared Printer.
some examples include optional
instructions for, 11
See also Printing
INIT program, listing of, 43
Initial guesses, for the Solver,

80-85
INPUT function, 15

brings up variable catalog in
Program-entry mode, 17enhancing HP-41 programs
with, 68
indirect address with, 43

Integration, 124 -145
ACC variable in, 124

accuracy factor and uncertainty
of integration, 134-139
approximating an integral thathas an infinite limit, 127 130
basic use of, 124 -127

calculation time for approximations, 129-130

conditions that can cause

and Integration, 131 -133
and Simultaneous Equations,168-172

Interpreting the results of theSolver, 108 - 122
ISG function, in a controlled loop,

39

K
KEY GTO function
emulating a multirow menu
with, 34-37
emulating a nested menu with,
37-39
to build programmable menu,
29
turns on VA annunciator whenassigned to menu key 7 or 8,
34
KEY XEQ function
to build programmable menu,
29
turns on VA annunciator whenassigned to menu key 7 or 8,
34
Keying in programs, helpful hints
for, 17

incorrect results, 140 —143

conditions that prolong calculation time, 143 -145
limiting the accuracy of, 134

Keystrokes, required to execute a

LLIM variable in, 124
more on how it works, 134 -145

L

MVARfunction in, 124

LIST program

Solver and, 131 -133

subdividing the interval of
integration, 142 -143
ULIM variable in, 124

uncertainty of. See Uncertainty
of integration
Interactive use of the Solver

228

Iindex

program, 19-20

accumulates statistical data forplotting, 220
emulating £+ function in, 176
fills XLIST matrix with x-y data
pairs, 176
general purpose flag in, 47
listing of, 176 -179

matrix operations in, 172
List statistics, 175-182
LLIM variablein basic integration, 124solving for with the Solver, 131
Local maximum or minimum,
Solver results with, 117
Loop current equations, 166, 169,

163
LVL1 program, listing of, 38 -39

geometric calculations with vectors, 154-156
interactive use of indexing utilities and statistics functions,149-150
matrix editor and indexing functions, 146 -154

matrix operations in statistics
and graphics programs,
172-173

matrix utility programs, 150 154
solving simultaneous equations,
MATA matrix
in MLR program, 172
in Simultaneous Equations
application, 164
solving for an element of, 168
MATB matrix
in MLR program, 172
in Simultaneous Equations
application, 164
Math error, Solver results with,120
Matrices, 146173

coordinate transformations with
vectors, 156-163

creating a named matrix, 147
filling a matrix element with an
Alphastring, 147
finding the column norm of amatrix, 151

finding the column sum of amatrix, 150-151

finding the conjugate of a complex matrix, 151
finding the matrix sum of amatrix, 151

finding the maximum andminimum elements of amatrix, 152 -153

163-168

sorting a matrix, 153 - 154
vector solutions, 154-163
Matrix editor, 146 —154

Matrix End-Wrap flag, in MINMAX program, 47
Matrix sum of a matrix, 151

MATX matrix
in MLR program, 172
in Simultaneous Equations
application, 165
Maximum and minimum elementsof a matrix, 152-153
Menu

multirow, emulating in a program, 34-37

nested, emulating in a program,
37-39
programmable, 29
MENU function, 29

Menu keys, 29
Menu variables
enhancing HP-41 programs
with, 71-73
to simulate the Solver, 88

Menu-controlled branching, 29—
39
Messages

Index

229

Bad Guessiesi; 120
Constant?, 121
Extremum, 117
Out of Ranas, 49
Festricted Operation, 56
Sian Rewer=sal, 115

MINMAX program,flags in, 47
MLR program
flowchart for, 184listing of, 186 -192
matrix operations in, 172
MOTION program,listing of, 84
Multifunction plotting, 203 -213
Multiple linear regression, 182 194
Multiple-linear-regression
equations, 182183
Multirow menu
VA annunciator in, 34(¥] and (4] keys in, 34
emulating in a program, 34-37
MVARfunction
defines variables in Integration
programs, 124

defines variables in Solver programs, 77

Neighbors, 109
Nested menu, emulating in a program, 37-39
Notations, consistent with owner’s
manual, 10

Numeric Data Input flag, 93

0
Ohm’s law equation, 86, 88
Jut of Range message, 49
PParabolic equation. See
Equation(s), relative
minimum
PFIT program

flowchart for, 214-215
listing of, 216220
matrix operations in, 173
PGMSLYVfunction, indirect
address with, 101 -105

PHONE program,listing of, 45
PIXEL function, operates on complex matrices, 213
PLOT3 program
flowchart for, 204 -205

listing of, 205-210
Plotting, 203 —-222
multifunction plotting, 203 -213
plotting data from a complex
matrix, 213 - 222
Pole, Solver results with, 115
Printer Enable flag, 47, 16

Printing
HPLOGO program results, 200
optionalinstructions for, 11
PLOT3 program results, 212
Q3 program results, 74
SSS program results, 33
PROFF function, and flag 21, 16
Program catalog
executing a program from, 19
globallabels placed in, 19
Program listingfor BINDATA,201
for CIRCUIT,87

230

Index

for CLEAR, 44
for CONE,81
for COORD, 158-160
for DISPL, 41
for EIZ, 89-90

for FCAT, 53-56
for GAS, 78
for GAS2, 103-104

for HPLOGO, 196 —-200
for INIT,43

for LIST, 176-179

programs, 194

defining the program, 15
displaying results, 16error trapping, 49-50
flags, 46 —57
helpfulhints for keying in programs, 17
indirect addressing, 43 -45
prompting for data input, 15
simple programming, 12-21
Solver and explicit solutions infor LVL1, 38-39

programs, 92 -100

for matrix utility programs,
150-154

Solver in programs, 92 -105

for MLR, 186192

summation-coefficient functionsin programs, 182 -194

for MOTION, 84
for PFIT, 216-220

for PHONE,45
for PLOTS3, 205-210
for Q2,69-71

for Q3,72-73
for QSHORT, 75

for ROW1, 35-37
for ZFORM,181
for SHAFT, 132
for SIMUL, 170

for SSA, 24-25
for SSA2, 28-29
for SSS, 17-18

subroutines, 26 —29

Programs

executing from the CUSTOM
menu, 19

executing from the program
catalog, 19
executing with XEQ function,
19
keystrokes required to execute,
19-20
Prompting for data input. See
Data input
PRON function, and flag 21, 16
Providing initial guesses for the
Solver, 80-85

for TORQUIEE,126

for TRAP (revised), 50
for TRIX., 60-65
for TVM2, 93-99
for XVALS, 182

Programmable menu
definition of, 29
in TRIA program, 32
Programming, 12 - 66
branching, 21 -39
controlled looping, 39 -43
curve fitting functions inQ
Q2 program,listing of, 69-71
Q3 program, listing of, 72-73
QSHORT program, listing of, 75

Index

231

RCL function, brings up variable
catalog in Program-entry
mode, 17

Realistic solution, directing theSolver to, 80— 82

Redimensioning ¥LIST matrix,
181
Regression, multiple linear, 182 194
Festricted Operation message, 56

Root(s) of a function
approximations of, 108
definition of, 105

ideal solutions for, 108
multivariable function roots, 106

Solver’sability to find, 107 -108
Round-off error, can affect Solver
results, 123

ROW1program,listing of, 35-37

S
SHAFT program, listing of, 132
Zian Rewers=al message, 115

Simple programming, 12 -21
SIMUL program, listing of, 170
Simultaneous equations
complex-number, 166 — 168
real-number, 163 -165

Simultaneous Equations, 163 —172
Solver and, 168 -172
Sine integral equation, 136
Solution matrix. See MATX
SOLVE function, indirect address
with, 101 -105
Solver, 77-123

ability to find a root, 107 -108
approximations for which f(x) is

232

Index

nonzero, 108
Bad Guess{es) message, 120
basic use of, 77-80

calculation time in TVM program, 99
cases when a rootis found,109-115
codes returned to the T-register,
108-109
Constant ? message, 121differentiating between Case 1
and Case 2 solutions, 110
directing to a realistic solution,
80-82
emulating in a program, 86— 91
explicit solutions and, 92-100
E:xtremum message, 117

finding more than one solution,
83-85
ideal solution, definition, 108
Integration and, 131-133
interpreting the results of,
108 -122
more on how it works, 105 -123
MVAR function in, 77

providing initial guessesfor,
80-85
results may be affected byround-off error orunderflow, 123

results with a discontinous function, 113-114
Zign Rewers=al message, 115

Simultaneous Equations and,168-172
using in programs, 92-105
Sorting a matrix, 153 -154
SSA program
flowchart for, 23

listing of, 24-25
SSA (triangle solution) equations,22

coefficient functions

SSA2 program

Summation-coefficient functions,flowchart for, 27

listing of, 28 -29
SSS programusing in programs, 182 -194
System flags, 47 -48
in MINMAX program, 47

flowchart for, 15

listing of, 17-18
SSS (triangle solution) equations,
13
Stack registers, contain results of
the Solver, 108

Statistics, 174 -194
calculating a multiple linear
regression, 182 -194
correlation coefficient, 221
curve fitting in programs, 194
linear or exponential curve
fitting for one-variable data,
181
list statistics, 175-182

matrix indexing utilities and,149-150redimensioning XLIST matrix to
execute ¥+, 181

summation-coefficient functionsin programs, 182 -194
STO function
brings up variable catalog in
Program-entry mode, 17
indirect address with, 44
STOP function, 29

Subdividing the intervalof integration, 142 -143
Subroutines, 26 —29
advantages of, 26
called with XEQ, 26
definition, 26
end with RTN or END,26
in SSA2 program, 26
Summation registers. See X+

TTime-value-of-money equation, 92
TORQUE program, listing of, 126
Translations, coordinate. See

Coordinate transformations
TRAP program,listing of, 50
TRI A program
flowchart for, 30-31

listing of, 60— 65
Triangle solutions equations, 58 59
TVM2 program,listing of, 93 -99

U
ULIM variablein basic integration, 124solving for with the Solver, 131
Uncertainty of integration
definition, 135

is greater than error in final calculation, 135

may be relatively large, 138 139
returned to the Y-register, 135
Underflow, can affect SolverV
results, 123

Userflags, 46—47

function; Summation-

Index

233

Vv
Valid solution. See Directing theSolverto 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
YLIST, 176

ULIM, 124

Vector solutions, 154 -163

VIEW function, 16
brings up variable catalog in
Program-entry mode, 17enhancing HP-41 programs
with, 68
Volume offrustum ofrightcircular cone, equation, 80

X
XEQ function
executing a program with, 73, 19
indirect address with, 45

XTOA functionin HPLOGO program, 195
used if corresponding charactercannot be typed, 203
XVALS program,listing of, 182

234

Index

Programming Examples and Techniques
for Your HP-42S Calculator
Programming Examples and Techniques contains examples in mathematics, science, engineering, and finance to help you more fully
utilize the built-in applications in your HP-42S calculator. Programmed
solutions are emphasized. Graphics and plotting with the HP 82240A
Infrared Printer are also addressed.
B Programming

Simple Programming ¢ Branching ¢ Controlled Looping ¢ Indirect
Addressing in Programs ¢ 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 TwoLine Display » Using Menu Variables ¢ Assigning a Program to the
CUSTOM Menu
® 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 ¢ More on
How Integration Works
B 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
B Graphics and Plotting

Graphics ¢ Multifunction Plots « Plotting Data from a Complex
Matrix(,5] HEWLETT'8 pACKARD
Reorder Number

00042-90020
00042-90019

EnglishPrinted in U.S.A.

7/88

0

""88698"00036"

6