0% found this document useful (0 votes)
66 views

An Easy Course in Using The HP-42S - OCR

An Easy Course in Using the HP-42S

Uploaded by

Calambres
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

An Easy Course in Using The HP-42S - OCR

An Easy Course in Using the HP-42S

Uploaded by

Calambres
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 388

. ...

An Easy
'Cou-r se In
c
(
. rJ
-· . ('
r
('
('
(
(

(
(
(

c
(
('
(
c
(
~

(
(
(
(
(
(
(
(_
(
(
An Easy Course In
Using The HP-428

by Dan Coffin
and Chris Coffin
Illustrated by Robert L. Bloch

Grapevine Publications, Inc.


P.O. Box 118
Corvallis, Oregon 97339-0118
Acknowledgements

We extend our thanks once again to Hewlett-Packard for their top-


quality products and documentation.

© 1989, Grapevine Publications, Inc. All rights reserved. No portion


of this book or its contents, nor any portion of the programs contained
herein, may be reproduced in any form, printed, electronic or mechani-
cal, without written permission from Grapevine Publications, Inc.
()
<)
()
Printed in the United States of America )
ISBN 0-931011-26-4
)
)
First Printing - August, 1989
)
)

)
Notice Of Disclaimer: Grapevine Publications, Inc. makes no express or implied warranty with )
regard to the keystroke procedures and program materials herein offered, nor to their merchantability )
nor fitness for any particular purpose. These keystroke procedures and program materials are
made available solely on an "as is" basis, and the entire risk as to their quality and performance )
is with the user. Should the keystroke procedures and program materials prove defective, the user
(and not Grapevine Publications, Inc., nor any other party) shall bear the entire cost of all necessary )
correction and all incidental or consequential damages. Grapevine Publications, Inc. shall not be
)
liable for any incidental or consequential damages in connection with, or arising out of, the
furnishing, use, or performance of these keystroke procedures or program materials. )
)
)
CONTENTS

Start Here ............................................................... 10

Before You Get Your Hands Dirty .................. 12

What's In This Machine? ............................................................ 13


What's Not In This Machine? .................................................... 13
What's In This Book? .................................................................. 14
What's Not In This Book? .......................................................... 15

A First Tour Of Your Workshop ...................... 16

The Big Picture ............................................................................ 17


The @ill Button ............................................................................. 20
The [OFF] Button ............................................................................ 20
Starting With A Clean Shop ...................................................... 21
The Display: Your View Of The Workshop ............................. 22
The Viewing Angle .................................................................. 22
Your Display's Two Lines ....................................................... 22
The Message Display .............................................................. 23
The Stack Display ................................................................... 23
The Menu Display ................................................................... 24
The Program Display .............................................................. 24
Where Are You? ....................................................................... 25
The Annunciators ..................................................................... 26
How Many Digits Do You Have? .......................................... 27
Your First Menu: How Many Digits Do You See? ... 28
(DISPJ
The Keyboard ................................................................................ 30
The Arithmetic Keys: Your "Nuts 'n' Bolts" ....................... 30
Menus And Their Pages .............................................................. 31
Data In The HP-42S ................................................................... 34
The Stack Registers ................................................................ 35
The Alpha Register .................................................................. 35
Data Types In The HP-42S ................................................... 36
Containers And Labels For Your Data: Variables And Their
Names .............................................................................. 37
Real Variables .......................................................................... 38
ALPHA Variables ...................................................................... 38
Complex Variables ................................................................... 39
Matrix Variables ...................................................................... 40
Storage Registers: The REGS Matrix ................................ .41
<)
Programs ................................................................................... 42
Reviewing Your Storage Area .................................................... .43 <)
The •CATALOG) Menu ............................................................... 43 )
The ~ Menu .................................................................. 44 )
Pop Quiz ........................................................................................ 45 )
Pop Answers .................................................................................. 46
)
)
Tools! Glorious Tools! .......................................... 48 )
)
Your Favorite Tools: Arithmetic And The Stack ................... .49 )
RPN .......................................................................................... 50 )
The Stack .................................................................................. 52
)
What Is Stack-Lift? ............................................................ 53
)
Putting Two and Two Together ........................................ 56
)
)
Chain Calculations .......................................................... .... 58
Changing The Sign Of A Number ........................................ 62
That® Key .............................................................................. 63
The ~ Key And l!D .............................................................. 64
Moving Numbers Around In The Stack ............................... 68
The §±) Key .......................................................................... 69
The [x~y) Key ....................................................................... 70
Notes, Doodles, And Stack Practice ................................. 71
The L-Register .......................................................................... 72
The 9l!iSfXJ Key ............................................................... 73
Reality Check ................................................................................ 75
Real Answers ................................................................................ 76

Bigger Hammers: Higher Math And Number-Crunching ..... 78


Exponentiation: Roots, Logs And Powers ............................. 79
Common Trigonometry ............................................................ 82
The~ Menu ..................................................................... 85
The (CONVERT) Menu ................................................................. 88
The ~ Menu ................................................................... 90
A Deep Breath .............................................................................. 92

A Complete Inventory Of Tool Menus ...................................... 93


Special Use Menus ....................................................................... 95
The ~ Menu .................................................................. 96
The~ And •CUSTOM] Menus ...................................... 98
Your Tools Can Work Together ............................................ 102
The •TOP.FCN) Menu .............................................................. 103
Tool School Reviewal ................................................................. 105
Tool School Reviewal Soolutions .............................................. 106
YOUR RAW MATERIALS:
Data And Variables ............................. 110

Handling Data ............................................................................. 111


How Do You Name It? ............................................................... 111
All About [STO)......................................................................... 114
(
All About [Rel)......................................................................... 115
Real Variables ............................................................................. 120
ALPHA Data And The ALPHA-Register ................................... 121
Complex Numbers ...................................................................... 126
Seeing Vs. Doing: The Difference Between
(
The~ And •CONVERT) Menus ......................... 131
(
Entering Complex Numbers ................................................. 132
Using Complex Numbers ...................................................... 134 (

What Are Complex Numbers Good For? ............................ 136 (


Matrices ....................................................................................... 140 ()
What Are Matrices Good For? ............................................. 141
)
Entering Matrices .................................................................. 142
)
Storing Matrices .................................................................... 145
Editing Matrices .................................................................... 146 <)
Complex Matrices .................................................................. 148 )
What You Can Do To A Matrix........................................... 149 )
Special Matrix Functions ...................................................... 151
)
What You Can Do With Two Matrices ............................... 155
Notes (Yours) ............................................................................... 159
)
Variable Vexation ........................................................................ 160 )
Victory Versus Variable Vexation ............................................. 162 )
)
)
)
)
BUILDING NEW TOOLS: Programming .... 166

Programs: A Different Kind Of Tool ....................................... 167


A Little Memory Reminder ................................... ............... 168
9PRGM) And Program Mode ..................... ................... ........ . 170
The Program Display Revisited ................................ ........... 171
The "No-Frills, Straight-Arrow" Program ... .................. .......... 173
How To Start A Program .................................................... . 175
How To END A Program ... ............................................. ...... 178
Using Your First Program .................................................... 180
Editing A Program ................................................................ 181
Moving Around In Your Program ..................... .............. .. ... 183
What Do You Know? ........................................ ..................... ..... 185
Variables And How To Use Them ........................................... 186
Using the mii Function ................................... .............. .... 188
Getting Your Program To Talk Back ............... ........ .... .. ..... 192
PROMPTing For ALPHA Data: 1m1 and llfilii.... ... ...... 196
Variable Menus .................................................................. 199
Creating Two-Line Messages ........................................... 204
Review ....... ................................................................................. 209
Preliminary Programming Probe ....... ....................................... 210
P.P.P. Answers ............................................................................. 212

Using Labels For All They're Worth ....................................... 218


Global Vs. Local Labels ................................... ... ........... ....... 219
Which Type Of Label To Use .............................................. 222
Branching Out With [GTO] and [XEO].. ... ...... ... ........ .... ........ ... 223
Routine Subroutines ... .............. .............. ............................... 226
Selective Branching: The Programmable Menu ... ............... ... 229
Multi-Page Programmable Menus .................................. 235
I
Letting The Calculator Decide What To Do .......................... 241
Conditional Tests ................................................................... 242
Flags ........................................................................................ 246
mI) And Flag 21 .............................................................. 250
Testing The Data Type .................................................... 251
Loop Counters ........................................................................ 252
Indirect Addressing ................................................................ 260
Using Indirect Addressing To Make Decisions ............. 262
Reviewing Your Programming Tools ........................................ 266
Prove Your Programming Proficiency ...................................... 268
Programming Proficiency Proofs .............................................. 270

Programming Big: A Case Study ........................................... 276


The Challenge ........................................................................ 278
Stage One: Planning ............................................................ 279
Stage Two: Writing The Program Section by Section .... 284
Stage Three: Debugging ........................................................ 302

)
SOLVING PROBLEMS: )
Using Your Power Tools .................... 304 )
)
The~ Menu ....................................................................... 306
Negative Numbers In The ~ Menu ........................... 310
)
Fractions And Integers And Bases ..................................... 313
The !!Im Menu ...................................................................... 314 )
Solving Problems in~· ................................................. 317 )
Matrix Multiplication ............................................................ 317 )
Simultaneous Equations ....................................................... 319 )
)
)
The [STAT] Menu .......................................................................... 322
What Are Statistics, Anyway? ............................................. 323
Entering Some Statistical Data ........................................... 325
Checking and Editing Your Data ........................................ 328
Just Plain Mean .................................................................... 330
A Moving Average ................................................................. 331
A Weighted Mean .................................................................. 332
Deviations From The Average ............................................. 335
Two-Variable Statistics .......................................................... 339
Getting Trendy: Regression and Estimation ............... 340
Solver And Integrate: Power Tools That Use Programs ...... 350
The ~ Menu ................................................................... 351
Spikes, Asymptotes, And Other Beasties ....................... 356
The~ Tool ................................................................. 359
What ~ Is Really Doing ...................................... 362
Guess the Answer: Telling llSOLVERJ Where To Look .. 363
Don't Be Misled By False Solutions ......................... 364
The Good News ............................................................ 365
Powerful Problems ..................................................................... 373
Powerful Solutions ..................................................................... 374

Foundation Completed ..................................... 380

"The Book Stops Here" .............................................................. 381


Comments, Books And Order Forms ....................................... 382
START HERE
... at the very beginning... with enthusiasm, energy and a dream or
two ....
)

Yes, there's a lot to be done- and a lot to learn - but remember that the
)
hardest part of learning anything new is simply )
)
Beginning )
This means you've just finished the hardest part of this Course!

But you're not quite completely finished yet. You've begun with a
powerful problem-solving workshop (your HP-428), and now, with this
Easy Course book, you're going to master that workshop and its tools.

So follow through on the Course you've started. It is an "Easy Course,"


but it's still a Course, and it's been carefully planned - so follow it
faithfully and let it be your guide and friendly mentor.

It's not a long apprenticeship - just a few good hours. But do it! The
rewards will definitely be worth your while; when you finish, you'll
know enough to solve problems that haven't even been invented yet!

How's that?

It's like this: The goal here is not just to leave you knowing how the
buttons work or remembering a handful of keystrokes and formulas.
You're going to get a fundamental understanding of problem-solving,
so that whenever you encounter new problems, you'll be able to analyze
and solve them confidently. No more the apprentice, you'll be the
master of your own workshop!

Now then....
)
)
........ ______ ~
·--- ·--.. .
)
)
)
Before You Get Your Hands Dirty )
)
)
What's In This Machine?

Inside the HP-428 you'll find a wonderland of tools that are useful in
solving real-world mathematical problems of nearly every kind. And
you can use these tools to build even more wondrous tools - to get you
to those "hard-to-reach" places. Congratulations on a wise choice!

Now you simply need to learn how to use and master the tools and
possibilities your HP-428 offers.

What's Not In This Machine?

There's no English-speaking person inside your calculator (one of


these days, though... ). You still need to "speak" your machine's
"language" in order to translate your everyday calculation problems
into shapes and forms it can understand. These are the skills you've
chosen to learn.

Your part of the work is in defining the problem correctly for yourself
and then restating it for your calculator. After all, only a human being
can really understand our human world (and even then it's tough
sometimes)!

This translation skill isn't really very hard to learn. It's a lot like
learning to use any sophisticated tool - like a typewriter, a car, a lathe
or a forklift. Everything seems strange at first, but after some training
and practice, you'll be doing things quite proficiently - without even
thinking much about them! And that's where this book comes in....

Before You Get Your Hands Dirty 13


l..I

What's In This Book?

This book is a sort of a workshop apprenticeship.

As your mentor, this Course will introduce you to the tools available in
the shop, watch over you as you use the power tools for the first time,
demonstrate some of the more useful operations that a Craftsman has
to know, and make sure that you know how to keep your working en-
vironment clean, orderly and inviting.

During your apprenticeship with the HP-428, you'll encounter lots of


explanations, diagrams, pop quizzes and answers, as well as useful
advice about visualizing your work. Ultimately- as any good mentor
does for his apprentice - this book should inspire you to build powerful
new tools that move you into your own "brave new world" ofproblem-
solving.

So, what makes this Course so Easy?

It's because you can control how fast you learn things. You needn't
worry about showing off or competing with anybody. You can repeat
your lessons whenever and as often as you wish-without making your
teacher the least bit grumpy. After all, it's your Course!

14 An Easy Course In Using The HP-428

)
What's Not In This Book?

You won't find discussions of everything, because some parts of your


HP-428 just don't need much explanation at all. Included here,
therefore, are just those things that most "craftsmen" tend to need
some practice on - most of the time.

For example, you'll get an overview of the higher math tools available
on your machine, but not an exhaustive and detailed survey of them;
some of those tools will be discussed more fully than others. This isn't
because those tools are any more important in the Great Scheme Of
Things; rather, it's because they're the most complicated to learn how
to use correctly, so they deserve more space in the book.

By contrast, some other menus tend to explain themselves after a few


uses of them, so that's what you'll do here -just use them a few times
- as a reminder that they're available if you want them.

Anyway, if you want a complete description of everything, you already


have it right there in your Owner's Manual. That's what it's there for
-as a reference manual to let you conveniently look up keys, functions,
examples, and generally browse through the Great Unknown.

But this book you're now reading is not a reference manual; it's an
entirely different approach, with a careful selection of topics that are
meant to be taken in order. So start here at the beginning and stay on
Course!

Now, roll up your sleeves, flex your fingers, oil your thinking cap
and ... go ....

Before You Get Your Hands Dirty 15


k~~~~f§&:u:i__QL~~00'- 1 ~
)
A First Tour Of Your Workshop )
)
)
)
The Big Picture

The best place to begin your first tour is to look at the Big Picture -the
"floorplan" of your HP-428 workshop.

At first glance, such an opening view of "everything-in-the-HP-428-


all-at-once" may overwhelm you with its size and variety. Don't worry:
you'll come to know and love this floorplan as you familiarize yourself
with the workshop. You'll be introduced to each nook and cranny in the
workshop - one piece at time. And as you accumulate more and more
understanding of these details, you'll easily keep track of where you
are by glancing back at the Big Picture from time to time.

Now, before you turn the page, consider what you're likely to see: What
would you expect to find in a craftsman's workshop?

• There would be a work area - an area designated for actually


building all your projects;

• There would also be tool storage areas - say, one area for hand tools
and one area for power tools;

• There would be an area to store the work and materials themselves


- both finished and unfinished projects.

OK. .. turn the page and see your HP-428 workshop .. ..

A First Tour Of Your Workshop 17


\.1

The HP-428 Workshop


Work Area-+

You'll be spend-
ing a lot of your
time here, with
the Stack acting
as your "work-
bench."

Power Tools-+ )
()
These are com-
plex and power- ~ ~
()
ful tools, each in mJIWJU ()
its own "room." EDI
)
)
)
Hand Tools-+
)
These tools per-
form most of the
)
"simple chores"
)
and are stored
on "shelves" (i.e. )
in menu collec- )
tions) here. )
)
)
)
18 An Easy Course In Using The HP-428 )
)
The HP-42S Storage Area
• Thememoryavail-
able in your HP-
Latest, Greatest Program 428 Storage Area
Third Program I
Programs I will depend on the

Second Program I •PRGM)


numbers and sizes
ofprograms you've
I
--------- ... --
First Program
built and stored.
(moveable barrier) .,v

Available • The •CATALOG) al-


Space
lows you to "see"
mm
what you have in
each storage area,
and it also shows
how much memory
space is available.

• The data variables


you store (of ma-
trix, complex, real
and ALPHA data
types), also affect
the available stor-
age space:

Real# • The.CATALOG)key
Variables
or Alpha also lets you view
Strings
all the available
hand tools.

A First Tour Of Your Workshop 19


The [ON)Button

You may have noticed from studying the Big Picture that your work-
shop apparently has no outside doors.

You'd better find the entrance: To get into your workshop, press the
button in the lower left corner of your calculator - the button marked
[EXIT), with ON written in silver below it and OFF written in orange
above it.

"How does it know which of the three instructions I mean?"

Well, if you push the button when the calculator is turned off, it acts
like the@ffibutton. You "go into the workshop." If you push the button
when the calculator is turned on already, the button acts as the (EXIT)
key (details about the (EXIT) key later.)

The [OFF) Button

Is your calculator on? All right, now turn it off again, by pressing the
[OFF) key....

)
Hmm ... the machine doesn't turn off simply by pushing that same (EXIT)
)
key again, does it?
)
Since the word OFF is written in orange above the (EXIT) key, you need )
to press the blank, solid orange "shift" key(.) before pressing [Ex1n )
Now it works, right? )
)
20 An Easy Course Jn Using The HP-428 )
..I
Starting With A Clean Shop

OK, press@ffi again. Now, the best way to start making sense of that
Big Picture is to look at your HP-42S display.... what do you see?

That's hard to say, actually. Since your HP-42S has continuous mem-
ory, it will look now just as it looked when you last used it. So, to be sure
that you're starting with a clean slate, here's how to reset the machine.

Warning: You're only doing this now to be sure that you can follow
along on this Course. This procedure completely wipes out all mean-
ingful information in the machine. This is not something you want to
do very often. There are plenty of other, safer ways to selectively erase
parts of its memory. This reset is an Equal Opportunity Erasure! It
erases everything without regard to its importance or value!

Drum Roll, Please: Press and hold down the [EXIT) key. While
holding it down, press and hold down the~
key (upper left corner). While holding both
those keys down, press and release the [XEO)
key (upper right corner). Now release the~
key, then the [EXIT) key. You should see this:

[MeMory Clear
x: 0.0000

(If this doesn't work the first time, just try


again.)

A Fin1t Tour OfYour Workshop 21


The Display: Your View Of The Workshop

To begin to understand and use your HP-428 workshop, you need to


understand the display and what it's showing you. The HP-428
display is indeed your view of your tools, projects and work areas.

The Viewing Angle

Can you see and read the display comfortably? The LCD (Liquid
Crystal Display) is hard to read if you're not looking at it from a certain
angle - but you can adjust that angle to whatever's best for you!
()
()
Try It: With the machine still on, press and hold down the [EXIT) key. ()
Then press and hold the (±) or the 8 key and watch how the )
display's best viewing angle varies .... )
)
)
The Display's Two Lines )
)
There you see it, a machine with utter amnesia. But notice that even )
now, in its emptiest state, your HP-428 uses its two-line display to tell
)
you what's happening-so when in doubt, look at the display for clues!
)
With two lines of display, the HP-428 offers more power and flexibility )
(and possible confusion) than do calculators with one-line displays. So )
it's time to learn what the HP-428 is telling you with its display.
)
)
22 An Easy Course In Using The HP-428 )
)
The Message Display

This kind of display is what should be showing right now: the top line
hasamessage(MeMory Clear)and the bottom line shows x: 0. 0000

A message itself is a temporary note that simply covers over part of


some other display- notifying you or instructing you to do something.
After you follow its instructions or acknowledge it, you'll once again see
what's underneath. For example, that 0. 0000 on the bottom line is
part of "what's underneath" right now - the part that isn't being
covered by the message.

The Stack Display

Now, press the~ key to clear the message line. You should see:

ly, 0.0000
x: 0.0000

This is the second type of display, the Stack Display. By clearing the
message, you've now uncovered the top line of this display.

These two numbers are the ones that your calculator happens to be
ready to work on at the moment. You can think of them as "sitting on
the workbench" right in front of you in a sort of stack, waiting for you
to grab a hand tool and start pounding or cutting on them or something
(and of course, you'll learn all about the relationships between the x:
and Y: numbers and the rest of the Stack later in this chapter).

A Finl Tour Of Your Workshop 23


The Menu Display

You'll find a third type of display by pressing •CATALOG] (i.e. the solid
orange key, then the(±) key with the orange CATALOG written above
it). You should see the following Menu Display:

A Menu Display is similar to a Message Display in that it usually


covers up or displaces a part of another (underlying) display. But a
Menu Display uses the bottom line of the display; and instead of a
message, it shows a set of items from which you select to help you in
your work on the top line. For example, the Menu Display above shows
part of a Stack Display on the top line; the selections offered on the
menu (bottom) line are meant to help you view and use certain tools (to
get back to the full Stack Display now, press the [EXIT] key).

The Program Display


)
The fourth type ofdisplay shows the program you're currently building )
or editing. You see a Program Display by pressing~ (do it now): )

)
00•{ 0-Byte Pr9M ) )
01 . E~lD.

Again, don't worry yet about what the information in this display is.
This is just to get you familiar with the types of displays you'll be seeing.

24 An Easy Coun1e In Using The HP-428


Where Are You?

The whole point of these first lessons on the display is: Always let the
display orient and remind you "where you are" in the workshop:

• If you see the Stack Display, you're at your "workbench," preparing


to do some calculations.

• Ifyou see the Program Display, you're building or editing a program


over in the program storage area. To go back to the Stack Display,
just press the [EXIT) key (do so now if you still see a Program Display).

• If you see a Menu Display, it means that, besides working in the


Stack or in a program, you're also using one set of tools. To get rid
of the Menu Display (i.e. to return that set to its storage bin and go
back to your "workbench" -just the Stack Display), use the [EXIT) key.

• If you see a message display, this is only a temporary note covering


part of another display. The ~ key will clear the message.

l
A First Tour OfYour Work•hop 25
The Annunciators

Besides the two full lines of information in your HP-428 display, you
also have some space above them. This space is for the annunciators.

"Fine. . .. What's an Annunciator?"

Press the• key and look at the display above the top line. You should
see a small upward pointing arrow: ~-

Now press the• key again while you watch the display. The arrow
went bye-bye. This arrow is a good example of an annunciator.

As you might guess from its name, an annunciator "announces"


something. In this case, the arrow is announcing that you're "shifting"
the meanings of the keys on the keyboard - shifting to the meanings
listed in orange lettering above the keys. Because this is similar to a
"shift key" on a typewriter, this annunciator is called the "shift"
annuniator.

Of course, there are lots of other annunciators in the display, and it


wouldn't pay to try to learn them all now. Since you'll run across most
of them during this Course, you might as well wait until you see each
of them in action. For now, just realize that you may occasionally see
something in the display besides the stuff on the two lines.

26 An Easy Course In Using The HP-428


How Many Digits Do You Have?

You may have wondered why your display shows exactly four decimal
places in every number. This is usually enough for most technical cal-
culations - and HP had to decide on some such display setting for the
HP-428 to "wake up" in after a total memory reset (recall page 21).

"But is this the best precision you can get?" Not at all. In fact, every
number carries 12 digits of precision, no matter how many you can see
at the moment.

For Example: Key in this number: 4562. 86553109. You'll see:

y: 0.0000
x: 4,562.86553109_
Now press~:

y: 4,562.8655
x: 4,562.8655
Was the 0. 00003109 lopped off by the calculator?
Find out by pressing(±) to add these two numbers:

y: 0.0000
x: 9, 125. 7311
The machine kept all 12 digits, even when you couldn't
see them (if it hadn't, you'd now see 9, 125. 7310).

"OK, so how do you tell the machine to display more (or fewer) digits?"

A First Tour Of Your Workshop 27


ll

[DISP] Your
First Menu:
How Many Digits Do You See?

Since the display shows you only requested portions of the full 12-digit
numbers, you have certain tools you can use to "change your request."
To bring these DISPlay control tools to your "workbench," press the
~key. You should see this menu:

x: 9, 125. 7311
m!Jllmllmlimlrnm::Jm!I

Notice a few things here: Notice the little boxes in the menu items that
look like this: Im and li!m. Those boxes remind you which "choices"
you've currently selected. Right now, the mil tells you that you have
a "FIXed" number of decimal places (and you can see how many digits
this is simply by looking in the number above).

The 1iJ.7J1J stands for "RaDiX," which is the technical term for the
decimal point. At the moment, it is a point. In Europe, they would
choose the other option, a comma.

So how do you choose which options you want? How do you use a menu?

Like This: Press the ~keys, then the [xEaJkey. What happens?

x: 9.125, 7311
m!JllmllmlimllB!Rm

28 An Easy Course In Using The HP·42S


The decimal point and the comma exchanged places, and the little box
is now next to the IB:a, indicating that the radix is now a comma. So,
press (hffi to change it back. ...

"Why the~ key?" Because that's how the menus work: Whenever you
see menu items in the display, they are aligned and matched with the
keys in the top row ofthe keyboard (directly beneath them). You choose
menu items by pressing the corresponding top-row keys!

Try Some: Change the number of fixed decimal places from 4


(where it is currently) to 5. Choose Im (by pressing the
~key). What happens? You get a Message Display,
this one prompting you to do something.

Such prompting messages are usually associated with


Menu Displays -as in this case. Here it's asking you for
how many decimal places you want to show to the right
of your decimal point. Press @TI] (fill up both of the
provided spaces) and voila ... youhave five decimal places.

Now set your display's notation to FIX eight decimal


places.

Solution: Select IECI, then @IT).

Result:
x: 9,125.73106218
IECIDl~l:l!JllBIB:!ml

A First Tour Of Your Workshop 29


lJ
The Keyboard

Of course, there's a lot more to using this calculator than just knowing
what the display is telling you. It's now time to look at all the keys (but
if you already know these keyboard basics, then jump now to page 34).

The Arithmetic Keys: Your "Nuts 'n' Bolts"

Look first at the white writing on the actual key-faces themselves. See
how the digit keys <@}-®) and the four arithmetic functions ([±J,8,(8),
and EJ) are all conveniently placed together on the lower four rows?
After all, you shouldn't need to search around just to add two and two!

But (as you'll soon see), there are other keys that you could consider as )
being arithmetic/math keys also: There are the (ENTER], [+/-],and (ID 0
keys, and the (B key is for correcting mistakes (just in case you should )
ever make one). Then the top two rows contain other mathematical
)
functions common to most scientific calculators (e.g. @ill,[ cos],@, (ill)).
)
And don't forget the shift key. You've already been introduced to this )
plain orange key, (which will appear in this book as•). It activates all
the orange-printed functions on the keyboard-similar to the shift key )
on a typewriter. But unlike a typewriter, you don't hold the• key down
)
while pressing the orange-printed function you're after. Just press and
release •• and then press the key you want. The~ will always tell you J
when the "shift" is in effect. (Notice also that the shift is cancelled after )
every use; you need to re-press the• for every orange-printed function )
you want, because •is not a "Caps Lock"). )
J
30 An Easy Course In Using The HP-428 J
)
Menus And Their Pages

All right, so far, you've looked at the display and keyboard of your HP-
428, connecting what you see on your machine with the Big Picture.
Next up: menus and how they work ....

A£; you can tell by looking at the Big Picture (on pageslS-19), most of
the orange functions in the lower part of the keyboard are names of
"storage shelves" in the your workshop. Here's where you'll find many
useful collections of "hand tools."

Each such collection is a set ofrelated tools (such as the DIS Play tools,
for example), stored on its own shelf and marked with an appropriate
name. That name appears (usually printed in orange on the keyboard)
as a menu key. Therefore, in the Big Picture, each "shelf' in the Hand
Tool Storage Area is headed by the name of a menu key:

~
lllBI DI]
lml
ED
um~
lmlllml

In the next few pages, get acquainted with each of these menu keys on
your HP-428 (and though you've already seen the [DISP] Menu, you'll
review it now, too, because there are some other points to learn) ....

A First Tour Of Your Workshop 31


F'rinstance: Make sure you see the Stack Display (press [EXIT) until
you do). Nowgotothe[DISPJMenuand FIX the number
of decimal places at 2: ~lilll@Jil.

Now, notice that you're automatically returned to the


Stack Display after you finish with that tool in the

need to press [EXIT] yourself in order to return to your


work area. Try it! Anytime you don't want to return
automatically to the Stack Display after a single use
of a tool in a menu, press the menu key twice. )
()
)
All menus work similarly to the [DISPJ Menu, but as you can see from the
)
Big Picture, some menus are much larger - so there's one more thing
to ... )

()
Notice: Look at the~ Menu (press~): )
,.... )
x: 9, 125. 73 )
mll:Dl!Dl!lilmJml
)
Only six menu choices are visible, but there's also an an- )
nunciator (T.&.). The ,..._ means there are more choices
available but not visible. To find these other choices, use
)
the@ and[!) keys (just above the• key) ....
)
Get the idea? Try a few more .. . )
)
32 An Easy Course In Using The HP-428
)

Examples: Press llfil@again to keep you from automatically re-


turning to the Stack Display. Now "page" through your
menu choices by pressing the ~key several times ....

Obviously, there are just two "pages" in the Clear Menu,


and they just keep alternating in the display as you push
the ~key. That is, the listing is circular- you just keep
going around and around on the list as you push~ (and
the same is true of the(!) key). And each page in a menu
can show only six choices, but from the Big Picture (page
18), you know there are twelve choices available under
•CLEAR), so it makes sense that this is a two-page menu.

Now look at the •PGM.FCN) "shelf' in the Big Picture.


How many pages do you expect to find in that menu?
Test your answer by trying it on your calculator.
.I
All right, at this point, you've had your first look at the display, the
keyboard and menus. It's now time to consider all those storage bins
in your HP-428 Workshop Storage Area (see the Big Picture , page 19).

Data In The HP-428

Many of the bins in your HP-428 Storage Area are for storing various
kinds ofdata. And what's data? "Data" asit'susedhereisjustanother
name for computer information, namely, "numbers and characters."

You probably have a good feel for what a number is: it's a quantity with
which you (and your HP-428) can do numerical calculations. In this
sense, it's an abstract idea; how you represent this idea to your own eye
and mind is irrelevant. The quantity "twelve" can be represented as
J--HI J..-1-11 I I or 12 or XII . The idea of the quantity you're
talking about is always the same, no matter what symbol you use.

A character, by contrast, is the visual symbol - a letter, punctuation


mark, numeral- anything you'd find on a typical typewriter keyboard.
And if you're talking about the numerals "12", these are simply two
symbols that happen to be set beside each other - much like "AB".
Characters do not mean numbers to the HP-428; the numerals "12" do
not mean the number twelve.

You can also combine or link numbers and characters into other data
structures or types. For example, if you link two numbers together in
an ordered pair, you get a vector. If you link two characters, you get a
string. By thus linking simpler data types, you make more intricate
(and presumably, more useful) data types.

34 An Easy Course In Using The HP-428


)

With that in mind, consider the various storage bins in your workshop:

The Stack Registers

The Stack registers are bins named with letters - X, Y, Z, T, and L.


These registers are the "workhorses" of your workbench area. Here's
where you bring data to work on them. If you look at the Big Picture,
you'll see the reason why this set of five registers is called "the Stack:"
they're stacked on top of one another and are linked together in a
special way that makes "data-crunching" easy and efficient.

The ALPHA Register

With the help of this register, the computer can store and manipulate
characters (also called ALPHA characters to remind you that they are
indeed only letters and symbols - not numerical quantities).

The ALPHA register can hold up to 44 ALPHA characters at one time


- but it can never hold numbers. You can't add, subtract, or otherwise
use a "12" in any math calculation while it's in the ALPHA register. If
you need to do math with the number twelve, you'd need to convert the
ALPHA string (i.e. the combination of ALPHA characters), "12'', into a
true number, 12. 00, in one of the Stack registers.

Now ... what kinds of data types can you build and store, using simple
numbers and characters -and using the Stack and the ALPHA register
as your "working containers?"

A Fint Tour Of Your Workshop 35


Data Types In The HP-428

Your HP-428 will let you build and store these four types of data:

L Real numbers
2. ALPHA strings
3. Complex numbers
4. Matrices

L A real number data type is just a single real number - plain and
simple;

2. An ALPHA string data type is a set of ALPHA characters-at least


one but no more than six such characters;

3. A complex number data type is set of two real numbers, linked


and ordered to represent the real and imaginary parts of a
complex number. You can think of the complex data type as )
linking together simpler data types (real numbers); )
)
4. A matrix data type is an ordered set of numbers, grouped in rows )
and columns. In the HP-428, you can have matrices filled either
with all real numbers or all complex numbers. You can think of
the matrix data type as linking together simpler data types (real )
numbers or complex numbers). )

These are the forms in which you can store and manipulate data. But
you might have lots of examples of each form - so you need a way to
store and identify each datum.. .. )

36 An Easy Court1e In Using The HP-428 )


}
Containers And Labels For Your Data:
Variables And Their Names

Whenever you build a datum, it will have one of those four data types.
And if you want to store it somewhere, that "somewhere" will be a
variable. As you can tell from the Storage Area in the Big Picture (page
19) variables are eraseable, namable storage bins. They vary because
you can delete them altogether - or change their names or sizes.

That's is an important distinction between a variable and a register:


A register is a built-in storage bin - a named space (usually a space for
"working in"), which is reserved and labelled with a certain name. For
example, you've already seen the Stack registers and the ALPHA-
register. They are indeed registers, for although you can clear these
bins of their current data (i.e. set them to 0. 0000 or blank), you can't
delete the bins themselves or change their names or sizes. By contrast,
a variable has no such built-in existence. Since you create it in the first
place, you can also destroy it. Also, you can change its name, and
sometimes increase or decrease its size.

Of course, there's an HP-42S variable type for each data type. So,
keeping your thumb marking page 36, look briefly now at each of the
four variable types (don't worry yet about how you actually build and
store these variables yet; remember that this entire chapter is just
your first guided Tour of your HP-42S workshop) ....

A First Tour Of Your Workshop 37


Real Variables

Not too surprisingly, a real variable is a named storage bin containing


one real number. But here's something not quite as obvious: Unlike
other kinds of variables, you cannot expand a real variable to hold more
than one number. It has only that limited amount of storage space.

ALPHA Variables

As you know, the ALPHA string data type is limited to a maximum of


six characters. This may seem odd, since the "work space" where you
build these strings -the ALPHA register- can hold up to 44 characters
at once. But notice in your Big Picture that real and ALPHA variables
are shown as being stored in the same area. The idea is to let you go back
and forth between these two common data types (reals and strings). So
both types are limited to the same non-exandable amount of storage
space in a variable: "six ALPHA characters= one real number".

Of course, you can also have an ALPHA string with fewer than six char-
acters, but this won't save you any storage space; it will use the same
amount of space as a full six-character string (or one real number).
)
)
The interchangeability of real and ALPHA variable types in the HP-
42S makes it just as convenient to refer to all such variables as "real."
So when you see references to "real" variables-either here in the book )
or in the menus of your HP-42S-you need to realize that, unless it's )
stated otherwise, this means ALPHA strings too. )

)
38 An Easy Course In Using The HP-428 )
)
Complex Variables \

) Another totally shocking revelation: Complex variables are named


storage bins containing complex numbers (recall from page 36 that a
complex data type is simply a linked, ordered pairofreal numbers-the
real part and imaginary parts of the composite complex quantity).

As with the simpler real variables, the complex variable type is fixed
in its size: You just can't squeeze any more into it than two real
numbers - one for each part. But unlike real variables, you cannot
substitute ALPHA strings for real numbers in the fixed spaces of a
complex variable. Your HP-42S is absolutely stubborn about this:
Alpha data is invalid in a complex variable type.*

*"Dave ...... Dave? ...... What are you doing, Dave? .... ........ Sorry, Dave, I'm afraid I can't do that.... "

A First Tour Of Your Workshop 39


v
Matrix Variables

Here's the "big-ey" - the real macho variable type: You can actually
enter, store and manipulate entire matrices, using named storage bins
that are matrix variables.

And here's where you can play around with the size of variables: If you
have, say, a two-by-two matrix of values, you can actually re-size it to,
say, a three-by-two matrix, then enter the two extra values!

Not only that, you can change the type of values that go into the matrix:
If that three-by-two matrix you just filled up is a matrix of real
numbers, you can actually convert it to a matrix of complex numbers
instead (all the real values in it will be converted)!

This means that matrix variables are re-sizable two different ways -
the number of elements and the size (type) of the elements themselves.
()
Not bad, eh? Of course, this means that larger dimensions or complex
types will eat more available memory, but it sure is nice to know you )

have this flexibility built right into the machine, no? 0


)
One caution, though: You can't mix-and-match. That is, a matrix is
either all-real or all-complex in the type of elements it handles. And
- consistent with the restrictions on ALPHA data within real and 0
complex variables -ALPHA data are allowed in real-valued matrices,
but not in complex-valued matrices.
)

)
)
40 An Easy Course In Using The HP-428 )
)
J

Storage Registers: The REGS Matrix

Now look again at the Big Picture of the HP-42S Storage Area (page
19). You'll see a long, skinny matrix already stored under the name
REGS in the "Matrix Variables" section .... What is that beast, anyway
- and what's a variable doing in your HP-42S already? You didn't put
it there, did you? Nope - this one's a built-in variable ....

"Built-in? Hmmm - then it sounds more like a register to me .... "

That's basically what it is - a group ofregisters (hence the name, REGS)


that you can't delete.

"So why are they shown as a variable - and in matrix, of all things?"

m
It's because you can do certain things to this ofregisters that you can
normally do only to a matrix variable - things such as changing the
type from real to complex, and changing the number of elements . And
yet you can also do something with this REGS matrix that you cannot
normally do with matrix variables: You can call each element by its own
"register-like" name (e.g. R12 , R19' etc.).

But what good is such a hybrid "variable register-matrix?" Well, often


it's a real pain to need to give every stored value its own unique name
and variable space. It's often more convenient to keep a set ofrelated
numerical values in a neat, ordered set, with each value indexed with
a number for easy automatic sorting and access (like Zip+4 or some-
thing). So HP has reserved such a set for you, and since- like a register
- it is a reserved space and name: they named it REGisterS.

A First Tour Of Your Workshop 41


.J
Programs

There is one other kind of container that can be named in your HP-428
- but it isn't a data variable (see page 19 one more time). It's called a
program, a set of automatically executing instructions by which you
can actually add to your collection of tools: A program is a tool you build
from other tools - the most powerful thing you can build in your
workshop.

Like variables, programs can be varied in their sizes and names - and
they take up space in your HP-428 Storage Area, but that's about
where the similarities end, since programs are not "raw materials,"
but customized tools of your own design.

As with all aspects of this First Tour, you'll see plenty of detail on
programming later. Right now, it's enough that you remember that
programs also must share the Storage Area in your calculator with the
variables you create - and that's why the Big Picture shows them
stored as you see on page 19.
Reviewing Your Storage Area

Here's the bottom line from this chapter: Your HP-42S Storage Area
is divided into areas for programs, variables, and still-available space.
And everything you store will use some of that available space.

The .CATALOG)Menu

To make it easy to review what you've stored, your calculator has a


special menu, the •CATALOG) menu, which acts like a series of windows
(notice the windows in the Big Picture) looking into the Storage Area.
Press .CATALOG. CATALOG] now to look at the menu list:

Each menu item provides an overview of what's available to use in the


various parts of your workshop. Try each selection as you read (and use
[EXIT] to go back to the •CATALOG) menu after each item):

IEI gives a complete list of all the functions (hand tools) available;
IED gives a list of any programs you've stored (none yet);
~ lists all the real (and ALPHA) variables you've stored (none yet);
l!D lists all the complex variables you've stored (none yet);
lml provides a list of all matrix variables (you have none of your
own as yet, but you always have the REGS matrix - that built-in
matrix of "registers" - of either real or complex numbers);
Gm] tells you how much memory you still have available (you must
hold down this menu key to continue viewing the memory).

A First Tour O{Your Workshop 43


The •CLEAR] Menu

That• CATALOG] menu shows you what you've got stored - but it doesn't
let you do anything about it. If you want to keep your storage areas
well-organized and free of clutter, you need to use the ~Menu.
This menu lets you clean out your data, variables, programs, etc.
selectively (i.e. you don't clear the entire machine to get rid of one item).

Press [EXIT) and then •CLEAR.CLEAR) to see this menu (it has two
"pages," so you'll need to use the~ and~ to see all the selections).

Although there are some items on it that won't mean much to you yet,
notice these selections (try them, too, if you wish):

IJg shows you a list of programs that you can clear;


11!!'1 shows you the list of all variables - any type - that you can clear;
1!§1 clears all five Stack registers;
)
11!11 clears just the ALPHA-register;
)
l!!ll clears just the X-register;
milll clears all the storage registers in the REGS matrix; )
t!Jlig deletes all programs and variables, and clears all registers - a )
fairly drastic move, so if you choose this selection, the calculator
asks you to confirm that it's really want you want to do.
)
)

Just remember this - in keeping with the idea ofregisters vs. vari- )
ables: When you use the ~Menu to clear a register, you remove )
the data but leave the container; but when you clear a variable, you )
delete it entirely - data and container.
)
)
44 An Easy Course In Using The HP-42S )
)
Pop Quiz

No sweat - just make sure you can answer these general questions:

L You see in your HP-428 display: HELLO What register is this?

2. What kind of register is the Z-register?

3. What's a menu key and how does it work?

4. What are~ and T•?

5. Name the four kinds of data allowed in your HP-428.

6. What's the difference between a register and a variable?

7. Name the four display types. How do you move between them?

8. What's so special about the ALPHA-register?

9. What if you left for Katmandu without turning off your HP-428?

A First Tour OfYour Workshop 45


Pop Answers

1. This could be a Message Display, or it could be showing you the


contents of the ALPHA-register or the X-register. If it's the X-
register, then it would display x: 11 HELL0 11 • If it's the ALPHA-
register, then you'll see the alphabet menu on the bottom line and
HELLO on the top line. See pages 23-24 to review displays.

2. The Z-register is a Stack register - part of the automatic Stack


of registers where you do most of your "data crunching." These
registers are named with letters to remind you that they're in
this special Stack (see page 35 to review).

3. The meanings of the top-row keys depend on the type of display


you see. For example, if you see just the Stack Display and press
[LOG), your HP-42S will simply take the common logarithm of the
number in the X-register. But when a Menu Display is showing,
this very same key acts as a menu key. Pressing[LOG] in that case
will select the fourth menu item (see pages 31-33 to review).

4. and - are annunciators. The"' ..A. announces that the current


"'..A.

menu has more "pages" -that you'll see more choices if you press
the ~ or (!) keys. The - announces that you've pressed the
orange "shift" key(.), so the machine will interpret the next key
you press in terms of the orange writing above the key instead of
the white writing on the key itself (see pages 26 and 32-33).

46 An Easy Course In Using The HP-428

)
5. The four data types are: real numbers, ALPHA strings, complex
numbers, and matrices. Complex numbers are linked pairs of
real numbers; matrices are linked sets of either complex or real
numbers (but not mixed). An ALPHA string data type is allowed
anywhere a real data type is allowed. See page 36 to review.

6. Variables are storage containers that you can create, name, fill,
empty and delete entirely. By contrast, registers are perma-
nently-created-and-already-named storage containers that you
can only fill and empty- but not delete from existence al together.

7. The four display types are: Message, Stack, Menu, and Program.
Much of the movement between displays is automatic, but you
have some control over it. To move from any other display to the
Stack Display (your "work- bench") you press [EXIT) (sometimes
more than once). To move from the Stack Display to a Menu or
Program Display, you select a function that requires that type of
display (see pages 23-24).

8. The ALPHA-register is the only storage register in the calculator


that cannot be directly involved in mathematical calculations. It
holds up to 44 ALPHA characters (see pages 35 to review).

9. After about 10 minutes, your HP-42S would turn itself off. Then,
if you returned later and turned it on, its display (and memory)
would be the same as before. As long as its batteries last, your
calculator will continuously remember everything you store in it.

A First Tour Of Your Workshop 47


Tools! Glorious Tools! )
)
Your Favorite Tools:
Arithmetic And The Stack

All right- so you have this whole HP-42S workshop full of tools to try
out. Where do you begin?

Probably right there in front of you- at the workbench itself, no? After
all, you can't do much else until you learn the basics of "number-
crunching" with your favorite tools and workspace - the Stack.

If this is your first experience with Reverse Polish Notation CRPN, for
short), you'll want to spend some time in this section. And even ifyou're
an old hand at HP-42S arithmetic, you're going to need a detailed
knowledge of the Stack in order to write good programs - so a review
with this section may be just the ticket.*

So turn your machine on (ifit's not on already), and make sure you see
the Stack display, showing both the X- and Y-registers.

Your tools are ready....

*But, if you really do know your way around the Stack, and you're already quite comfortable with
doing arithmetic on your HP-42S, including negative numbers and scientific notation, then feel
free to go on to page 74 now.

Tools! Glorious Tools! 49


v
RPN

So what is RPN? It's a way of doing arithmetic that's a little different


and a lot more efficient than the way you might "say it out loud."

For example, if you were "saying" the solution to an addition problem,


you'd probably say something like "5.79 plus 34.6 equals 40.39." This
seems easy and intuitive, right?

OK, but try "saying" the solution to this: 19 - l l{(5 .79 + 25) + 34.6)
{40 x 22)

"uh ... 19 minus the quantity 11 times the quantity 5.79 divided by 25,
plus 34.6, divided by the quantity 40 times 22 equals ... ?"

A person could get a sore throat with all those "quantities," which are
meant to denote the parentheses, right? And it's pretty hard to tell
where the parentheses should open and close, isn't it? If you get
several nested sets, it's a real pain to make sure you've got a closing ()
parenthesis for every opening one. )
)
The point is, all those troubles are still with you if you use a calculator )
that tries to mimic the way you "say it out loud" -a calculator that uses
()
"algebraic notation," rather than RPN.
)
With RPN, you never use parentheses (no matter how complex the )
calculations get) nor do you even need an G key (notice that your HP-
428 has neither CIIIJ keys nor an G key).
)
)
"How is this possible?" Glad you asked!. ...
)
)
50 An Easy Course In Using The HP-428 )
)
The main "strategy" with RPN is: A. Key in a number;
B. Do something to it.

And most RPN calculations are just repetitions of this simple pattern!

Example: Press (EXIT) so that you see the Stack, then add 5.79 and
34.6 on your HP-428.

Solution: Do the above procedure twice:

A. Keyin~.
B. Press [ENTffi) to "finish" it.

A. Key in @:8Effi;
B. Press(±) to add it to the previous number.

Result: x: 40. 39

Putting the action at the end of the sequence of numbers is what makes
RPN so different - and so much easier - than the way you're used to
"saying" a solution (and it's also what puts the R in RPN*).

For one thing, it eliminates the need for an B key, since pressing (±)
signifies that you're ready to have the operation performed. But the
biggest advantage is that you never need parentheses, because you're
always "combining as you go." You don't need to give the machine the
entire problem before beginning to solve it!

*See the footnote on page 42 ofyour Owner's Manual for more details about how RPN got its name.

Tools! Glorious Tools! 51


The Stack

The Stack is what makes RPN arithmetic possible: You don't need to
key in an entire problem at once with an RPN machine because it can
accumulate the intermediate results (partially completed calcula-
tions), letting them "stack" up until it's time to use them.

So whenever you do arithmetic on your HP-42S, you're using that set


of five registers - named X, Y, Z, T and L -known collectively as the
Stack. Four of these registers (X, Y, Z and T) work in a closely linked
fashion to do the arithmetic (the L-register is important, but not while
you learn the details of arithmetic. Until further notice, when you
think about "the Stack," just think about the X, Y, Z, and T-registers).

The first thing to realize about the Stack is that whenever you key a
number into your HP-42S, you're keying it into the X-register. All
numbers are keyed into the X-register.

Challenge: Set the Stack up like this:

T: 56.87
)
,------------,
I
Z: 43.6
10.02
y: I
)
L _x.:_~--------- _J

Solution:

OK, but what's really happening when you press that (ENTER] key?

52 An Easy Course In Using The HP-428 )


)
)

What Is Stack-Lift?

Take a closer look at the inner workings of the Stack as you re-solve the
previous Challenge ....

Below is a series of Stack diagrams, a handy way to demonstrate


what's happening in the four Stack registers.

In these diagrams, the visible portion of the Stack (what you see in the
display), is outlined in the dashed boxes. And the ?'s mean, "some
number is there, but for the purposes of the example, it doesn't matter
what it is."

T: ?d T: ?b T: ?b
Z: ?a Z: ?a

T: ?a T: ?a T: 56.87 T: 56.87
Z: 56.87 Z: 56.87 Z: 43.60 Z: 43.60
- - - - - - - r-------1 - - - - - -----
1y: 43.60 II y: 43.60 II y: 10.02 11 y: 10. 02
l~:_43._§.0___ I ~:J0. 02 _ __ x:J0. 02_ _ x: 6_
IENTER]j'~GI~I::I:§:IIlj'~ !ENTER] j'~ 0 j'

Study this diagram and compare it with your HP-42S display as you
re-solve the example (press (B to clear the 6_ if it's still in your display).

Notice a few things that tell you a lot about how the Stack works ....

Tools! Glorious Tools! 53


}

1. Often, when you key a number into the X-register, the numbers
in the other registers are "bumped" up one notch (and the value
that was in the T-register is bumped off the top - gone for good,
never to return). This is how the Stack automatically saves your
partial results when you're doing a big arithmetic problem: as
you key in the next number, the previous (partial) result bumps
up a notch, "floating around" above until you need it.

This "bumping up process is called "Stack-Lift," and whenever


the Stack is ready to do this, you say that Stack Lift is enabled.
When the Stack is not ready to lift, you say that Stack Lift is
disabled. Most of the time, as you do arithmetic, you want the
Stack Lift to remain enabled - and, sure enough, that's how it
works. But sometimes you specifically want to disable it .. ..

2. Whenever you press [ENTffi], you cause three things to happen:

First, you terminate digit entry, which is a fancy way of saying


that you tell the machine you're finished keying in the number
in the X-register. If you think about it for a minute, you'll realize
that you must have some way of telling this to the machine, since
)
with RPN arithmetic, when you add 2 and 2, the order of entry is
@)@)(±],so you need something in between the two @J's to tell the )
machine that you do indeed mean two 2's, not one 22. )
)
Next, you cause a Stack Lift - but without keying in any new
)
value to the X-register. That is, all Stack values are bumped up
)
one notch- just as in any other Stack Lift- but the new value in
the X-register is still the same as the previous value. )
)
54 An Easy Course In Using The HP-428 )
)
J

Finally, you disable the Stack Lift- so that ifyou now key in a new
number to the X-register, it will not bump everything else up, but
simply overwrite the previous contents of the X-register.

Thus, in the example, as you key in every number, you press


[ENTER] to (i)terminate the keying-in process; (ii) lift the Stack
(thus saving a copy of this latest number in the Y-register); and
(iii) disable the Stack to ensure that the next number can slip
right into the X-register without further affecting the rest of the
Stack!

Right now, you might be thinking that this is an awful lot of detail to
have to remember just to do arithmetic - but don't worry. It takes only
a little practice and the Stack will become as automatic as, say, driving
a car or riding a bicycle!
Putting Two And Two Together

Of course, to do actual arithmetic, you'll need to do more than just "set


up the Stack." Here's how you use the Stack to crunch numbers ....

Do This: With your Stack properly set up from the previous Chal-
lenge, press the~ key to multiply together the contents of
the X- and Y-registers.

Result:
ly, 43.60
x: 60.12

( )
Look at what happens to the stack during this multiplication: )

T: 56.87 T: 56.87
()
Z: 43.60 Z: 56.87
----- ----- <)
1 y:10.02 11 y:43. 60
x:-6_- - - - x:-60.12 )
----
~@ j' )
)
When you press the ~ key, several things happen:
)

The values in the X- and Y-registers combine in the multiplication )


operation, and the result lands in the X-register. )
)
Next, since two numbers have just been combined into one, the rest of
)
the values above simply drop one notch (the T-register stays the same).
)
56 An Easy Course In Using The HP-42S )
)
.J

) And (best of all) at the end of the operation, the stack is left enabled,
so that you can now key in another number to the X-register, and the
previous result (60. 12) will "bump" up to the Y-register- all ready to
be combined with your new entry!

So Go For It: Subtract 42 from that last result.

Nuthin' To It: Just key in Gffi, then press 8 * Here's the result:

ly, 43. 60
x: 18.12

And here's what happened:

T: 56.87 T: 56.87 T: 56.87


Z:-56.87
---- ______
.....,Z: 43.60 ] Z:-56.87
----
1y: 43. 60 II Y: 60. 12 IIy: 43. 60
x'._§0.1_2__ ~:_42 _____ J x:J8.1_2__
1---7 (ill) -1' ~ 8 -1'
See how an enabled Stack Lift allows the upper Stack values to simply
"ride" along during the calculation?

And notice how the subtraction operation subtracts the X-value from
the Y-value (i.e. it's "y minus X"), not the other way around. Each
operation that combines two numbers has a specific order (although in
some operations, order doesn't matter).

*Notice, by the way, the efficiency ofRPN here: If this were not an RPN machine, then to do this
example, you would need four keystrokes <8~8. rather than three ~8)!

Tools/ Glorious Tools/ 57


J

Chain Calculations

By now you can begin to see the advantages of the RPN Stack -
especially when Stack Lift is enabled for subsequent ("chain") calcula-
tions. For that very reason, most operations will leave the Stack Lift
enabled (indeed, (ENTER) is one of very few keys that disable it).

Now try this problem as a fuller example of the Stack, its lifting and
dropping - and the beauty and simplicity of RPN:

Problem: Calculate 3.57 x {67.12 + {89.43) 2) without storing any


numbers or writing down any intermediate results
(and of course, there ain't no CITD or G keys either)!

A Solution:

Answer: 28, 791 , 50

You may be wondering how to decide on the "order of doing things."

That's not too hard - remember how you were taught to analyze such
involved, chain-calculation problems in school?

"Work from the innermost parentheses outward."


)
)
It's still good advice - especially for RPN arithmetic! Study the
)
following diagram as you repeat the keystrokes ....
)
58 An Easy Course In Using The HP-428 )
)
T: 43.60 T: 43.60 T: 43.60 T: 18.12

T: 18.12 T: 18.12
Z: 18.12 Z: 28,791.50
----- -----
1~ 28,791.50 II~ 8,064.84
x:_?l..06~84 x:_.?~57 __ _
[±) _j' 4 03ill) _j' ~ [8J

Notice that any operations, such as (8) and (±), that combine two
numbers into one result will cause the Stack to drop, but an operation
such as~. will affect only the "X-value," as the name implies.

Of course, there are other solutions, too. For example, you could have
chosen to key in the numbers in the order you encounter them in the
problem: @ITOilENTffi)~~(±)(8)

But this takes more keystrokes than the other way. And besides, if you
limit yourself to this left-to-right method, you simply can't solve a prob-
lem like this one: 112 - (386,000 + {35.7 x (67.12 + {89.43)2)

You have only four Stack registers, remember; and the whole idea of
RPN is that you key in only part ofthe problem at once, reducing it and
simplifying it as you go. So the best way is always to work from the
"innermost" parentheses "outward."

Tools! Glorious Tools/ 59


)

Are you starting to get "oriented" to RPN?

Try Another: 6.7 +-V(6.7)2-4{3.9X2.12)


2(3.9)

Solution: Again, work from the "innermost" expression "out-


ward:"

~~~@BlliJ~G~
fil:Ifill~@BlliJB

Answer: 1. 30 ::=- /, 2 9 CJ 7

Getting easier, isn't it? And of course, with practice, you won't be
needing even to think about what's really going on in the Stack as you
do this. After all what would be the point of a more efficient form of
arithmetic if you spent a lot of time trying to remember how to do it and
why it works? ()
)
For now, though, check the Stack diagram opposite, just to be abso- )
lutely sure you know what you're really doing....
)
)
)
)
)
)
)

J
60 An Easy Course In Using The HP-428 )

)
T: 18.12 T: 18.12 T: 18.12 T: 28,791.50
Z: 18.12 Z: 28,791.50 Z: 28,791.50 Z: 28,791.50
----- 1-------1-------~ -----
1y: 28, 791.50 II y: 28, 791.50 II y: 28, 791.50 II y: 44.89
x~8, 791_.20 ~:J.J.=. ___ J ~:_:l4.§_9___ u x:_4=----
'---7 (fil1J _j' ~ ~ _j' ~ 0 _j'

T: 28,791.50 T: 28,791.50 T: 28,791.50 T: 28,791.50


Z: 44.89 Z: 28,791.50 Z: 44.89
----- 1-.------1 . - - - - -
lf--Y:_4,._.•..,,...,00,-----i ,_____ ___, 11 Y. 44. 89
II Y· 15. 60
x: 4. 00 x: 15. 60 x: 2. 12_

T: 28,791.50 T: 28,791.50 T: 28,791.50 T: 28,791.50


Z: 28,791.50 Z: 28,791.50 Z: 28,791.50 Z: 28,791.50
----- 1------- ----- -----
1Y: 44.89 II y: 28, 791.50 II y: 28, 791.50 II y: 3.44
x~3.~7__ i~J.!_.82___ x~~4_±__ x:J.J.=. __
(8J_j'~ 8 _j'~@ j'~~ _j'

T: 28,791.50 T: 28,791.50

T: 28,791.50 T: 28,791.50
Z: 28,791.50 Z: 28,791.50
----- -----
(8) --7 I y: 10.14 1 y:28, 791. 50 I

x: 7.80 x: 1. 30

Tools! Glorious Tools! 61


Changing The Sign Of A Number

Of course, if you're going to do much arithmetic, sooner or later you'll


encounter some negative numbers, so you'd better know how to handle
them, right?

Try This One: Find -4.56 x (3.4 + 6.79}

Solution: Press ~rn:Tili)[±)~(8)

Answer: -46. 47

See? The(+/-) key simply changes the sign of the


number in the X-register.

Of course,(+/-] goes both ways: It changes a posi-


tive number to a negative - and vice versa. Press
it again now to change the -46. 47 to 46. 47.

)
)
62 An Easy Coune In Using The HP-428 )
)
That(IDKey

Problem: What's 2,500,000 x 3,000,000?

Solution: 2 5 0 0 0 0 0 ENTER 3 0 0 0 0 0 0 X
Answer: 7. 50E 12

And what's that? It's just a shorthand way of writing


very large (or very small numbers), a notation called
"scientific notation," since scientists often need to use
such numbers. You'd read 7. 50E 12 as "seven-point-
five-zero times ten to the twelfth power."

Of course, you can key in numbers in scientific notation,


too. For instance, you can do the above problem without
even using the@) key: ~@nffi[8)

One More: Calculate (-3.46 x 109) + (4.23 x 10·1 )

Solution(s): r:n:::TilII+/-~~EJ, or
@IJ+/-~~EJ,etc.
Answer:-8.18E 15

You can use the[+/-) key at any time while keying in


a number. And in scientific notation you'll change the
sign of either the mantissa or the exponent - which-
ever part of the number you're keying in at the time.

Tools/ Glorious Tools/ 63


.J
The~ Key And mD
All right - you now know some basic arithmetic, how to use negative
numbers and a little bit about scientific notation.

But still, nobody's perfect. What do you do if you make a mistake while
keying in a number?

Like This: Suppose you wanted to multiply 56.87 and 23.4.

So you blithely rattle off crrrr::::IITI) ... (. .. oops).

Not To Worry: This is the main reason for the (B key. When you're
keying in digits, it is indeed a simple backspace
key, so use it as such....

First, back out your erroneous digits: (B(B.

Now key them in correctly: (!JI) and finish the


problem: (ENTffi)~. Answer: 1, 330. 76

Not too mysterious, right?

)
) OK, but what if you want to get rid of the entire number (i.e. "start
over") altogether? What if it's not just a digit or two-the whole thing's
bad? .. .

Try This: You want to add 1.61803398875 and 3.14159265359.

) 1 •61803398875ENTER

3 • 1 4 1 9 s 2 s s 3 s 9 . .. oops! - you botched that


second one -and it's going to be easier to start over than
~back to fix it. So you'd really like to clear that number
in the X-register entirely. But how?

Solution: Remember the~ menu? Press that key now and


choose the selection on the far right: l!D.

OK, you'venowclearedawaytheS.14195265359_ and


replaced it with just 0. 00. And here's your display:

So far, so good ....

Tools/ Glorious Tools! 65


Next Question: When you start to re-key in CIT:IillITiill]... , will
the 0. 00 be bumped up? That is, is the Stack Lift
enabled right now?

Hopefully not, right? After all, you still want to


add this number to what's in theY-register (1. 62 ).

Good News: The l!!ll function leaves Stack Lift disabled, so


the 0. 00 that you've temporarily placed in the X-
register (to clear it) does not "bump up" and get in
the way of your arithmetic - it's overwritten by the
corrected entry that you're keying in. HP designed
l!D that way, because they knew that the main
reason you normally use it is to correct an entry in
the middle of some calculation - and you don't
want the rest of the Stack "messed up."

So although most operations leave the Stack enabled (making it easy


to do chain-calculation arithmetic), there are two keys that disable the
Stack.

First, you had the [ENTER) key; now there's l!!ll, too.

66 An Easy Course In Using The HP-428 )


)
.)

)
Yes, But: Now repeat the previous problem - exactly- except
) this time do it the long way: "back out" the erroneous
number with the ~key.. ..

Guess What: It works the same way, doesn't it?

It's a fact: Whenever you use the~ key to clear the


very last remaining digit in the X-register, you are
actually using the 11!!!1 function.

)
Not only that: If you're not keying in a number at all, then~ is not
"backspace" at all - it's 11!!!1 then, also!

Prove It: Do some arithmetic (or anything else that leaves Stack
Lift enabled): O]ENTm)@)(±).

Now press~. Voila! That's not backspace -that's 1!!111.


It cleared the entire X-register and disabled Stack Lift.

So remember: [ENTffi) and l!!ll are the two common functions you'll use
that disable Stack Lift. And except when you use it to "back out" part
) of the number you're keying in, the~ key is also a convenient l!D key.

Tools! Glorious Tools! 67


I

Moving Numbers Around In The Stack

Those Stack diagrams were pretty helpful in understanding "where


the numbers go" when you're not using them, weren't they? After all,
you can see only two Stack registers at a time - the X and Y- registers,
so you must simply "imagine" the other two, right? ...

Hmmm - come to think of it - is there any way you can check the
current contents of those other two registers (Z and T) - without
messing up the values in the Stack?

You Betcha: Set up your Stack so that it looks like this:

T: 8.00
Z: 3.90
r._:-----------,
I y. 4.60 I
L 2<~9~~-------- _J

Now, your challenge is to replace that 3. 90 in the Z-


register with a 1. 30 -without changing the values in
any of the other registers.

Solution: First, you must set up the Stack: [IIENTERITEITJENTER)


~ENTER)~- No sweat, right? You've done
this kind of thing before.

Now for the "surgery:" @Ifil)(Bo:r:TIJ@Ifil).


Not bad, eh? See how this works?

68 An Easy Course In Using The HP-428 )


)
,I

The@) Key

The@) ("roll down") key causes the Stack to do just that - its contents
rotate or "roll down" by one register. The value in the T-registeris sent
down to the Z-register; the Z-value down to the Y-register, and so on,
and the value in the X-register is "rolled" up into the T-register to
complete the rotation.

So in a@), no numbers are lost; only their locations are changed. The
Stack registers are linked in a circular pattern (hence the "roll"), where
the bottom register (X) is connected to the top register (T).

This means that four consecutive [jff) 's will roll the Stack completely
around once -back to its original state. This is how you can quickly look
at all four values without changing any of them.

So in this last solution, the trick was to roll the Stack down twice - to
get the doomed 3. 90 into the X-register where you could clear it out
with the (B key. Then (because the (B key acts as a l!JJI in this case,
as you know), the Stack was left disabled, so you keyed in o:r::TIJ, then
rolled the Stack down twice more - that's now four@)'s in all - to get
back to the original positions of the values. Pretty slick!

)
)

Tools! Glorious Tools! 69


J

The [x~y) Key

There's one other key that you'll often find useful to manipulate your
Stack registers: The [x~y] key. Suppose that you wanted to ...

Do This: Set up the contents of the Stack as shown here (this


should be exactly how they ended up from the previous
problem, but if you want to review them quickly to
check, you now know what to do - ~ - right?):

T: 8.00

,--:-----------,
I
Z: 1.30
4. 60
y. I
L 2<:__9~~-------- _J
Now, the challenge is to reverse the order of these values.

Solution: As with most Stack manipulations, there are many


ways to do this, but here's one of the easier ones:
)
(Deceptively simple, isn't it?)

The [x~y] key ("X exchange Y")simply exchanges the values of the X- and
Y-registers-which is handy for all sorts of things (not just stupid little
exercises like the one above).
)
For example, the 8 and8 keys are defined only as "y + X" and "y - X"
-not the other way around. So, to divide or subtract in the other order,
you just use (x~y] once to swap the two numbers, then use 8 or 8 . )
)
70 An Easy Course In Using The HP-428 )
)
,)

Notes, Doodles, And Stack Practice

)
T: T: T: T:
Z: Z: Z:

~ ~ ~ ~
- ----<
Z: Z: Z: Z:
----- 1-------- - - - - - - - - - - - - - -
1-------ill~Y_
: ------ill~Y_:----ill~Y_:- - - - i
x: x: x:

T: T: T: T: - - - - - - i
1
Z: Z: Z: Z:
,-------~,-------i ------- -------
1Y: II y: ll y: ll~Y_:- - - - i
x: x: x: x:

~ ~ ~ ~
1 ------i
Z: Z: Z:
) r-.------ 1- .- - - - - - -.------~

1-------il I y. 11 y. 11 y. I
!:__ _____ J12<:______ I~:__ ____ _
j'~ j'~ _1'
)

Tools! Glorious Tools! 71


_}

The L-Register

OK, ok, now that you've got a little Stack practice "under your fingers,"
it's finally time to let you in on the big secret: "What-in-Lis the L-
register?"

Think of the L-register as an automatic precaution your calculator


takes, "just in case" you didn't really want to do whatever you just did
to the number in the X-register. That is, any time you do an operation
on the number in the X-register- anything that would affect its value,
- a "back-up" copy of that number is placed into the L-register.

In other words, operations that alter numbers (such as(±),@, and EJ)
will indeed save a copy of the X-value in the L-register before changing
the original in the X-register. But functions that clear or move numbers
around (like (B, [X~YJ,@l, and (ENTffi]) do not do affect the L-register.

"Fine- so what ifyou ever need to make use of this back-up copy? How
do you retrieve it?"

72 An Easy Course In Using The HP-428 )


)
The .LAST X) Key

) Here's the key for retrieving that "emergency copy" of the X-register
because you've made a little goof-up during your calculation.

Watch: You're trying to multiplyi/216.14 x {789f, but unfortunately


) youpress~@~EJ... uh-oh! Drat!
Now what? You could start over, of course, but why not use
the L-register?

First, press ~and (8)to undo what youjust did (thus


recovering ffib.14 ). Now press ~ again and pro-
ceed correctly: (8) Bingo! Answer: 9, 152, 117. 35

Keep in mind that when you use the ~ key, you're bringing a
copy of the L-register to the X-register; that same back-up value will
stay in the L-register until you next alter the contents of the X-register.

And you can also use~ simply to save yourself keystrokes ...

Like This: c 1 1 t 3.51 -(4.33 x 10·2)


a cu a e (4.33 x 10·2)

Solution: 3 • 5 1 ENTER 4 • 3 3 E +/- 2 - LAST X -:-

Answer: 80, 06

Tools! Glorious Tools! 73


I
Take a breather here for a moment and reorient yourself a little bit:

All this time (the last 25 pages), you've been learning and practicing
with the tools that are most immediate to your workbench- the Stack.
And look at what you know already:

• You know something about arithmetic - and about how Stack Lifts
(and drops) happen as you're doing a calculation;

• You know that most operations leave Stack Lift enabled-so that it's
ready to lift when the next number is put into the X-register- except
for (ENTER) and l!!lll;

• You know that the~ key can act either as a "backspace" (when
you're keying in a number) or as a convenient way to l!D;

• You know at least a few tricks for manipulating the values in the
Stack- moving them around without changing them -with the [x~y]
and @] keys.

• You know how to use the L-register and the~ key to recover
from an error with a back-up copy of the value previously in the X-
register.

So, in theory, you're perfectly comfortable with all these things, right?

But that's only theory....

74 An Easy Court1e Jn Using The HP-428 )


)
Reality Check*

) 1. To double the number in the X-register, you can use the keystrokes
(ENTs=!)@J(8) (three keystrokes). Can you accomplish the same
thing with only two keystrokes?

2. Compute -8.9 + (4.57 -(3.5 x fl)) .

3. Without using the (ENTffi) key, set up the Stack to look like this:

T: 1.6000
Z: 3.5000
1-.------1
1 y. 2.2000 I
x: 4.7000

4. Using the Stack you just set up in the previous problem - and
without keying in any numbers, compute:

(3.5 -2.2}2+4.7
1.6

) 5. What four keystrokes can completely clear all of the Stack reg-
isters? Don't use the menus for this procedure.

*AKA a"Pop Quiz"

Tools! Glorious Tools! 75


'
Real Answers

1. Yep: (ENTER](±). (Right? ... Right.)

2. Here are two different approaches:

Cf@@EITJ(8)CIT:.IillJ [X~YJ8 crr::IlliBlx~yJ8 or


Cf@lIEffi (8)[+/-) CIT:.IillJ (±)crr::IlliB 8~

Answer: 1. 90.

Do you see how you can use the [+/-] and ~keys to effectively
reverse the order of 8 and 8. respectively?

0
)
3. First, notice that the display should be set to FIX 4 decimal places
(press~. thenlilllJ@ENTER)). Notice also that the number in )
the X-register should be terminated (i.e. it must have no trailing )
cursor like this: 4. 7_). Here are some of the possible solutions:
u
)
crr::::IT) [x~y JlIEffi [x~y) ffi:::TIJ [x~y [fil) (1Eli) [x~y) or
)
GEITJ[ x~y) (B1Effi[x~y)CIT:li) [x~y)CIEli®) or
ffi:If)[x~vJx~y)~@IJ]J~[x~y), etc. )

The point is, almost any non-digit keystroke except [ENTER) or~ )
(l!!ll) leaves Stack Lift enabled and terminates your digit entry
(whereas [ENTER] disables Stack Lift and terminates digit entry).

76 An Easy Coune In Using The HP-428 )


)
)

Answer: 8. 9988

Wouldn't it be lovely ifthere were a "roll up" function to go along


with "roll down?" It sure would be a lot more convenient in this
case, wouldn't it?

Well, there is such an animal. It's a "hand tool" - like all the
Stack-manipulation tools you've been using up to now - but it
isn't used often enough to merit a key of its own. You'll find it,
therefore (along with all the "hand tools"), listed in the• CATALOG~
under IEll ("FunCtioNs").

Press •CATALOG] IEll ~(that's 14


~s - rolling backwards through the many pages of this huge
menu - which is the fastest way) to find the menu choice, OJI.

5. (BENTER{ENTERI'ENTER) or [[!ENTER~ will both work. Of


course, if you're allowed to use the menus, then ~ 1!§1
(Clear STack) would be the best choice.

Tools! Glorioua Tools/ 77


J

Bigger Hammers:
Higher Math And Other Number-Crunchers

All right, now that you've been introduced to the Stack and its tools,
you're going to start using them as you look at the other tools in your
workshop.

You'll notice that most of the common Stack functions have keys of
their very own (e.g. the arithmetic operations, [x~y),@), (ENTER),~' etc.)
- because you use them so often. You might say that the keyboard is
like a shelf built right over your "workbench," where you keep your
most-used tools "within easy reach" (i.e. you don't have to use menu
keys to go to the hand-tool storage area to "get" these functions).

Well, there are some other commonly-used "number-crunching" tools


on the keyboard- on that "easy reach" shelf, too - and now it's time to
get acquainted with them.

'
Exponentiation: Roots, Logs, And Powers

) The keys you need for any root, logarithm or power problems, are
located in the top row on your HP-428 keyboard.

Try This: Find (34.19 + /J


Solution: Press 3 4 • 1 9 ENTER 1 1 Vx + x2
or~[ENTER)(8)
or~(fil~

Answer: 1, 175. 1807

When it comes to squaring a number, you have all


sorts of options - including the ~ key.

Try Another: Find (4.56)3·6

Solution: Press ~ENTER]r:n::ffi~


Answer:235. 6532

Note that, like subtraction and division, the ~


(exponentiation) key is a function that requires you to
give the two numbers in a particular order; for expo-
nentiation, you need to enter the Y-value (the base)
first and then the X-value (the exponent).

Tools/ GloriolUI Tools/ 79


I
When you exponentiate, you're raising the base number to the power
indicated by the exponent, right?

Now go the other way: Ifyou have a number that is the result ofraising
a known base (say, 10) to some power, how do you find out what that
power was? You take a logarithm.

Answer: 316. 2278 Now, starting with this answer,


work back to find the power that 10 was "raised to."

Solution: [LOG) Answer: 2. 5000 Shur 'nuff!

Hmmm ••• : The LN function is the Natural Logarithm (base e); the
LOG function is the common LOGarithm (base 10).

However, there's a formula you can use to convert be-


tween the logarithm of any base, b, and the natural (LN)
)
base, e: ln(x) =logb(x)ln(b)
)

Verify this for the common LOG base (i.e. use x = 100 and )
b = 10: )

Solution: First, the easy way: ~ Answer: 4. 6052


)
Then the indirect route, using the above formula:
)
OJOIOJLOG)OJilifill9 Answer: 4. 6052
)
)
80 An Easy Course In Using The HP-428 )
)
Good Questions: What's the easiest way to key in the natural LN
base, e (to 12 digits, of course) on the HP-428?
)

How about the same approximation for re?

How much is e 1Q1t ?


Tte 10

Decent Answers: To get e, just compute e1: ~(to temporar-


ily see the 12 digits, you can press l(S80W) and
hold it down): 2. 71828182846

To get Tt, just press t i and 9S80WJ to peek:


3.14159265359

As for that bizarre and hairy fraction, do this:


~ti~~ti~~B
Answer: 0, 0544

Perhaps that last one threw you a bit.

Remember to treat a number base and its exponent together-as ifthey


were enclosed together in parentheses. When looking at the top half
(the numerator) of the fraction, you should see e(lO")-two numbers,
not three. The same goes for the bottom (the denominator) of the
fraction: rc(e 10). Ifyou do this, then knowing about RPN arithmetic and
how to work from the insides of parentheses outward, the problem is
much easier, right?

Tools! Glorious Tools! 81


Common Trigonometry

You' re slowly adding to your repertoire of workbench tools, aren't you?


You now know about the exponentiation tools within your easy reach.

Next, move down a row, and look at those functions on the three right-
hand keys. It's time you got comfortable with your basic trig tools ... .

What would you do, for example, if you encountered a problem like
this?
Atan(sin(22°) + cos(7t/6) + tan(-125°))

You'd whip out this book to review trigonometry, wouldn't you?*

The word trigonometry itself means "the measure of the trigon." And
if a pentagon is a five-sided figure, then a trigon must be ...yep-a three-
sided figure (also known as a triangle).

So trigonometry is "the measure of the triangle" - the right triangle,


actually. And long ago, somebody noticed the quasi-mystic relation-
ship between right triangles and circles.

Take a moment here and contemplate it.. ..

•Of course you would.

82 An Easy Course In Using The HP-428


Every point on a circle (centered at the origin of a coordinate system)
can define a right triangle:
B.....--,-...._

Each triangle is formed from a radius through the point and a line
segment perpendicular from the point to the horizontal (x-) axis.

The important question is how you know exactly which point on the
circle you're talking about. The points above have been given names
A,B,C, and D, but that isn't a very precise system.

Look at point A above. In order to get to A from the positive x-axis, you
must "sweep out an arc:"

Thus, point A can be "renamed" -identified instead as a measure of the


arc "swept out" bys the hypotenuse as it "sweeps" from the beginning
point (on the positive x-axis) counterclockwise to point A.

So, how do you measure this circular arc -in what units? The HP-428
offers you three different ways:

Degrees Radians Grads

Tools! Glorious Tools! 83


)

One way to measure arc is to split up the circle's total swept angle into
360 equal pieces. There are 360 degrees of angle (or arc) in a circle.

Another common method to measure arc has to do with the distance an


imaginary ant would cover if it were to start at the x-axis and crawl
along the circle until it got to the point in question:

5
-,·~

The total distance around the circle (its circumference) is always equal
to 21t times the radius of the circle. So if the ant walks around the circle
for a distance of exactly one radius, it will have walked an arc length
of exactly one radian. There are 21t radians of arc length in a circle.

Thus, you can measure circular arc either by the angle it sweeps out
(degrees) or by its length (radians).*
)
*The third method of measuring circular arc, as offered by your HP-42S, is not as common as the
other two, but you should know what it is. It was developed probably because 360 degrees is an
awkward, non-decimal number to work with. Thus, there are 400 grads of arc in a circle - or
exactly 100 in each quadrant (quarter part of a circle).

84 An Easy Course In Using The HP-428 )


The [MODES) Menu

So how do you tell your HP-428 what units you're using in your trig
calculations - whether you're talking in, say, degrees or radians?

It's easy - you just ...

Do This: Press~ (twice so that you don't EXIT after


the first selection). Now look at the first three menu items.

These items are the three possible methods of measuring


arc. One of them is selected at all times-the one with the
little box next to the menu choice.

Right now,~ is selected, so your HP-428 is "thinking" in


degrees. But it doesn't know what you are calculating in -
only what it is calculating in. And if you're calculating in
radians and it's calculating in degrees ... well, your answers
will be garbage. You must keep in mind which MODE your
machine is set to!

Actually, your HP-428 will remind you: Press the buttons


to choose IB and lfillllll. Notice the little annunciators, RAD
and GRAD, that appear when you do this. Now select DH
once again. See? If neither RAD nor GRAD is showing, then the
machine is in degrees - and the menu confirms this.

Tools/ Glorious Tools/ 85


So, what do you know about your workshop's trig tools so far?

• Every point on a circle defines a right triangle, which can also be


specified (more conveniently) by its arc measure;
• Your HP-428 lets you choose (with the~ menu) between
three different units of arc measure.

But do you remember why you want to measure arcs in the first place?
What does all this have to do with SIN, COS, and TAN -you know... trig?

The ratios of the sides of these right triangles are what make them so
handy for finding distances and angles that you can't easily measure
- such as the height of a skyscraper or the distance across a lake.

Here are those ratios for a right triangle defined by an arc measure of
angle 9:

)
x
)
SINe(()) = ~
r CO Sine(()) = f TANgent(()) = ~

cosecant(()) = y secant(O) = f cotangent(())= f


)
Thus, for example, to find SIN(22°), you must:

• find the point on the circle at 22 degrees of arc from the beginning
point (on the positive x-axis);
• look at the right triangle defined by that point;
• calculate the ratio y/r for that triangle.

86 An Easy Course In Using The HP-428 )


)
Now Then: No kidding - find Atan(cos(7t/6) + tan(-125°) + sin(22°))

Gulp: In this ugly problem, you have mixed units. Whenever


you see the little 0 mark, the angle is being expressed in
degrees; otherwise, it's in radians.

Also, you haven't been told in which angular units the


final ATAN should be calculated.

And keep in mind that ATAN(x) means "the Arc (or Angle)
whose TANgent is x." There happen to be a lot (mathe-
maticians say "an infinite number") of angles that have
x as their TANgent (and the same is true for ACOS and
ASIN) - because you can continue to sweep out arc by
going around the circle repeatedly (after all, 22° is the
same point on the circle as 36,000,022°, right?).

So your HP-42S makes the assumption that you want


the first angle it encounters that has x for its TANgent.
Now, knowing all that, how do you solve the problem?
Start in radians mode: .MODES) m . Then

~cos)~l!JBOlfill+/-lTANE]
Cill@ffi miliffi

Answer: 44. 4506 (degrees. You know this because this


is the last MODE you set- and neither the RAD nor the GRAD
annunciator is showing).

Tools! Glorious Tools! 87


Yes, But: What if you now want to see this result in radians? Do
you need to repeat the entire calculation?

Nope: Press •CONVERT.CONVERT). This menu allows you to


actually alter the number in the X-register from one set
of angular units to another (by contrast, when you
switch in and out of RAD mode, for example, this affects
only subsequent results-not the number already sitting
in the X-register).

To convert from DEGrees to RADians, choose 911 and


voila! Answer: 0. 7758

To convert back again, just press m!!I. )


()
Get This: You can even convert to and from Degrees, Minutes and )
Seconds! For example, when you solve for an answer in )
degrees (as you just did), it is given to you in "decimal )
degrees." That is, this 44. 4506 means "44 degrees, plus )
45.06/lOOths of a degree."
)

But press mm ... bingo! You now have 44. 2702, in )


HH .MMSS format (44 degrees, 27 minutes, 02 seconds). )
It's HMS (not OMS) because H is for Hours; hours and
degrees both have 60 minutes of 60 seconds each.

Press lllTI) now to convert back to decimal degrees.

)
88 An Easy Course In Using The HP-428 )

)
One More: Find cos 2(37°) + csc2 (48°) + sec2(156°)
)
Solution: There are two new problems here. First of all, in what
order do you use [cos) and~ Is it first the (cos] and then
the~ - or vice versa?

The correct method is the first one: you need to calculate


the COSine and then square the result.

Second, how do you calculate csc and sec? There are no


keys for those functions!

Well, if you noticed back on page 86, csc (cosecant) and


sec (secant) are the exact reciprocals of SIN and COS,
respectively. This means you'll need to use the recipro-
cal key,~. to calculate these functions. To find csc(48°),
for example, you'd first find sin(48°), then press~-

Now, knowing all that, turn to the task at hand:

~
~~(±)
OJ:ill]~~(Yill)

Answer: 3. 6468

Chances are, you're heartily sick of trig by now. But it's nice to know
you have all this right there "near your workbench" (on the keyboard).

Tools/ Glorious Tools/ 89


J
Speaking of chances, you haven't yet had a chance to explore one of
those menus you see sitting on the shelf in the HandTool Storage Area
(see page 18). Since you've seen some of what the keyboard has to offer
directly to your "workbench," how about a quick excursion into the
"tool room" to see what you can "bring" from there?

The~Menu

And speaking of chances, how are you at probability? As an example


of a set of hand tools stored under a menu key, look now at the llPROBJ
key and its menu (press~ now), and try this

Example: If you have 6 red marbles, 5 orange, 4 yellow, 3 green, 2


blue, and 1 purple - all in a leather pouch-how many
possible combinations of six marbles (any color and
never mind the order) can you draw out of the pouch?

What if you count permutations - where the order does


matter - but you take them out only 3 at a time?

Solution: You're really just asking how many ways you can com-
bine 21 objects, taking them 6 at a time. The COMBina-
tions selection in_ this PROB menu will tell you; press:
~ l!!Im Answer: 54, 264. 0000

If you want PERMutations in sets of three, then press:


(lliJENTER@) milD Answer: 7, 980. 0000. Press [EXIT~

90 An Easy Course In Using The HP-428 )


)
Aren't menus great? And what a collection of tools you have! Can you
imagine, for example, what it would be like trying to do such probabili-
ties calculations on your own - without such easy and powerful tools?
You might well end up ...
. . .losing your marbles.

1----------i~
I

A Deep Breath

To avoid even further marble loss, you'd better stop for a moment now
and survey where you've been and where you're going. This machine
is so jam-packed with stuff to learn that it's going to be very easy to get
lost in the forest while you're trying to learn about each tree:

• In the First Tour of your "workshop," you got an orientation of the


shop with the Big Picture, hopefully giving you a general idea of
what the machine was all about and how it was organized.

• Now in this chapter on Tools, so far you've learned only about the
Stack, RPN arithmetic, and some other some number-crunching
tools, including exponentiation, trig and probability.

So, what's next? Is this chapter finished now?

Not yet. Actually there are many other tools, but they don't all appear
in this Tools chapter. That would be a HUGE chapter-way too much. )
Besides, many of those tools wouldn't even make sense to you yet. )
)
Sure -there are some more you're ready for now-you'll see those next.
But others deal with variables (they'll be covered in the next chapter)
or programming (the chapter after that). And the Power Tools are
even big enough for a chapter of their own. u
So don't worry - you'll encounter each tool when it makes the most
sense to. Just keep this larger perspective as you continue now....
)
92 An Easy Course In Using The HP-428 )
)
A Complete Inventory Of Tool Menus

To help keep that larger perspective, go back and look at the Big
Picture (pages 18-19) once again.

You know now about the Stack, your arithmetic keys, Stack manipu-
lation keys, and some of the other "keyboard functions" that form your
"workbench and tools within easy (keyboard) reach." But now look for
a moment at all the tool menus in your workshop-menus that are part
of the different Storage Areas:

Hand Tools Menus

Uses Of Tools

~ Clear specific data or storage areas of your machine;


~ Control format of displayed data;
~ Set default data units and other machine features;
.CONVERT) Convert data between various units and notations;
~ Collection of probability functions;

SFLAGS) Control flags - useful in writing programs;


.PGM.FCN) Collection of other functions useful in programming;
9PBf@ Control output of machine to infrared printer;

(Up to now, you've seen the first five of these menus, because they're
useful in "number-crunching" on the Stack. But as for the others, you'll
see them when you learn about programming, later.)

Tools/ Glorious Tools/ 93


J
Special Use Menus

.CATALOG) Gives you access to and a complete inventory of all func-


tions, programs, and variables available in machine;
~ Gives you access to the ALPHA register and characters;
.CUSTOM) Calls a special menu that you have "custom-built" as a
convenient set of often-used tools and variables;
Allows you to actually build the •CUSTOM] menu by as-
signing tools and variables to it.
• TOP.FCN) Allows the selection of the top-row keys via a menu;

(Of these, you seen only the •CATALOG] menu so far, and now that you
know the basics of RPN "number-crunching" on the Stack, the other
Special Use Menus are what you'll see next.)

Power Tools Menus

~ Allows you to use of different number bases;


11£!0 Allows you to calculate definite integrals; )
~ Allows you to calculate and manipulate matrices; )
.SOLVER) Allows you to solve an equation for any variable in it; )
msrATJ Gives you access to statistical functions and analyses.
)

(Each of these power tools is involved enough to get a section all to itself
)
- but that's later - after you study variables and programming.)
)
94 An Eaay Course In Using The HP-428 )
)
}

Special Use Menus

Special Use Menus are named such because they just aren't like the
other tool menus. Make no mistake: They are tools - and important
ones. But they're somehow related to other menus in unusual ways,
and so they fall into this catch-all category.

For example, you've already seen the •CATALOG) menu (page 43).
Remember how it worked? You could use it to find and select any tool
or variable you wanted - no matter in what menu you could otherwise
find that tool or variable.

In this way, •CATALOG) was a "menu of menus" - a sort of master menu


(recall how it's portrayed in the Big Picture - pages 18-19 - as present-
ing you access to the storage areas through a set of windows).

Well, one way to think about the other Special Use Menus is that they
all provide some kind of "special access" to certain tools or menus.
}

The~Menu

The~ menu is a Special Use Menu. It's "where to go" whenever


you need to "spell out" anything. You may want to spell out a command,
a variable name, or build a character string (as data) to store, but no
matter what you spell - and no matter where you are in the workshop
- the "spelling tools" of the m:AlPEA)menu are always available to you.

Try This: Press ~- You should see the ALPHA menu:

In this particular example, the menu is displayed under the current


contents of the ALPHA register (it's empty). You "went" to the ALPHA
register here because you pressed •ALPHA]- no other keystrokes. That
told the HP-428 to save what you type as data in the ALPHA register,
rather than to use what you type as a command or a variable name.

Now This: Notice the T .A annunciator. Press either@ or~ to see


the other page of the ~menu.

You get quite a wide variety of characters to type, no?


)
)
96 An Easy Course In Using The HP-428 )
)
So, how's your typing?

Practice: Put HELLO THERE! into the ALPHA-register

Solution: First, press~ to get back to the first page of the menu.

..
Then: IETilm:J:llrnm!. . mml_.mml . . CE!Em!ll
!EiB_!i§i!ll1. .IETillDl~. .!i§i!ll1~rnm!. .
~~

Now, you can press either [EXIT) or (ALPHA) to clear the


menu and leave the ALPHA register....

Are your characters still saved in the ALPHA register?


Press 11ALPBAJ again to check .... HELLO THERE!

In this particular case, you "called" the llAlPBAJ menu right from your
"workbench" (the Stack). But keep in mind that you can also "call" the
~menu from within any other menu - and when you finish with
your typing (with [EXIT)), the machine will return you right to the menu
from which you "called."

Prove It: Enter another menu, say, llPROB). Now call the~
menu. There'stheALPHAregisteragain: HELLO THERE!

Now press (EXIT) or [ALPHA).... Sure enough-you're back at


the llPR08) menu, from where you did the "calling."

Tools! Glorious Tools! 97


J

The ~And •CUSTOM) Menus

Here are two more Special Use Menus.

The main task of the ~ Menu is to help you create your own
•CUSTOM] Menu - gathering together whatever collection of tools and
variables you might find convenient.

Watch: Press~· Here's what you'll see:

Notice that this~ menu is nearly identical to that of


.CATALOG] (recall page 43).
)

~ will let you search out and collect any functions )

CIEi), programs (IElJ), or variables (mil), DB, or mII) )


that you use frequently, putting them all together on one )
handy "shelf' - the• CUSTOMJ Menu. This searching proce-
dure works just like that in •CATALOG!; thus the similarity
)
of the menus.

So, what items do you want to gather into your •cusroMJ Menu? ()
)
)
)
98 An Easy Course In Using The HP-428 )
)
How About: Back on page 77, you noticed how useful the "roll up"
tool could be for Stack manipulations. The problem
was, it took a lot of "thumbing" through the pages of
the •CATALOG) menu to get to it.

Well, here's your chance to make it handier by put-


ting it on your •CUSTOM] Menu!

Here's How: Make sure that your~ Menu is showing, then


press: 11!31 .... .... .... .... .... .... .... .... .... .... .... .... .... .... om.
You should see:

Since you signified a completed selection when you


pressed om. the machine is now showing you your
•CUSTOM] menu (which is empty as yet).

You need to select the menu position where you'd like


m to be placed in your. CUSTOM) Menu. Put it in the
left-most slot for now (press the~ key).

Not too tough, right?

But did you notice that when you pressed 8ASSiGffi, the display showed
some quotation marks- as ifthe machine expected you to spell out the
name of what you were going to assign?

Tools/ Glorious Tools/ 99


J
Yep- as a matter of fact, you can do it either way: You can select what
you want from the~ menu or (if that's too much trouble - and
it was a bit of a pain here -with all the menu pages to flip through) you
can simply spell out the proper name of the tool.

Try Spelling: Assign the ID tool to your •CUSTOM] menu again -


but this time spell out its name rather than selecting
it from the~ menu.

Solution:

See how the [ALPHA] key helps you spell out the name
(and signal when you're done)?

Now all you need to do is choose where to put this


()
second ID on the •CUSTOM] menu (yes, you can put
multiple "copies" of the same tool on the •CUSTOM] )
menu): put it next to the first one (press the ~key). )
)
)
Notice that when you used the [ALPHA] key here, you didn't need to press
)
•first.

This is usually true whenever you're going to use the ALPHA menu to )
spell out the name of a tool, variable or command (rather than put
actual data into the ALPHA register): you don't need to press• first;
the context of your other keystrokes (in this case, 8ASSiGN)) will tell the
machine what you mean.
)
)
100 An Easy CouNe In Using The HP-428 )
)
J

Now Undo It: You don't really want two copies of the 1111 tool on
your •CUSTOM] menu, so here's a good opportunity to
learn how to "unassign" an item from that menu:

You simply assign a nameless item there instead - by


spelling out no name at all:

~(ALPHA]- but don't spell out anything - now


press [ALPHA] again (to end the "spelling"), and select
the second Ill! on the .CUSTOMJ menu ... bye-bye!

One More: Just so you know - besides tools, you can also put
variable names on your •CUSTOM] menu.

Recall, back on page 41, that built-in matrix variable,


REGS. You can save m!B for handy access in your
•cuSTOMJ menu (put it in, say, the fourth "position").

Here's How: ~IEilm!B [LOG]

Of course, you could have spelled it out instead:


~(ALPHAJ!immlDll~--(i!iITl~!imm. .
(ALPHA)[LOG)

But that would have been the less convenient method


in this case, right?

Tools! Glorious Tools! 101


Your Tools Can Work Together

As you learn about these Special Use Menus, it's important to realize
that there's a certain hierarchy to all the menus in your HP-42S.

That is, there are some fairly simple rules about which menus you can
"call" from which- and whether you will return to the "calling" menu
after finishing with the "called" menu.

The Stack and "bare keyboard" (no menus)

(-~~~~~~~P_o_w_e_r_~_o_o_ls~~~~~~__...)
()
( Hand Tools and Special Use Menus )
)
( ALPHA Menu )
(
)
If you call a menu lower than where you are, when you return, it will
be back to the menu from which you did the calling.
)
However, if you call a menu higher than your own level, you'll actually
be "jumping" to the highest level (the Stack) and "calling" from there;
for when you return, you'll return to the Stack.

Ofcourse, whether your returns are automatic or require you to use the )
[EXIT]key will depend on the circumstances. This hierarchy merely )
shows your return "destinations." Experiment with it until you get the
)
idea. Where do you return from a call at the same level where you are?
)
102 An Easy Course In Using The HP-428 )
)
/

The •TOP.FCN) Menu

With this hierarchy in mind, it's a lot easier to understand the reason
for this last Special Use Menu. You might have wondered why the folks
at HP put the six top-row keys onto its own menu as well ....

Try This: "Call" the Power Tool .SOLVERL Don't worry about what
you might be doing there. Just suppose you're there and
now, for a side calculation, suppose you find yourself
needing to compute (113)·5 •

Normally, you'd press ~(IEB~ But~ isn't


~right now. None of those top-row keys are "them-
selves" - they're menu keys instead!

Solution: •TOP.FCN) to the rescue:

Press .TOP.FCN.TOP.FCN]ffi mrIEB•m


Answer: 243. 0000

Notice that you're using the• key with a menu choice


here (because~ is an orange function on the keyboard).

This is the only menu in which you can do that; •TOP.FCN]


exists solely to preserve convenience in the hierarchy.

Press [EXIT) a couple of times now to return to the Stack.

Tools/ Glorious Tools/ 103


.I

Well, by now you must be feeling like a graduate of "Mr. Goodbench


Tool School."

Over the last 30 pages or so, you've seen quite an inventory of the
various tools in your HP-428, and its time you "graduated on to the
next part of the Course" to build something with all these tools.

But before you get going, maybe you'd better check your understand-
ing so you don't get bogged down later on.

Yes fans - that's right - ready or not, here it comes ....


)
)
)

104 An Easy Coune In Using The HP-428 )


)
Tool School Reviewal

1. Find V6561 , using two different methods.

log(122 +~)
2. Find
eJ

3. Find 9+-v'(l2x3.3}1.4 _75

4. If eighteen U.S. states and three Canadian provinces meet to


decide how to stop acid rain, how many ways are there to cast just
the minimum majority of "no" votes to prevent any action?

5. An arc measure of 180° is equivalent to 7t radians. Compute


sin(l 80°) and sin(7t) on your HP-428.

6. Find Acot(37t/4). Express it in degrees, minutes and seconds.

7. What display do you see when:

(a) you enter a Power Tool Room?


(b) from that Power Tool Room, you select a hand tool menu?
(c) from that hand tool menu, you use a particular hand tool?
(d) you then press~

Tools/ Glorious Tools/ 105


I

Tool School Reviewal Soolutions

L~or~
Answer: 3, 0000

Finding the "eighth root" is the same as "taking the l/8th power."
And then (6561) 118 is the same as (((6561) 112 ) 112 ) 112 , which is also:
../vv6s61.

2. 1 2 X 2 2 7 0 4 ENTER 3 ...;- + LOG 3 ex -;-


Answer: 0, 1503

3. ~CIT:TIJ8)~(filB@(fil)
Answer: 18, 8739

As always, work from the "innermost" parentheses or expres-


sions "outward."

4. The question is "How many different combinations of 11 'no' votes


are possible among the 21 voters?" (combinations, not permuta-
tions, because the order of voting doesn't matter).
)
A piece of cake for the ~ menu: )
)
Press (YIIENTER]QID~l!!Im
Answer: 352,716.0000

}
106 An Easy Course In Using The HP-428 )
)
5. sin(180°): ~lffillo:IillJ@m Answer: 0. 0000
sin(rt): ~IBti@m Answer: -2. 0676E-13

The difference is due to the fact that you're not really taking the
SINe of 7t radians. You're taking the SINe of 3.14159265359
radians - and that's different. Like any finite machine, the HP-
42S is limited to using an approximation ofa, not 7t itself. Nobody
can ever use the "exact" value ofany irrational number (one with
an infinite number of non-repeating digits).

Your HP-42S uses an approximation rounded at the 12th digit:


3. 14159265359. Since the true value of7t is 3.14159265358 ... the
12-digit rounding represents a slightly upward rounding. There-
fore, when "sweeping around" to find the corresponding point on
the trigonometric circle, your HP-42S goes slightly past where it
should be - exactly on the negative x-axis - thus extending
slightly below that axis and producing a negative SINe (which,
after all, is the vertical leg of the corresponding right triangle).

Interestingly enough, if you take the COSine of rr/2 radians, you


will get zero, but only because the error happens to be ''further
out" than the last digit used in this machine (i.e. a large computer
that carries more digits should not return zero).

The point is,your machine is being exactly faithful to the numbers


it is working with. It just never works with any truly irrational
value (e, rt, fi, etc.). And ifyou find a calculator (certainly not any
HP machine) that will give you exactly zero when you ask for
SINe(3.14159265359) - or exactly two when you ask it to square
1.41421356237 - feel free to be outraged: it's doing bad math.

Tools/ Glorious Tools/ 107


6. Hmm ... there's no ACOT tool, is there?

Nope. That's a problem .... Ah, but isn't Acot(37t/4) the same as
Atan(4/37t)? (think about it- and review page 86 if you need to).

To compute this, first make sure the machine is in RAD mode (by
pressing~ Bm!, if necessary).

Then press: ~X~YEJIATAN]


Answer: 0. 4014 radians

To convert this to degrees, minutes and seconds, first you need to


convert from radians to degrees:

.CONVERT)mE
Result: 22. 9970 (these are decimal degrees, remember)

Now convert to degrees, minutes, seconds: •coNVERT]mm


Answer: 22. 5949 (which means: 22° 59' 49")

)
)
)

108 An Easy Coun1e In Using The HP-428


7. (a) When you enter any Power Tool Room, you'll see the menu
for that Power Tool. For example, press: •SOLVER].

(b) When you then select a hand tool menu, you'll see (the first
page of) that menu. For example, press m@Q@.

(c) When you select a hand tool from that particular Menu, the
display will automatically revert back to the Power Tool
(unless you had pressed the hand tool menu key twice upon
entering that menu - step (b) above - in which case, the
display would return to the hand tool menu). For example,
press GB.

(d) Anytime you press~. you'll see the~


menu, indicating that the calculator is prepared for you to
spell out the name of a variable or a tool.

Tools/ Glorioru Tools/ 109


YOUR RAW MATERIALS:
Data And Variables >
)
)
)
Handling Data

If the functions and operations are the "tools" in your HP-428 work-
shop, then your "raw materials" are the data you "crunch" with them.

Remember (from page 36) that your HP-428 can handle four types of
data: real numbers, ALPHA-characters, complex numbers, and matri-
ces. It's time now to learn the details about how to name, store and
retrieve these various data types.*

How Do You Name It?

Most of the data you've used so far have been only temporarily useful.
That is, you used the numbers only once during a quick problem-
solving session; it hardly seemed necessary to name or save them.

But suppose instead that you're reusing a particular number fre-


quently in your calculations - and you're tired of keying it in every
time. What would you do?

You would save this number in one of those data-bins you can create
and name - a variable.

*Unless, ofcourse.you already feel comfortable with some of these things, in which case you should
skip ahead. So, ifyou already know about storing and retrieving real and ALPHA variables, skip
to page 126; ifyou also know about complex variables already, go to page 134; and ifyou also know
about matrices already, jump ahead to page 155.

YOUR RAW MATERIALS: Data And Variables 111


J

Example: Put the natural logarithm base, e, into a variable named


EE.

Solution: First, obtain the value of e (at least its 12-digit approxi-
mation): press~·

Now press [STO{ALPHA]. You'll see the following:

Here's that ever-useful mALP8AJ Menu again, waiting


for you to spell something out. In this case, it's the name
of the variable in which you're going to STOre e.
)

Notice that with ISTO] you don't need to press the• key )

before pressing [ALPHA]-just as with the~ Menu )


(recall page 100 ): the fact you just pressed [STO Itells the )
machine that you may want to spell something out now, )
so if you press [ENTER], it assumes you really mean [ALPHA].
)
So, press !llD . . rnim . . to spell "EE_, then press )
[ALPHA] again to tell your machine you've finished your
typing. )

That's all there is to it!

112 An Easy Course In Using The HP-428 )

)
)

)
Try Another: Store the value 6.92 into a variable named FRED.

Solution: ~putsthenumberin theX-register. [STOJALPHA)


then signals that you're going to store it in a variable
whose name you're about to type. Then:

lifilll. .~EllClD. .ClD. . types in 11 FRED_


and [ALPHA) signals the end of your typing.... Zing! -
you've just stored the value 6.92 into FRED!

Yes, but how do you know that your calculator has really STOred your
numbers? Is there a way to find out for sure - to verify this?

Naturally: Press [RCL).

Lo and behold, you now have Im and .:!JI - menu


items on the list of things you can ReCall!

So press .:!JI to bring that value, e, back into the X-


register.

See how [RCL) works in opposition to [sroT? And as soon


as you've named a variable, it will appear on the [STO)
and [RCL) menus - so you don't need to keep spelling it
out every time you want to use it - very handy!

YOUR RAW MATERIALS: Data And Variables 113


All About [STO)

There are a few important things to know about the [STO) key and what
you're really doing when you use it:

• First of all (as you probably already know), [sro] stores the value
that's currently sitting in the X-register. This means that if you
want to store a value now sitting somewhere else, you'll have to
bringit to the X-registerfirst (probably by using the [RCL)key), right?

• Secondly, [sro] is a copying process. That is, when you [sro] a value
into a variable, you are storing a copy of the value that's currently
sitting in the X-register. Notice in the previous examples that when
you finished ~ng, the value was also still in the X-register; only
a "clone" was sent into the variable.
)

• Since it is a copying process, [sro) doesn't affect the Stack very much.
It certainly doesn't lift the Stack or alter any value in the Stack
registers. But keep in mind, that, like most functions on your HP-
42S, [sro] will leave Stack Lift enabled - so that if the next action
taken brings a number to the X-register, the Stack will preserve the
X-register's previous contents by bumping the whole Stack up.

114 An Easy Course In Using The HP-42S )


)
All About [RCLJ

And now notice these details about [RCL) (compare them with (STo)):

• [RCL) recalls the value from wherever you specify and brings it to the
X-register - nowhere else.

• Whenever you [RCL] a value from a variable, you are actually making
a copy of that variable's value and placing this copy in the X-register.

• [RCL) does affect the Stack of course, since it's bringing a value to the
X-register. Does this new value "bump" the Stack up in a Stack Lift?
That depends. {RCL}behavesjust as if it were "keying in" the value:

If Stack Lift has been left disabled by the previous action (say, [ENTER)
or [B, for example) then this (copied) value that (RCL] is bringing to
the Stack will overwrite whatever had been in the X-register
previously-just as you would do if you were keyingin a value under
these circumstances.

However, if Stack Lift has been left enabled, [RCL] will bump every-
thing up and insert its new value underneath - again, just as it
would work for you ifyou were keyingin a value to an enabled Stack.

See how [STO) and [RCL) work together to help you save and retrieve data
conveniently? To make sure you understand, try a few more ....

YOUR RAW MATERIALS: Data And Variables 115


J

Examples: Press (IIENTER~ to fill up your Stack.


Now press (RCL] !ii!E.... Did the Stack Lift when you per-
formed this [RCLT?

Solution: Yep - press@) four times to check. ... The 1. 0000 that
had been in the X-register is now in the Y-register. This
is because the keystroke immediately prior to the (RCL)
was a digit-entry keystroke (a [D), which left Stack Lift
enabled. Remember that most keystrokes - including
the digit-entry keys - leave Stack Lift enabled.

Compare: Nowpress~ENTER). Then(RCL)!ii!E. Did


the Stack Lift this time?

Nope - because the previous keystroke was an (ENTER),


which always disables Stack Lift, right?

What If: You press @[sro) !iilE [RCL) !ii!E. How many copies of
4. 0000 will this produce? Where will they be located?

Solution: You'll have three separate values of4. 0000: the original
you key in, the copy of this original that you save into
IJll:E by pressing [STO), and then a copy of this copy that
you put back into the X-register when you press [Rel).
That's two 4. 0000's in the Stack (the original in the Y-
register, the second copy in the X-register) and one (the
)
first copy) in !ii!E!

)
116 An Easy Coune In Using The HP·42S )
)
And now, discover a few more places you can store things:

Try This: Calculate 5.67 x 7.833 and store the result in the data
register R08 (recall from page 41, these registers are the
individual elements that make up that built-in matrix
called REGS. By special design, remember, you're al-
lowed to refer to these elements individually by name).

Solution: crr::J1IT]ENTER] ~ ~(29 does the calculation,


leaving the answer in the X-register, as always.

Now rsroI-OI8) stores a copy of this result into the data


register Roa- That's how simple it is to use that built-in
matrix, REGS: you don't need to refer to REGS itself;
you simply name which of its elements you want to use!

Challenge: Put 8. 7900 into the Z-register without using lim or@).

Solution: Press ~6:.J. Surprise! You've just discov-


ered the hidden Stack Menu, which you find by pressing
either~ or (BfilJ. The 8 says you want to [STO YlRCL)
to/from a Stack register. In this case, you're copying the
value in the X-register (8. 7900), storing it directly into
the Z-register. And what happens to the number that
used to be in the Z-register? It's destroyed. Remember
that [STo) always overwrites the previous value in the
"destination" variable or register.

YOUR RAW MATERIALS: Data And Variables 117

)
J
There's one other clever thing that [STo) can do, too: It can work in
combination with the four basic arithmetic operators((±), 8 ,(8), and EJ)
to alter the contents of a variable or register.

Example: Multiply the value of FRED by 5 without bringing that


value to the X-register.

Solution: Press (IJ@IQ0 6iIB. The [STOIB) combination multiplies


the value in FRED by the value in the X-register.

And where does the answer end up? It's not in the X-
register-it's in FRED! Press [RCL)~ and see that it no
longer contains 6. 9200 (its previous value), but now
34. 6000 (fives times as much).

It'sasifyouhad temporarily moved the "arithmetic site"


to FRED: Whenyoupressed@fQIB)(instead ofjust[STO)),
the 5. 0000 from the X-register was copied into FRED, )
but instead of overwriting the previous value in FRED
)
(6. 9200) this "bumped it up somewhere" for a moment
- as if FRED had a "Y-register." Then the (8) combined )
the two values and left the result right there in FRED!
)
So this is how to use the [STO Ikey as a shortcut, doing two
things simultaneously: arithmetic and storage. Instead
of having to do [RCL) m:3l (IJ(?9[STo] liiIB, all you need to
do is (IJ[SToIB) IJm ! And you can do similar "on-site" )
arithmetic with the other operations, too.

)
118 An Easy Counte In Using The HP-428 )
)
OK, so how about [RCLT? Can you do this kind of shortcut with the [RCL)
key, too? Hmm ... how do you suppose a keystroke sequence like [RcLG
would work?

Try This: Divide the value of EE into the value of R08 and take the
square root of the result.

Solution: Answer: 31. 6437

In the case of[RCL), it's pretty clear what's happening-


and not that much of a shortcut: Normally, you would
say [RCL) IDI 8@; here you're saying [RCL8 ll!ll @.

Using "recall-arithmetic" is so straightforward that it's a good way to


remind yourselfhow "storage-arithmetic works:" Just picture yourself
looking at things from the variable's "point of view" instead of from the
Stack- so that your [sro) commands seem to be "recalling" values to a
"Stack" located in the variable!

-A
Real Variables
'
All this storing and recalling you've been doing so far has involved just
a couple of variables (EE and FRED).

And these are real variables because they contain real-number values,
right? So you should have a good grasp of how to create real variables
- but just to be sure, try one more.

Create: A real variable named LORI, containing the result of this


calculation: 56.89 + 3.562·15 •

Behold: ~®::Iill)~~B
That's the calculation (Answer: 3. 7104 ).

Now for the creation of the variable in which to store that


result:

And now, whenever you [RCL) or look in the •CATALOG], you'll find the
variable LORI along with EE and FRED.
0
)
All this should seem pretty familiar by now, no? )

)
)
120 An Easy Course In Using The HP-428 )
ALPHA Data And The ALPHA-Register

All right, so much for real variables. But recall (from page 38) that a
real variable is a named "storage bin" that can contain either one real
number (as in EE, FRED and LORI) or an ALPHA string (up to six
ALPHA characters), right? So, try one with a string now....

How 'bout: Put this ALPHA-string into a variable named HI:

HOWDY!

Shucks: First, press ~to get to the ALPHA-register. As


you know from page 96, when your press ~ like
this -with no preceding keystrokes -you'll be "sent" to
the ALPHA register, ready to key in some ALPHA data
(characters). The only way to get ALPHA data into the
machine is to key it into the ALPHA register (just as the
only way to get numeric data into the machine is to key
it into the X-register).

When you start to type, you'll overwrite whatever is now


sitting in the ALPHA-register: mrnlmlllrnTIEllilll'mm
llillrn:Irn. .m:m. . ~~...

Now press~ and key in the variable name: Im


mlllmrnl. . (ALPHA], then [EXIT] to the Stack and [RCL]
m, copying the value in - to the X-register: II HOWDY! II

YOUR RAW MATERIALS: Data And Variables 121


Notice in that last example that your calculator began by showing
'
ASTO __ (instead of the usual STO __ )when you pressed [sro).

This is because you were at the ALPHA menu (in "ALPHA mode") at the
time, thus STOring something directly from the ALPHA- register into
the named variable. In other words, you were Alpha-STOring.

ASTOring works as a copying process similar to@IQ)ring- except that


you copy from the ALPHA-register instead of the X-register.

Try This: Put the ALPHA-string, THE ANSWER IS, into a variable
named YEP.

Solution: Keying the string THE ANSWER IS into the ALPHA-reg-


ister is no problem:

llAi?BAJ mi!P1 . .ffillll lllll rm!I3 . . ~ IIID- ~


mim. .cmEICllOO!Pl. .mwR.,.ll!lill. .mi!Plml
~ l'mB- ~ ffillll . . OO!P1. . .

Now ASTOre it into YEP: (STO!ALPHA]l!Em. .rn:im. .


Clillrn. . (ALPHA).

Now press (EXIT), to get out of ALPHA mode entirely, and


check yourself by recalling a copy of YEP to the X-
register: (RCL) m

You see "THE AN" in the X-register(!)

122 An Easy Course In Using The HP-428 )


The Obvious Question: What happened to the rest of the string
that was supposed to be stored in YEP?

The Logical Answer: It never got there. Remember that a real


variable can hold at most only six ALPHA
characters. So when you use ASTO, it will
copy only the first six characters from the
ALPHA-register into the variable you
name.

Ofcourse, theentirephrase, THE ANSWER


IS is still in the ALPHA-register; nothing
has happened to it (since ASTO is a copy-
ing command, like [sro)). But YEP has
only the first six characters.

So while you're in ALPHA mode (i.e. you're at the ALPHA-register,


having pressed •ALPHA]), both the [sro] and [RCL] keys are automatically
converted into A@'.Q) and~ keys. Or, you can select them, mil!) and
E!iDI, in a menu - under acATALOG]IEll- if you'd rather.

Just remember that you're dealing with ALPHA data and the ALPHA-
register (and that you can't do any math with it).
But you haven't used ARCL yet! The (RCL) you used in the last example
was a normal (RCL) that put a copy of YE P's contents into the X-register
(remember? you pressed (RCL)after you had [EXIT)ed from ALPHA mode).

Just as ASTO had a few details to learn about, so does ARCL. ...

Such As: Use A(B£g to recall a copy of the contents of FRED to the
ALPHA register.

Solution: Go to ALPHA mode(~) and press [RCL) (which is


actually ~) lill!]J. You should see:

"""' ANSWER IS84.6000_


THE
lll!mlElil~rn!W!im!EIE!m

Do you see what's happening here? ARCL is indeed a


copying function (similar to [RCL)); it makes a copy of the
contents of the named variable. But when this copy is
sent to the ALPHA-register, it is appended to (tacked
onto the end of) any characters that are already there.

Since you already had THE ANSWER IS in the ALPHA-


register, ARCL appended to it the value it copied from
FRED (84. 6000).

So, whereas [ACL) may overwrite or "bump up" the con-


tents of the X-register (depending on the status of Stack
Lift), ARCL will always append to the ALPHA- register.

()
124 An Easy Course In Using The HP-428 )
<)
Yes, But: That phrase in the ALPHA-register isn't quite "pretty"
yet. Fix this small glitch and put in the missing space.

Hmm ... how do you edit the ALPHA-register, anyway?


With the X-register, remember, you could use the~ key,
either as a backspace or a l!!ll. Is there something
similar for ALPHA mode?

Naturally: It works the same way: When you're building a string,


by keying in (or appending) data to the ALPHA-register,
the~ key will indeed operate as a backspace -just as it
does when you're building a new number in the X-regis-
ter. And in both cases the cursor_ signals this status.

So, to edit this "string-in-progress," first backspace until


you've erased the FRED part:~- Then add
the space: l!LWJ-. Finally, A(Bfg liR!) once again (but
just press [RCL) m:!ll -you're already in ALPHA mode) ...
Aaaaaah-that's better!

OK, [EXIT) from ALPHA mode and press •CATALOGl#l• to confirm that
you've now created five real-type variables: ~'.::rm, l!illl), (ifil, and
IBlll (remember: variables containing ALPHA characters are real-type
variables, too)!

YOUR RAW MATERIALS: Data And Variables 125


Real data are the simplest data in your HP-428. And though ALPHA
strings are more complicated because they're linked collections of AL-
PHA characters, they're still fairly simple. Now it's time to start
looking at the other ones.

Complex Numbers

The first of these is the complex data type. Complex numbers are
mixtures (linked pairs) of real and imaginary numbers. A complex
number is the sum of a real number and an imaginary number.

An imaginary number (remember your algebra class?) is a number


whose square is negative . You represent such a number as a real
number multiplied by V-I Thus,

v-25 = 5Y-T = 5i (or i5)

where i = V-f (engineers often use j instead of i).


)
But how can you possibly add real numbers and imaginary numbers
together (like adding apples and oranges)? Well, you can do it because
it's not addition in the simple sense; it's "directional" or vector addition.
)

Consider this: If you're following a map and it tells you to go 3 miles


east and 2 miles north, then that's the most it can do to describe your
destination. You can't "add" directions; you can't say that your desti-
nation is "5 miles east-north" or something. Ifyou did that, you'd have
no idea if your destination were really 1 mile east and 4 miles north,
or 2 miles east and 3 miles north, etc.
)
126 An Easy Course In Using The HP-428 )
)
.J

Well, real numbers and imaginary numbers are truly different "direc-
tions," mathematically, and so you can't mix them directly. Instead,
you represent their mixture (a complex number) as coordinates (i.e. as
a vector) on a "map" (the complex number plane); the horizontal direc-
tion is the real direction and the vertical is the imaginary:

i3
Imaginary i2 • Complex number
i1

2 3 4 5 6
Real
-i2

The problem is, just as there are many ways to give directions to any
one destination on a map, there are many different ways to represent
complex numbers in the complex plane.

YOUR RAW MATERIALS: Data And Variables 127


J
For example, these formats all describe the very same complex "des-
tination:"

3+j2 3 + 2i 3.6(cos 0.6 + isin 0.6) 3.6 cis 33.7° 3.6L33.7°

So how do you know which notation to use with your HP-428? Well,
there are two common strategies or formats used to describe a complex
number's "destination" - rectangular and polar.

The rectangular format (the first two examples above) contains i or


j . Its method is simply to tell you to go "so many units east" (the real
direction), then "so many units north" (the imaginary, or i- direction):
y
i3
Imaginary i2 (3 + i2)
i1 y=2
x=3
x
2 3 4 5 6
Real
-i2

Your HP-428 will always display the rectangular form as 3 + i2. The
3 is the real (or x-) cofficientand the 2 is the imaginary (ory- )coefficient.
The other way to describe a destination is to give a distance and an
angle "north of east" (in either degrees or radians). This is the polar
format:

Imaginary i2 (3.6L33.7°)
i1

x
2 3 4 5 6
Real
-i2

Notice that simple trigonometry will tell you what the two rectangular
legs of this triangle are - simply from knowing the hypotenuse (the
distance) and the angle:

3.6cos(33.7°) =3 and 3.6sin(33.7°)i =2i

Therefore, you can get the rectangular "instructions" to your destina-


tion simply by saying 3.6(cos 33.7° + isin33.7°), or 3.6cis 33.7° for short.

And then remember that you can specify an angle either in degrees or
radians: 3.6(cos 33.7° + isin 33.7°) =3.6(cos 0.6 + isin 0.6), right?

Finally, you could dispense with any reference to the rectangular form
(i.e. omit the i notation altogether) and just describe your destination
with the bare minimum - the direct distance and angle: 3.6L33.7°

Since this latter form is so short and succinct, it is the polar form used
by the HP-428.

YOUR RAW MATERIALS: Data And Variables 129


OK, so your HP-428 uses 3 + i2 for a rectangular form and 3.6L33.7° (or
3.6L0.6 radians) for a polar format of complex number. But how does
it decide when to use each format? ... It doesn't -you do!

Watch: Find Y-25 . Express this first in rectangular format, then


in polar (degree) format.

Like So: Press @FR@ This is the rectangular form.


Answer: 0, 0000 i 5. 0000 (which means 0 + iS.0000)

Now switch to polar form: First, press •MODES.MODES]


and lml to switch to DEG mode (if necessary), then IEJilil.
Answer: 5, 0000 .i90, 0000

And what does the answer look like in polar radians mode?
To find out, press m. Answer: 5. 0000 .il 5708 I

)
)
The point is, it's always the same number; the~ menu simply )
offers you different display formats -just different descriptions of how
)
to get to the same complex destination:
)

)
)
)
130 An Easy Course In Using The HP-428 )
)
Seeing Vs. Doing: The Difference Between The
•MODES) and •CONVERT) Menus

Back on page 85, you learned how to change the units of angular
measure with the ~menu. When you went back and forth be-
tween, say, DEG and RAD, the number didn't change, did it? In order
to actually change the numerical value in the X-register, you had to use
the Cml and~ selections in the •CONVERT) menu, right?

So what's going on here with complex numbers? In that last example,


you were not at the •CONVERT] menu and yet you certainly seemed to
be changing numbers. When in POLAR mode, you went back and forth
between DEG and RAD - and didn't that complex number change?

No - only its appearance changed. Your HP-428 is being entirely


consistent: The only thing you change at the ~ menu is the
machine's interpretation of the values it's holding. And it will make
every effort to alert you to its interpretation.

In the case ofreal numbers, your HP-428 was saying, for example, "The
44. 4506 in the X-register is 44.4506 degrees right now, as far as I'm
concerned." Then, when you chose lirn!I, it said, "OK, now it's 44.4506
radians" (and it turned on the annunciator to alert you to this re-
interpretation). But it still had the value 44.4506 in the X-register. Now,
with complex numbers, there are simply more ways to alert you to the
current interpretation: The display changes the format of the number
itself - not just an annunciator. But the underlying value in the
machine's memory is still the same. You cannot actually alter a nu-
merical value with the lfMODES}menu - only with the •coNVERT}menu.

YOUR RAW MATERIALS: Data And Variables 131


Entering Complex Numbers

All right, now that you know how the HP-42S handles and interprets
complex numbers, you'd better learn how to enter them, no? So far,
you've encountered them only as results of your calculations. But what
if you want to key them in - build them from scratch?

Do This: Make sure you're in RECTangular Mode and press


(I} ENTERJG). COMPLEX).

See? acoMPLEX) will link together two real numbers in


the X- and Y- registers, combining them into a single
complex datum in the X-register: 5. 0000 i4. 0000

Now This: Press •COMPLEX) one more time. What happens?

Your calculator has now unlinked the complex number


that was sitting in the X-register, putting the first (real) )
coefficient into the Y-register and the second (imagi- )
nary) coefficient into the X-register.

What's going on here?


)
It's simple: •COMPLEX] forms a complex number when- )
ever you have real numbers in the X- and Y-registers.
But •COMPLEX) forms two real numbers whenever you
have a complex number in the X-register. OK?

)
)
132 An Easy Coune ln Using The HP-428 )
)
And naturally, you create complex variables to store complex numbers:

Try This: Store 5 + i4 as a complex variable named PLEX.

Solution: You do it the same way as with real variables: [STOlALPHA]


rnillm . . !!Im . . ri!lm . . ma'B . . [ALPHA].

If you press [EXIT)[RCL] you'll see that you now have two
menu pages of variables that you can [RCL] (the T•is on),
since you now have more than six such variables. And
pressing mB confirms that you've done it all properly.

Of course, you can also combine already-existing values ...

F'rinstance: Create a complex number from LORI and FRED, with


FRED the imaginary coefficient. Store the result of
this union in LORI.

Like So: [RCL) IE[I [RCL) mlJ .COMPLEX) [STO) l!illl)


Result: 3.7104 i34.6000

So from now on, you'll find LORI in •CATALOG) l!D,


because it's now a complex variable.

So real numbers can become complex numbers (but remember from


page 39 that ALPHA strings cannot be a part of any complex number).

YOUR RAW MATERIALS: Data And Variables 133


Using Complex Numbers

The Bad News: It's time for a review of the basics of complex-number
arithmetic.

The Good News: You get to use your calculator!

I
I
)

Try These: 1. (6 - i2) + (7.5 + i3.66)


~ I

2. (5L166°) - (-4L39°) )

3. (5 + i4.6) x (2.3 - i8.l)


)
4. (-3L7t/3) + (4L47t/5)
)
)
134 An Easy Course In Using The HP-428 )
)
)

Solutions: L (SJOOER) ~.COMPLEX) crr::rrlENTs=I) m::nm


•COMPLEX](±) Answer: 13. 5000 i 1. 6600

Notice that you need to use a negative number (-2)


as your imaginary (''i'') coefficient; your calculator
always assumes a plus sign between the two parts
of a complex number unless you say otherwise.

2. ~ rn (illNTER) Cillli) .COMPLEXJ GEE)


(ENTs=i]crrfil •COMPLEX](notice here that your HP-
428 changes the -4 .i39 (the number you input)
into 4 .i-141. It will do this whenever you give a
negative distance in polar mode like this. It's just
another way to indicate the same value; it changes
neither the problem nor the answer*). Now 8.
Answer: 4. 1143 .1115. 0633

3. ~ lil:m ~.COMPLEX) 0::li)


[ENTs=!JlIEID+/-) .COMPLEX)~
Answer:48.7600 -i29.9200

4. ~rn~lil'illlffi+/-}ENTs=!]l[iijEN@J
~~~fi~(18
.COMPLEX]E)
Answer: 0. 7500 .i1. 6755

*See page 92 of your Owner's Manual if you'd like more details about this conversion.

YOUR RAW MATERIALS: Data And Variables 135


What Are Complex Numbers Good For?

OK, so you now know how to do complex arithmetic. So what? What's


so outrageously useful about complex numbers?

Well, for one thing, remember that a complex number is nothing more
than a two-dimensional vector - a pairing of two different coordinates
or directions (recall page 126). And those directions don't have to be
limited to "real" and "imaginary."

Sure -when you want to do certain kinds of arithmetic with a complex


number, the machine will naturally assume it's made up of a real and
an imaginary part, mathematically speaking. But there are some
vector operations - such as addition and subtraction - that are valid
for any kind of two-dimensional rectangular or polar coordinates.

Thus, you could use the two parts of a rectangular complex number to
represent, say, a position (north and east) on a map. Or you could rep-
resent a velocity (speed and direction) as apolar complex number.

For example, a complete descrip-


N
tion of a plane's velocity might be
"450mphonaheadingof95." This
)
velocity might be represented as
the polar vector 450L95°. w 2700 f-------ic-----1900 E
)
)
On a navigator's coordinate sys-
tem (shown here), a heading of95 180°
means the plane is flying almost s
(just south oD due east.

136 An Easy Course In Using The HP-428 )


)
}

)
Challenge: Assume the pilot of a plane has its nose pointed on a
heading of 95 at an airspeed of 450 mph. But he also has
a hefty cross-wind of56 mph blowing at a heading of167.
What is the groundspeed and true heading of the plane's
flight?

Solution: The engine velocity and the wind velocity must be added
together to find the total plane velocity. You can add
these two vectors by treating them as complex numbers.
So the problem becomes: 450L95° + 56L167°.

To solve: ~ GEi ~®I) •COMPLEX]


~·COMPLEX](±)

Answer: 470.3302 ~101.5020.

The plane is traveling about 470 mph on a heading of


101.5° -which makes sense, because the wind is pushing
it south and slightly east, thus increasing its speed.

Notice that this navigator's coordinate system is different than the one
you saw on page 128 for complex numbers (and on page 83 for trigo-
nometry). But this vector math still works!

The beauty of vector math is that it doesn't matter where you call
"zero," as long as you're working with a rectangular or polar coordinate
system; you'll always get answers consistent with- and correct for -
the system you're using!

YOUR RAW MATERIALS: Data And Variables 137


One More: Ernie, Frank and George are moving a boulder. George
shoves it with a force of195 Nata bearingof 105. Frank,
pushes 30° more northerly than George, with a force of
175 N. Ernie, on the other side, pulls on a rope with 180
N, due east. What's the net force exerted on the boulder?
N

George
W 270° f--~!}----~~~Ernie

Frank

180°
s
Solution: Like velocity, force is a vector quantity, with both mag-
nitude and direction. To solve this problem, you must
sum the three force vectors: George's force vector is
195Ll05°, of course, and Ernie's is 180L90°. The bearing )
at which Frank is pushing is (105-30), or75, so Frank's )
force vector is 175L75°.
)

Thus: •01spijlfl@TI) CiffiilENTER) (]Eill •coMPLEX) )


CIXfilJ~ ~ ~ (ill) )
•COMPLEX)(±) Answer: 537. 4 6:90. 6 )

)
So the boulder rolls away at a heading of 90.6° (almost exactly the
direction Ernie is pulling - very efficient of them). And the total force
acting on the boulder is 537.4 N. )
)
138 An Easy Course In Using The HP-428 )
J
Again (as these examples illustrate): Although complex numbers are
themselves mathematically meaningful (and there are plenty of opera-
tions that use them as such), you 're not limited to using them just as
complex numbers. You can also use them as two-dimensional vectors.

In fact, you can even use them for non-vector applications - simply as
a convenient ways to group related number pairs. Because you can pull
complex numbers apart and put them back together again, you can
give your own meanings to the complex number data type in the HP-
428 - meanings unrelated to the mathematical concept of complex
numbers or directional vectors of any kind. You can use complex
variables simply to store and manipulate ordered pairs of real num-
bers - information objects for you to use in whatever way you see fit.

Try This: The heights and circumferences of a grove of trees are:


18 feet and 24 inches; 25 feet and 23 inches; 28 feet and
29 inches. What are the average height and circumfer-
ence of these trees?

Solution: Enter the information as three rectangular complex


numbers, then add them together:

~~COMPLEXITIIJENTERfIGJ•coMPLEX)
®I)[ENTER)@li).coMPLEX]ffi±).

Now divide by three: ffi3 Answer: 23. 6 i25. 6.


So the averages are about 23.6 feet of height and 25.6
inches of circumference.

YOUR RAW MATERIALS: Data And Variables 139


Matrices

Real Numbers? .. .("Check!") .. .


ALPHA Strings? ... ("Check!") .. .
Complex Numbers? .. .("Check!") .. .

Matrices? .... Ah, yes .... Looks like you're now ready to study this fourth
and final type of data. Matrices are the most powerful and most
involved of all the variables and data types - so much so, in fact, that
the HP-428 workshop has an entire work area dedicated to helping you
build matrices (see the Big Picture on pages 18-19 for a quick
reminder) .... Welcome to your first Power Tool!

A complex number was a simple linking of two real numbers, right?


Well, a matrix takes this linking idea one step farther. It links together
two or more numbers in a particular order, grouping them in rows and
columns. The dimensions of a matrix are the numbers of rows and
columns it has. Look at these examples:

l
2x3 3x2 1x5 3x3 3x1
l
[4 5 9
2 -2 I
[~ ~ l [-3 9 0 7 2 J 1 0 0
[ 9 -3 5
2 7 -1

The number ofrows is always listed first, then the number of columns.

Hmm ... If you think about it, a complex number (or any two-dimen-
sional vector) is really just a small (1 x 2) matrix, right?

140 An Easy Course In Using The HP-42S


What Are Matrices Good For?

Matrices are incredibly useful tools for solving problems. That's why
your HP-428 devotes so much power and memory to them. They allow
you to solve large (or small) systems of simultaneous equations in ways
much faster and easier than any other. You'll find these systems in
physics, engineering, economics, business, and most other sciences
and social sciences.

Matrices are essential to computer-aided design (CAD) systems, be-


cause they make it easy to "rotate" a graphic image through space.*
And astronomers and engineers use them to calculate trajectories of
heavenly bodies and space shuttles as they hurtle through space.

Matrices are helpful in spreadsheet analysis and many sophisticated


types of "what-if' modelling in business and finance, and they're
widely used by computers to provide quick, efficient sorting routines,
making this information age possible.

And best of all, matrices give you the only feasible way to calculate
physical phenomena in higher dimensions (part time! on weekends!).
With matrices, you can describe how subatomic particles move through,
oh, say, 10 or 11 dimensions -whatever you need to make your calcu-
lations come out right (without even building a clay model)!

*Yes, Virginia, there really is a matrix in your video game.

YOUR RAW MATERIALS: Data And Variable• 141


Entering Matrices

So how do you get a matrix into your calculator? You need to start
learning to use that Power Tool Room now.

To begin, suppose you wanted to enter the following 2 x 2 matrix:

What do you do?

Well, the very first thing to do is tell your machine the dimensions of the
matrix you're about to enter. It needs to prepare the necessary amount
of storage space before you dump in a bunch of data.

Press~ to place 2. 0 in both the X- and Y-registers. When you


)
dimension a new matrix like this, your HP-428 will assume that the
number ofrows in the new matrix is entered in the Y-register and the
number of columns is in the X-register.
)I
)

Press •MATRIX) to enter the Matrix Power Tool Room. You'll see its
Main Menu:

The annunciator, T .a., tells you that there are more pages of menu items,
- but first things first: Choose Cim, to declare this new matrix you're
)
creating, and notice what happens ....
)
142 An Easy Course In Using The HP-428 )
)
See? Your calculator has combined the row and column dimensions you
just entered into one single dimension statement (similar to the way
• COMPLEX]combines theX- and Y-registers into one complex datum) in the X-
register:

TA
x: [ 2x2 Matrix J
Ciml!aDDiIBmmmmD

In effect, your HP-428 is now saying, "OK, I've got this 2 x 2 matrix
sitting in the X-register, all ready to edit or crunch."

Great.

Only problem is, there's nothing much to edit or crunch yet. This
newborn matrix is still full of zeroes and unnamed; in order to put some
meaningful data into it, you need to use the Matrix Editor!
You find the Matrix Editor by choosing Im):
.......
1:1=0.0
IDll!l!l. . . .rnm. .

This menu now tells you that you've taken this current matrix (the one
that was in the X-register) into the Matrix Editor, where you must go
to enter or change any of its data.

While in the Matrix Editor, you'll see only one element at a time. For
example, upon first entering the Editor here, you'll see the upper-
leftmost element in the matrix: The notation, 1: 1=0, 0, means that
the matrix element at row 1, column 1 is currently the real value 0, 0.

As a reminder, here's the matrix you're trying to build:

[ ~ 1]
You need to key in 0 in this window and then move the window one
column to the right by pressing llJlll.

For element 1:2 (that's row 1, column 2) enter: (IJ+;-]SJll. Since 0


you've no more room to move right one column, pressing ml moves
the window to the leftmost element in the next row (2: 1).

Finish keying in the matrix: @)11110 and then (EXIT] the Matrix Editor
(going back to the Main Menu of Matrix). This essentially places this
newly-edited version of the matrix back into the X-register, replacing
the previous version.

144 An Easy Course In Using The HP-428

)
.J

Storing Matrices

Before going any further, you should store your matrix into a named
matrix variable. After all, entering the data into matrix is a tedious
task, and you don't want to do it more than once. Remember that this
matrix can get bumped off the top of the Stack just as easy as any other
datum!

So press (SfOfACP8A) MATT[ALPHA) (by now, you've certainly got the hang
of using the ALPHA menu to spell out names and things, so you're not
going to see all those hideous "typing" keystrokes anymore - just the
letters themselves - you know what to do, right?).

It's just as simple as storing into any other kind of variable, right? You
now have a brand-new matrix variable named MATT.

Try recalling it: First press~ to clear the X-register. Then [RCL) lmll.
There's MATT!
Editing Matrices

Suppose now that you want to edit MATT.

Try This: Replace MATT's element 1: 2 with the value 6. 0.

Solution: To make a change in an existing matrix, you have a


choice:

You can [RCL) it to the X-register and then enter the


Matrix Editor with the lml command, which always
works on the matrix currently sitting in the X-register.

Or, you can avoid having to bring the matrix to the X-


register at all: Press (!) (to go to the next page of the (
Matrix Main Menu), then select~ (try this now) .. .

You'll see a menu of existing matrix names. Choose llJlill


and there you are, in the Matrix Editor, working on
MATT.

So press the arrow keys (you choose which ones) until


)
you come to 1: 2=-5. 0. Then key in the new element,®·
and hit [EXIT] to leave the Matri.x Editor. )

Done!

146 An Easy Course In Using The HP-428 )


)
But that's only one way to edit a matrix -changing its values. You can
also change its shape ....

Like This: Convert MATT into this 2 x 3 matrix:

[ 7 6 -3 ]
3 4 8

Solution: Put the adjusted dimensions into the Y- and X-registers,


~. and select ElII IElll to re-dimension MATT.

Now reenter the Matrix Editor with Imm. mii) and find
the last value in the first row 1: 3: 1: 3=3. 0

Hmm ... if it's "new," why does it already contain the


value 3. 0?

It's because when it makes an existing matrix larger


(more elements), your HP-428 moves the existing ele-
ments as far "up" and "left" as it can (filling the larger
matrix in "row-major order"), leaving zeroes in the extra
"new" elements:

[74 63 ] - - - - - 7 [7 6 3j'
4 0 0

Keeping this in mind, key in ffi+1-J IOI@:) IOI 0 IOI


and @[EXIT) to complete the change to the matrix at the
top of the page.

YOUR RAW MATERIALS: Data And Variables 147


Complex Matrices

Back on page 40, you learned that a matrix can contain either all real
elements or all complex elements, but not a mixture. It's time to see
how complex matrices work.

10 + i4 i58 ]
Example: Create this complex 2 x 2 matrix: [
-3 + i2 -17
How To: First, create a real 2 x 2 matrix: ~@}ENTER) mm.
Next, copy it to the Y-register, (ENTER), then combine the
two real matrices into one complex matrix by pressing:
• COMPLEX]-just like you did to create a complex number )
from two real numbers! 0

Now, in rectangular mode (9MODES) rn:ID, if needed),


press IEII and key in the values:
~·COMPLEX) IDl@)ENTER)@lij.COMPLEX)
IDl@J+/-HENTER)@).coMPLEX) IOI OJII+!-][EXIT).

That's all there is to it! Now store a copy of this complex


matrix for later: [STO}ALPHA) PIXY (ALPHA)

Finally, just for show, split it into two real matrices:


•COMPLEX) will now unlink the two parts of each element
of this complex matrix. The real parts form a matrix in )
the Y- register; the imaginary parts in the X-register!

148 An Easy Course In Using The HP-428


J

What You Can Do Th A Matrix

Whether it's real or complex, there are a number of things that you can
do to a matrix once you get it into the X-register.

The first category of things you can do is called scalar arithmetic. This
is where you do something - the same something - to each element in
the matrix. In the world of matrices, a simple number is called a scalar.

Example: Multiply the real matrix, MATT, by the real scalar 4.7.
That is, multiply each element of MATT by 4.7.

Solution: Press [RCL) mm ffi:Ifl~. What do you get?

A scalar arithmetic operation always preserves the di-


mensions of the matrix involved - so you certainly get
another 2 x 3 matrix (as your display tells you). But to
see the exact elements of the solution matrix, use the
Matrix Editor (via IEi), since you have a newly created
matrix in the X-register, not a named one):

[ 32.9 28.2 -14.1]


14.1 18.8 37.6

Ofcourse, you can combine a matrix and a scalar in any ofthe four basic
arithmetic operations.

Press [EXIT] now, if you're still in the Matrix Editor.

YOUR RAW MATERIALS: Data And Vari.ables 149


And you can do storage arithmetic (recall page 118) with scalars, too.

F'rinstance: Subtract 1 from each element in MATT.

Solution: [D[sroB lmill: That's it. And if you edit MATT now,
here's what you'll see:

[6 5 -4]
2 3 7

How about some of the other one-number functions- such as@ or~
How do they work on a matrix?

Find Out: Take the square root of MATT: [RCL) Imill

Ooops: An error message? It's because you tried to use@while


still at the Matrix Main Menu. @has a totally different )
meaning whenever a menu is displayed. Either you )
must [EXIT) the MatrixArea altogether, then~ ImiiJ@;
or you can recall page 103 and do this: •TOP.FCN) FE:iil... .

.. .Now what? The message, "Invalid Data" shows be-


cause you're trying to put a complex number into a real )
matrix. MATT has one negative element (1: 3=-4. 0)
and V-4 is a complex number -which you can't put into
a real matrix.
u
u

150 An Easy Course Jn Using The HP-428 )


)
J

Special Matrix Functions

) In addition to scalar arithmetic, there are other one-matrix functions


that are unique to matrices. For example, you have some functions
that reshape or re-order a matrix ....

Try One: Make sure you're looking at the Matrix Main Menu,
then [RCL) MATI and choose Dm. What happens?

Result: MATI is transposed - the rows become columns and the


columns become rows - and its dimensions change from
2 x 3 to 3 x 2:

You also have these two functions that let you expand or shrink a
matrix - by a whole row at a time:

(!)Em Adds or "inserts" a whole new row of elements before (above)


the row you're currently viewing. The new row will be filled
with zeroes until you change them.
(!) fil3!il Removes or "deletes" the whole row of elements that you are
currently looking at (unless it's the only row left).

Of course, you may not yet see when and why you'd want to use such
)
reshaping functions, but it's good to know that they're there (you'll see
some examples of their uses in upcoming problems).

YOUR RAW MATERIALS: Data And Variables 151


So, what other one-matrix "stuff' can you do? Well, with 11i1IT:), II.ml,
and Fm), you can re-shape a matrix in such a way that it doesn't matter
what shape (i.e. what dimensions) the matrix has to begin with. But
there are two very useful and important matrix functions that work
only on a square matrix: Im and mJI.

The first of these, El'.I, is the inverse or reciprocal function. Recall from
your school days that the multiplicative inverse of a number is what
you must multiply it by to get 1. So, for example, 1/3 is the multiplica-
tive inverse of 3, because 3 x 1/3 = 1.

But what's the inverse of a matrix? There's nothing you can multiply
by a matrix to give you 1. Besides, you don't want a 1, anyway; you want
the matrix equivalent of 1-the matrix identity, which, when multiplied
by any matrix, gives you the matrix back again Gust as multiplying any
number by 1 gives you the number back again).

Identity matrices are all square matrices with 1'son their left-to-right
diagonal elements and O's everywhere else, as in these examples:

1 0 0
[0 1 0
0 0 1
l 1000 ]
[0 1 0 0
0 0 1 0
0 0 0 1
The multiplicative inverse of a matrix, then, is another matrix, which,
when multiplied by the original, gives you an identity matrix in the
pattern of those above. And it turns out that the only matrices that have
these inverses are square matrices.

152 An Easy Course Jn Using The HP-428 )


)
Your calculator makes it easy to find the inverse matrix of a square
matrix- if that matrix is sitting in the X-register. So ...

Try One: Make MATT into a square matrix by deleting its last
column. Then find the inverse matrix of MATT.

Solution: To delete a column is a little bit tricky. But deleting a row


is easy. In this case, you want to eliminate elements 1: 3
and 2: 3 (see page 150 for the current picture of MATT).

So, first TRANspose the matrix, so that the unwanted


elements become 3: 1 and 3: 2 - sharing the same row:
[RCL)ll][iJ IJZil:I,

Now you can delete that entire third row by entering the
Matrix Editor (IEII), moving to that row with the arrow
keys, and pressing~ m!jlEXff).

Now TRANspose back again to get your new, pared-down


MATT. Store this new matrix as MAT ([STO)(ALPHA] MAT
(ALPHA)), then go ahead and use Ila to find the MAT's
inverse matrix. Pressing ~UBl]TI) and then mil
shows you the inverse matrix:

[ 0.375 -0.625
--0.250 0.750
l
Now [EXIT) the Matrix Editor and store this inverse
matrix as TAM.

YOUR RAW MATERIALS: Data And Variables 153


The other important one-square-matrix function is the determinant.
The determinant of a square matrix is a real number-calculated from
the matrix elements - that tells you something about the matrix.

Example: Find the determinants of TAM and MAT.

Solution: For TAM, you need only press IDI, since TAM is still
sitting in the X-register from the previous problem.. ..
Answer:0.125

To find the determinant of MAT: !RCL) GilII DB:


Answer: 8. 000

TAM and MAT are multiplicative inverses of each other,


right? What about their determinants (now sitting in
the Y- and X- registers, respectively)? Press [29 to see .. ..

Unity, Identity, Oneness, Reciprocity! 0 Wow!


}

Now that you have an idea about what you can do with only one matrix,
what types of manipulations can you do with two matrices?

What You Can Do With Two Matrices

Of course, what you normally want to do with two matrices is arithme-


tic - combine them - right?

OK, but before you get started with that, consider this: When you do
operations involving two matrices, it's important to pay attention to
their dimensions. There are strict rules about how matrices can
combine with another. And when you violate these rules on your HP-
428, it'll tell you: Di Mensi on Error . So remember these rules:

Rulel: When adding or subtracting matrices, you must always use


two matrices with exactly the same dimensions.

You simply cannot add a 2 x 3 matrix to a 3 x 2 matrix,


because the definition of matrix addition (or subtraction) is
simply to add (or subtract) corresponding elements - so
your result would necessarily need to be a matrix with
those same dimensions.

Rule 2: When multiplying two matrices together, the order that


you multiply is important! And the number of columns in
the first matrix must match the number of rows in the
second matrix.

YOUR RAW MATERIALS: Data And Variables 155


This is because the definition of multiplication is row x
column: You multiply the elements in the first row of the
first matrix by their corresponding elements in the first
column in the second matrix - then sum those products to
get the first element of the resulting matrix:

[~ ;l[
-1 1
4 -3 -2 0 =
1 -2 0 3
l
3(4)+2(1) 3(-3)+2(-2) 3(-2)+2(0) 3(0)+2(3) J [ 14 -13 -6 6
[ 4(4)+5(1) 4(-3)+5(-2) 4(-2)+5(0) 4(0)+5(3) = 21 -22 -8 15
-1(4) + 1(1) -1(-3) + 1(-2) -1(-2) + 1(0) -1(0) + 1(3) -3 1 2 3

Thus you can multiply a 3 x 2 by a 2 x 4, but you cannot


multiply a 2 x 4 by a 3 x 2. And a proper solution matrix will
have the same number of rows as the first matrix and the
same number of columns as the second matrix. So in this
example, you get a 3 x 4 solution matrix.
)
)
Rule 3: When dividing matrices, the dividend (the first) matrix can
have any dimension, but the divisor (the second) matrix
must always be a square matrix with the same number of
rows as the dividend. Thus, you can divide a 2 x 3 only by
a 2 x 2, and a 3 x 2 only by a 3 x 3.
)
Why? Because dividing is really the same process as multi-
plying by the inverse. And as youjust learned on page 152,
only square matrices have inverses (and these inverses
have the same square dimensions) - so only square matri-
ces can be used as divisors!

156 An Easy Course In Using The HP-428 )


Examples: You have six matrices with the following dimensions:
)
A: 3x4 B: 2x3 C: 3x3
D: 4x2 E: 3x2 F: 2x2

Decide whether the following operations are possible. If


so, give the dimensions of the solution matrix. (For
these operations on the HP-428, the first matrix would
be in the Y-register and the second one in X.)

1. B + E 2. D+ F 3. A+C 4. CE
5.AC 6.CA 7. B+ F 8. BF

Solutions: L No. See Rule 1.

2. No. See Rule 2.

3. Yes. The solution is a 3 x 4 matrix (see Rule 3).

4. Yes. The solution is a 3 x 2 matrix (see Rule 2).

5. No. See Rule 3.

6. Yes. The solution is a 3 x 4 matrix (see Rule 2).

7. Yes. The solution is a 2 x 3 matrix (see Rule 3).

8. No. See Rule 2.

YOUR RAW MATERIALS: Data And Variables 157


}

And there are two other types of common matrix multiplication, also:

The first is called the dot product of two matrices: A • 8. To do this,


you multiply the corresponding elements of two matrices together and
then sum up these products (so the result is a number, not a matrix).
Notice that the formula for a dot product means that you must have
two matrices with the exact same dimensions.

Try One: Find MAT • TAM

Solution: [RCL)mlJ [RCL) l1lID ~ HII Answer: 0. 875

The other type of matrix multiplication is for two- or three-column


vectors, which (as you'll recall from page 140), are matrices with only
one row. With two of these (same dimensions only), you can compute
their cross product, symbolized by X. The solution will be a new vector.

Example: For these vectors: A: [ 2 5 -3 ] and 8: [ 7 -4 l


find AX 8.

Solution: flIENTERffi ~mm 1EI10.-m1n1 @@IExlTJ


rn:m:3 . . [ALPHA)
[STO{ALPHA)
~Im HlII m.. ffi+/-](EXiffRCL)lm[ x~y]~
t!B!m

Find the answer via~ mil: [ -12 -21 -43 ]


Then [EXIT] to the Stack.

158 An Easy Cour11e In Using The HP-428 )


)
Notes (Yours)

That's about it for this chapter on data and variables. They are indeed
the raw materials used by your calculator to shape solutions for you.
The next step is to learn how to fashion your own tools from the
workshop's built-in tools.

But first, of course, you need to test yourself- to be sure that you don't
ever become exasperated, perspirated, and otherwise unduly vexed
with data and variables ....

YOUR RAW MATERIALS: Data And Variables 159


u
Variable Vexation

1. Store 4.56 in data register R, 8 . Then store 9.23 in the T-register.


Finally calculate 4.56 x 9.23 4·12 using the [ACL{8l function.

2. What's the difference between~ and~

3. Pressing •COMPLEX] causes different things to happen depend-


ing upon what the X- and Y-registers contain. What happens in
each of the following circumstances when you press~

a. Complex numbers in both X and Y.


()
b. Real numbers in both X and Y.
)

c. A real matrix in Y; a complex number in X. )


)
d. A real number in Y; a real matrix in X.

e. A 2 x 3 complex matrix in Y; a 2 x 3 real matrix in X.

f. 3 x 3 real matrices in both X and Y. )

g. A real 2 x 2 matrix in Y; a real 2 x 3 matrix in X.

u
160 An Easy Coune In Using The HP-428 )
4. Sometimes you can take the square root of a matrix and some-
times you can't. Why?

5. Create (and name) the 1 x 3 matrix, A: [ 3 6 -4 J .


Then redimension it to a 2 x 2 matrix:

[~ -~ l
Now find the inverse of this, then the determinant of the inverse.

6. Create and name two vectors, B: [ 2 5 ] and C: [-2 9 ] .


Then show that B X C ,;: C X B (X means the cross product).

7. During this chapter you created and stored the matrices, PIXY,
MAT, and TAM. Calculate the determinant of the solution matrix
to the following problem:

e [ PIXY (112{MAT)+ TAM}]

8. If you want to change between Rectangular and Polar formats,


what's the difference between using the~ Menu and the
•CONVERT) Menu items(~ and~)? When should you use
the~ Menu? When should you use the• CONVERT) Menu?

YOUR RAW MATERIALS: Data And Variables 161


)

Victory Versus Variable Vexation!

1. First GI:Jiill~. Then ®::::Iill!sroEJ e::.I.


Finally, m:::TIITJ9E]lBfillilil1). Answer: 43, 211.153

2. If you press [RCL) while in ALPHA mode, you'll be doing ARCL


(hence the notation~). Ifyou're not in ALPHA mode, [RCL) does
a normal RCL.

~ makes an ALPHA-character copy of whatever is cur-


rently stored in data register 04 (R 04 ) and appends those charac-
ters to whatever is already stored in the ALPHA-register. If R04
currently contains a real number, the numerals (characters) rep-
resenting that number will be appended to the ALPHA-register ()
in the same format as the display is currently using to format real
)
numbers.
)
lB9JQll), on the other hand, makes an actual copy of the contents )
of R04 (a number for a number or a string for a string) and stores
this copy in the X-register. Whether this new addition to the X-
register bumps the Stack up in a Stack Lift or merely overwrites
the contents of the X-register will depend on whether the previ-
ous operation left Stack Lift enabled or disabled.

162 An Easy Counte In Using The HP-428

)
3. a. Because the number in X is complex, pressing• COMPLEX] will
split this complex number into two real-number parts. The
first part (formerly the real part of the complex number) will
be stored in Y, the second (formerly the imaginary part of the
complex number) in X. The other complex number (that had
been in Y) is bumped up into the Z-register.

b. This time, pressing •COMPLEX] causes a new complex number


to be formed, the real part formed from the real value in Y, the
imaginary part formed from the real value in X.

c. This is the same situation as the first case. Because X contains


a complex number, your calculator doesn't care what's in Y. It
simply splits apart the complex number in X, sending the two
pieces into Y and X.

d. You'llgettheerrormessage,Invalid Type. Since you have


a real matrix in X, your calculator is expecting to find a real
matrix in Y, as well. Nothing else will do!

e. Again, just as in the previous case, because X contains a real


matrix, so must Y.

f. You'll make a 3 x 3 complex matrix.

g. You'll get the error message, Di Mensi on Error, because al-


though you have two real matrices, you cannot combine them
to form one complex matrix unless they have exactly the same
dimensions.

YOUR RAW MATERIALS: Data And Variables 163


)

4. You can always take the square root of a complex matrix without
worrying about whether any of your elements are negative. But
when working with a real matrix, you can take the square root
only when all of the elements are positive in sign. Otherwise,
you'll be trying to put complex elements into a real matrix.

5. KeyinandnameA: ~Cimmil@J._Cfil
. . @+!-)[EXIT)[STO) lliJm.

Redimension: ~ lmlEllOOilm . . SJI . . 0


.-0+1-)

Invert this: [EXIT)[RCL) . . (!)Ila (tml and -.·s to view):

[ 0.167
0.083
0.250
-0.125
l
Find the determinant of this: [EXIT] IHI Answer: -0. 042

6. First create and name the vectors (each is a 1 x 2 matrix):


o::@fgillJ Cim mII [I) . . (]][EXIT)~ rn::fil3 . . [ALPHA)
o::@fgill]m!DIEil@J+/-JlllDll®[EXIT](STO{ALPHAJri'Ii!~. .[ALPHA).

Now find BX C:~ . . [RCL] . . (!)~


Answer (use mII to view): [ 0.000 0.000 28.000 ]

)
c x B: [EXIT) [RCL) . . [RCL] . . (!) ~
Answer: [ 0.000 0.000 -28.000]
The answers are opposite in sign! )
)
164 An Easy Course In Using The HP-428
7. Go to the Matrix Main Menu. Then [RCL) mi.I [RCL) lml [IJE)[RCL)

get that, you'll need to press •TOPFCN) •Ell


1rn3 8[8] does everything except for the exponentiation (~). To
(recall page 103).

Finally, press IIll Answer: 12. 721 - i 18. 818

8. Complex values in your HP-42S are always kept in rectangular


form, regardless of what you see in your display. The ~
Menu changes only the way those values are displayed. RECT-
angular mode will display them as is. POLAR mode will display
those values in the corresponding t. format.

The• CONVERT] Menu, on the other hand, performs a calculation


(actual math in the Stack) on the (always-rectangular) values it
finds in x and y. mm, for example, assumes that the numbers
it finds represent the results of some POLar calculation and that
now you want to convert these to RECtangular values. Press [RCL]
~m!ll. x: 5.000 i4.000 Nowpress.CONVERT)H!Bto
convert to rectangular.... Why the change? Aren't you already in
rectangular format? ...Well, the display is, but when you press
HIN, your HP-42S reinterprets the values in the X-register to be
in polar format-no matter whether they actually are or not! The
5. 000 and 4. 000 are then taken to mean 5. 000 .i4. 000 -
regardless whether they appear as 5. 000 i 4. 000 to you - and
an actual calculation is done, putting new values in the Stack.

So, since the ~Menu changes only the display's represen-


tation of the Stack values, always use it rather than the• CONVERT)
Menu unless you really do want to change the values in the Stack.

YOUR RAW MATERIALS: Data And Variables 165


I
)
I

BUILDING YOUR OWN TOOLS: J

Programming

J
Programs: A Different Kind Of Tuol

Up to this point, you've worked with various hand tools and data types
- the raw materials that you manipulate with your tools.

What about programs? Are they a special type of tool or a type of data,
or what?

At one level, programs do look a little bit like data. After all, they're
stored in memory and are assigned names. But that's about as far as
the resemblance goes. Programs are really tools: they do things to
data you've entered - just like the built-in tools you've already seen.

You can think of programs as little robots that you build to take care
of the more repetitive tasks in your workshop. So this chapter is
dedicated to the building of little HP-42S "robots" - tools that know
how to follow your instructions.

\ \

r
A Little Memory Reminder

Before you get started on building programs, you'd better review how
programs affect the amount of memory available in your machine.

As you recall (page 43), you can review the contents of your various
storage areas by pressing •CATALOG] and selecting one of the menu
choices to see the names of the objects stored in each area. So do it:

•cATALOGJm shows ALPHA variables YEP and HI and real variables


FRED and EE (provided, of course, that you've been following this book
in sequence and haven't done a bunch of freelancing in the meantime!).
0
Then [EXIT]l!B shows that PLEX and LORI are your current complex 0
variables. And [EXIT] lml shows C, B, A, TAM, MAT, PIXY, MATT, and
0
REGS as your current matrix variables (remember that REGS is
()
always there - it's built-in).
)
)
So how much memory do you have left? Press [EXIT] and choose Glfil 0
from the main •CATALOG] Menu and hold down the menu key to view: )
)
Available MeMory:
6444 Bytes )

You have 6444 bytes of memory with which to create your programs (of
course, if you've stored additional variables, you'll have less than 6444.

But how much memory is a byte? To get some feel for this, clear a few 0
variables to see how many bytes you "free up." 0
168 An Easy Course In Using The HP-428 )

( )
Do This: Clear matrix variables A, Band C, and then check to see
how many Bytes this clears.

Solution: Then press~ (remem-


[EXIT) to the Stack.
ber that pressing a Menu heading twice is useful if you
need to use a Menu several times in a row) and l!D . .
ll!D . . ll!D . . [EXIT) to clear the matrix variables.
Now check available memory with .CATALOG) rn
Answer: 6570 Bytes

Those three 2 x 2 matrix variables had been using a total


of 126 Bytes - an average of 42 Bytes each:

Another: Now clear the complex variable PLEX, and find out how
much memory you save.

Solution: [EXIT) Sf.IJ@ll!D m:!il .CATALOG) mm:


Answer: 6597 Bytes

This complex variable - including its name- appears to


be worth 27 Bytes of memory.

One More: Clear the real variable, FRED, to find out how bigit was.

Solution: [EXIT) 99J@ ll!D (!)~.CATALOG) mm:


Answer: 6616 Bytes

This real variable uses 19 Bytes, including its name.

BU/WING YOUR OWN TOOLS: Programming 169


v
•PRGM)And Program Mode

All right, those are variables. Now how fast do programs "eat up"
memory? To find out, you'll need to begin working in Program Mode.

The first thing to notice about the~ key (sitting there on the
bottom row of your calculator) is that it is your access to a "mode," - not
a menu like most of the other "shifted" functions on your keyboard.
And~ activates such an important mode that it gets its own key
instead of being relegated to the 9MOOES)Menu.

How does it work?

When you're in "normal" mode (often called Run Mode) and you use a
tool or store a variable, you're actually doing something with your data
at that moment - directly "crunching" as you press the keys. Data is
moved around in the stack, values are calculated or stored, etc.
)
But in Program Mode, most of your actions are treated as a "set of )
recorded instructions" - instructions for doing something in the future .
And when you've written these instructions and given them a name,
you've built a program.

Of course, when you're ready to run your program, you must then get
out of Program Mode (back into Run Mode -yep, that's why it's named
that).

To record instructions, you go to Program Mode; to execute those


recorded instructions, you go to Run Mode.
)
)
170 An Easy Course In Using The HP-428 )
The Program Display Revisited

Back on page 24, you briefly glanced at a Program Display-just to see


what it looked like. Now it's time to study it for real.. .. Press [EXIT) until
you see the Stack Display, then press ~- You should see this:

00•< 0-Byte PrgM }


01 END.
I

You're looking at two program lines stored in your calculator (and


these are the only two program lines in storage right now).

Notice these important features about this display:

• The first two digits of each line are line numbers - 00 and 01 here.

• The first line of every program is numbered 00, and it tells you about
the size of the program. Here, because there isn't any program yet,
it says just that: you have a 0-Byte PrograM.

• There's a small arrow c•) following the line number. This is the
program pointer, which is what the machine uses to "keep its place"
in program memory. Since you may occasionally be unsure of the
position of the program pointer, this little arrow in the Program
Display is your reminder.

• Line 01 contains a special instruction - the Permanent. END, This


"END-with-the-periods" says that you're looking at the very end of
storage space allotted to programs. This is where you'll start when
you begin to key in and build a new program.

BUILDING YOUR OWN TOOLS: Programming 171


OK- now how fast do the bytes add up when you record some program
lines? Try some more memory experiments ....

Try This: Find out how many bytes a digit takes up when you key
it in as an instruction in program memory.

Solution: Press any number key, say, (]].

~: Your program - which was previously 0 Bytes


- is now 2 Bytes

But Now: Add another digit, say, 0:

Result: Now the total for two digits is 3 Bytes .


0
0
)
Hmm ... does the 8 really take up less space than the 5
or is something else going on here? )
{)
Answer: It's the ol' "Hidden Byte" trick. ()

Actually, each digit only uses one Byte of memory. The


third byte never shows up as an instruction because its )I
information pertains to the instruction as a whole: This 0
program line is an instruction that tells the machine to )
"key into itself' (into the X-register) the number 58 (an )
exact recording of what would have happened immedi-
ately if you had been in Run Mode, right)? u
0
)

172 An Easy Course In Using The HP-428


The 'No-Frills, Straight-Arrow'' Program

So, how do you write a program? Well, basically, it boils down to


imagining the keystrokes you'd have to perform manually to solve a
certain kind of problem.

Imagine, for example, that you've just finished a physics experiment


in which you've compiled a list of fifty temperatures as resulting data.
But your lab was ill-equipped - you had only Fahrenheit thermo-
meters - so now you need to convert these temperatures to more ac-
ceptable units - degrees Celsius (°C).

The formula to do this conversion is: °C = (°F - ~ 2) x 5

Try This: Find the keystrokes you need to convert 97°F to °C.

Solution: Press (EXIT), then ®IIENTER]@ITE)(I0(ffi


Answer: 36. 111

And Another: Now do the keystrokes for the conversion of 85°F.

Solution: (!ill ENTER~ Answer: 29. 444

Well, running through these keystrokes fifty times (once for every tem-
perature you took in your experiment) is going to be no fun at all. You'll
be repeating the same eight final keystrokes ((ENTER]@ITE)(ill9(ffi)
over and over - once for each temperature datum. A big, big drag.

So what do you do about it? ...

BUILDING YOUR OWN TOOLS: Programming 173


You write a program that can solve this equation:

(INPUT - 32) x 5 _ OUTPUT


9
Good news ...

You have already written that program!

Did you know you were already programming (at least, on paper)? The
keystroke sequence you developed as a solution to this equation is
indeed a program.

Right now, the program is not stored in your calculator, but in your
mind (and on the previous page). When you worked through the
sequence of keystrokes to convert a Fahrenheit temperature to Cel-
sius, you actually visualized ("called up") a logical sequence of instruc-
tions in your mind and (possibly with the help of your fingers) worked
through these, step-by-step, starting with [ENTa:I] and ending with EJ. )
)
All you need to do now is to turn this set of mental instructions into
ones that your HP-428 can understand.
How To Start A Program

At the beginning of this chapter, you observed that programs and vari-
ables are somewhat alike because they both have names. That's true,
but the name of a program is more often called a label.

The very first thing any program needs is a label.

To label a program you use a function in the •PGM.FCN] Menu: 1!11

Try This: Begin building a program to convert °F to °C, by labeling


it "FIRST".

Solution: Make sure you're in Program Mode. Then use the ~key
to clear that experimental line 01 58_, so that you see
the Permanent • END. on line 01 .

Now press .PGM.FCN]l!D and key in FIRST using the al-


phabetic keys (and pressing (ALPHA] as usual, when
you're finished). You should now see:

00 ( 9-Byte PrgM }
01KBL 11 FIRST 11

What happened to the. END. in this example? Press(!) and find out.

Aha! It's now down on line 02. You have inserted the label between the
00 line and the • END. Press ~ to go back to line 01.

BUILDING YOUR OWN TOOLS: Programming 175


Notice that the~ and(!) keys have a special function when you're in
Program Mode. They move the program pointer backwards and
forwards through the program lines without changing anything writ-
ten on the lines. The~ key does a BackSTep (BST for short)- moving
the pointer backward, to the previous line. The(!) key- does a Single
STep (or SST) - moving the pointer forward, to the next line.

But, whenever you use a Menu, the~ and(!) keys will revert to their
traditional function of cycling you through the menu pages - even in
Program Mode. Therefore, to BST and SST when a menu is showing
in the display, you'll need to use the ~ and ~ keys ....

Try This: Choose the •PGM.FCN] menu and then step backward to
line 00 of your program. Now step forward to line 02.

Solution: •PGM.FCN]~~~

)
Get the idea? Press [EXIT~
Challenge: Now finish keying in this program, 11 FIRST 11 that con-
verts a Fahrenheit temperature to Celsius.

Solution: Use the~ and(!) keys until the program pointer(.) is


on line 01. Now press the keystroke sequence you devel-
oped earlier (on page 173):

~ You should now see this:

II.___~~.~ _II
Notice how each line you key in will be inserted following the line you're
viewing. And the pointer then moves to the new line.

OK- that's it, then. You've got this program all ready to go ... right?

Mmmm ... not quite....

BUILDING YOUR OWN TOOLS: Programming 177


How To END A Program

How do you tell the calculator that you're finished entering a program?
You tell it to END.

END is an instruction like any other. It tells your machine that this is
the last instruction in the program. There are three ways to put this
instruction at the end of your program:

• You can select END from the •CATALOG] (El Menu: •CATALOG] (El
~rnl!I and then [EXIT].

• Or, you can directly command your calculator to eXEOute an END,


by pressing [XEO{ALPHA] rll1m . . rnTIE ICll rll1!!13 . . [ALPHA).

The [xEa) key will become one of your favorite programming keys as
you get to know it better. It allows you "spell out" any function from
any menu - as an alternative to pressing a key or choosing a menu )
item.*

• Or, you could press~- This means "Go TO the END with
the two c:J's - the Permanent , END. - and prepare for a new
program." In doing this, the calculatorautomatically places an END
instruction as the last line of your program (if there's not one there
already).

*Of course, this means you need to know how to spell the function correctly. You can find th e correct
spellings of all the functions in your Owner's Manual's Operation Index, starting on page 310.

178 An Easy Course In Using The HP-428


.l

So choose one of those three methods and do it now.. .. When you finish,
notice that you're still in Program Mode cEND does not change that), but
you're now positioned to line 00 of a brand-new program.

Try This: Confirm that you've properly entered your END by look-
ing at the program FIRST again.

Solution: [EXIT) from Program Mode, then press •GTO) [illil m:PRGM),
which should bring you to the Program Display with
yourprogrampointeron: 01KBL 11 FIRST1'. Now, using
the~ key, BST around to line 09, where you should see
an END.... ... sure enough!

Question: What's the difference between END and • END. ?

Answer: When you see • END. in your display, you know the pro-
gram pointer is positioned to the very end of program
memory (and the last program in memory- the one just
"above" this. END. -is always the oneyoukeyedinmost
recently). There is only one. END • .

By contrast, there can be many END 'sin program memory.


Each END acts as a partition, separating one program
from the next program. If the program pointer is posi-
tioned within one program and you want to move it to
another, you need to use •GTO) to "call up" a label in the
other program. Using BSTand SST will never moue you
from one program to another.

BUILDING YOUR OWN TOOLS: Programming 179


Using Your First Program

OK, here's the moment you've been waiting for ....

Coup d'Grace: Using the FIRST program, convert the following


Fahrenheit temperatures to Celsius (and change
your display setting to FIX 01, to match the preci-
sion of these data): 454, 127, 98.6, 212, 72, and -40.

Denouement: [EXIT] to Run Mode, if you haven't already. Then


~ 11111:1 @ID sets the display. And:

(TI[@[XEO] l1IiW (Answer: 234.4) CillTI)[RIS)


(52.8) CillEIT)[R/S) (37.0) ITiill)[RIS) (100.0)
(Iill[RJS) (22. 2) (ilil+/-)[RIS) (-40. 0)

Notice that when you pressed [XEO], the label "FIRST" appeared as a
selection on an XEQ Menu. Your machine knows that when you want
to execute (run) something, you're going to be referring to a label.

But why did you use the [XEO] key for only the first datum, but then just
the [RIS) (Run) key after that? Because after the first time through your
program, you knew that your program pointer is positioned within
)
that program. So when the machine stopped after encountering the
END instruction, a mere [RIS]was all that was necessary to get it to cycle
around and start at the top again. But on the first time through, you
didn't know where the pointer is; it could have been in another )
program entirely - so you used [xEa) to jump to the correct label.

180 An Easy Course ln Using The HP-428

( )
Editing A Program

Suppose now that you want to include the FIX 01 procedure in the
program Fl RST -so that the program would automatically change the
display precision. How could you go back and add in this feature?

Like This: Re-enter mPRGMJ Mode by pressing ~- This will


always take you to the the program line where the
program pointer is currently positioned. Right now, it's
at00•< 20-Byte Pr9M }.

This makes sense: A program's instructions "wrap


around in a circle," so line 00 is the "next line" after line
09 -the END instruction that halted the program. Again,
this is why [R/S) works for repeated execution.

Now you're going to insert a (recorded) FIX 01 instruc-


tion on the program line immediately following line 01.
To do this, you press [!)to get to line 01 and then simply
use the same keystrokes as if you were doing it immedi-
ately from the Stack Display: ~ EBI @TI).

Notice that when you're inserting new program lines,


each new line will be inserted immediately following the
current (i.e. the "pointer") line.

BUILDING YOUR OWN TOOLS: Programming 181


Get the idea? Editing is really no big deal. Try ....

One More: Replace the 5 on line 06 with a 7.

Solution: ~~0.

Aft.er using the(!) key to position the program pointer to


line 06, you then delete the line with the (B key, and
finally insert a new line (06 ).

When deleting a line, you simply place the program


pointer on that line and press ~. This does the deletion
and moves the pointer back to the previous line, so that
you're all ready to insert a new line following - exactly
replacing the deleted line!

(Now, before you go any farther, you should re-edit your )


Fl RST program back to its correct formula: Replace the )
7 on line 06 with a 5, by pressing (Bfil)

I
/

:'/ ! '
I

I l

/ / I/
I I .

.
Moving Around In Your Program

Hopefully, you already have a good working understanding about how


to move around in your program memory:

• To move forward or backward one step in program memory - when


there is no menu showing-use the(!)and~keys (page 175); when
there is a menu showing, use~ and~ (page 176).

• To move to the permanent • END. of program memory, you press


am=or:n. This is what to do whenever you want to start keying
in a new program.

• You can also go immediately and directly to any line in the current
program without using SST or BST. For example, to move the
pointer to line 07 in your FIRST program, you could ...

Do This: •GTO)~. This will work in either Run Mode or


Program Mode. In Program Mode, the SGf?SE]sequence
(as in llfilfil::::E) and now~) signifies a
command to be done immediately-not to be recorded for
future execution.

Voila! The program pointer is now pointing to line 07.


This works only for the specified line 07 in the current
program. Ifthere were another program, (SECOND for
example) your machine wouldn't "see" its line 07 at all
- because there is an END partition in between.

BlHLDING YOUR OWN TOOLS: Programming 183


• And you can use the do-it-now properties of the~ sequence
to move to a label in your current program -as well as a line number.

Like This: Without using SST or BST - but while in Program Mode
- go to (i.e. move the pointer to) the label, 11 FIRST 11 •

Answer: In Program Mode, press llfilQE)[ALPHA] FIRST [ALPHA].

Nothing to it!

But Notice: Press~ a couple of times, then [EXIT] out to Run Mode.
Now move the pointer back to label "FIRST" again:

Since you're in Run Mode, there's no need to use the 0


key to request immediate execution; you always get
()
immediate results in Run Mode - no recording of in-
struction done here: Just press •Gro) i:mm. )
)
When in Program Mode and jumping to a label with )
ll§IQO, you'll need to spell out the label; but in Run
)
Mode, you get to use the menu to select it.

)
)

184 An Easy Course In Using The HP-428

( )
What Do You Know?

Here's a quick summary of what you know about programming and


Program Mode up to this point:

• You know how to find the permanent • END. and prepare for a new
program;

• You know how to begin and name programs with labels;

• You know three ways to put an END to a program.

• You know how to write a simple, straight-forward program that


solves an equation with one input;

• You know how to change a program by editing it;

• You know how to move around within a program, either step by step,
or more rapidly;

• You know how to "run" or "execute" a program using the [RIS] and
[xEa] keys respectively;

• You know how to find out how much memory you have left.

Now, what if you want to write a more complicated (and smarter)


program?
"Read on, Macduffi"

BUILDING YOUR OWN TOOLS: Programming 185


Variables And How To Use Them

Suppose you want to write a program to calculate the volume and total
surface area of a cylinder, given the radius (r) and height (h). The
relevant equations are:

Volume = rtr2h Area =2rtr(r + h)


·bJ r

There'll be two inputs (radius and height) and two outputs (volume and
area) in this problem, right? You'll have to be careful to avoid mixing
them up. How are you going to do this?

First: Write out in words exactly what you want your program
to do.

''Hmmm: I want the calculator to tell me when to input the radius


and the height of the cylinder, making sure that I don't
get them confused.

Then it should calculate the volume and surface area.

Then I want it to show me these answers, making it clear


which answer is which."

All right, that's not asking too much of your HP-428-especially if you
take these "wants" one at a time, in the order you listed them here.
That's the essence of programming - breaking a large problem down
into an orderly series of smaller, simpler problems. )
)
186 An Easy Counte In Using The HP-428 )
)
But before you start on these problems, you need to prepare a space and
a name for the new program ....

That Is: Begin a new program in program memory and name it with
the label 11 CYL 11 •

Like So: •GTO EE)m:PRGMJ takes you to the end of program memory
and puts you into program mode.

Now begin the new program with a label to name it: Press
•PGM.FCN.PGM.FCN) (twice because you'll use this menu
often while programming), andl!]]l llll!Il . . l!EiB . .
~--(ALPHA).

BUILDING YOUR OWN TOOLS: Programming 187


Using The mil Function

In the •PGM.FCN) Menu, there's a special set of instructions designed to


help you manage inputs and outputs more easily: um:!H, l1lI3ll ,rnmI!,
~,lml]J, and rnml,.

Now, the first thing you wanted the calculator to do is to prompt you
for the "inputs" -making it clear as to which one it wants, so that you
don't mix them up.

Well, you can actually tell it when to expect a particular input by using
the llm!IJfunction.

Try It: Tell your calculator to stop, prompt for, and store two
inputs. The first one should be stored in a real variable, )
R (for radius) and the second one in a real variable, H (for
height).

Solution: Press Imm (ALPHA) !im!l1lm:ill (ALPHA) and llm!ii (ALPHA)mTII


IOI (ALPHA).
)

Seems pretty simple doesn't it? )


)

)
)
)
188 An Easy Course In Using The HP-42S )

)
Well, it is simple. The INPUT instruction does a lot automatically for
you. Whenever a running program encounters an INPUT instruction,
it does several things. Take a look:

• First, it halts execution and looks in variable memory for the


variable named in the INPUT instruction- and ifit doesn't find such
a variable, then it creates one with that name.

• Next, it prompts you for the value you want to store into that
variable - by replacing your normal view of the X-register with a
prompt, showing the name ofthe variable and the variable's current
value (which will be zero if it has just been created).

• Now it's your tum: You key in the new value to store in the variable
and then press the[RIS)(RUN)keyto continue (of course, since you're
being shown the current value in the prompt, if you decide you don't
want to change that, all you do is press [RIS), without keying in any
value).

All this-an automatic stop, variable search-or-creation, recall, prompt,


and storage -with one little INPUT command!

And now you've handled all your input problems for your CYL program
with just two uses of this command- one for each input. So much for
the first of your three problems ....
)

BUILDING YOUR OWN TOOLS: Programming 189


Next up: Do the actual math.

Problem: Write a program that uses the existing values in variables


Rand H to calculate the volume and surface area of a cyl-
inder according to the formulas given on page 186.

Like This: As with most programming of actual calculations, just


use the sequence of keystrokes you'd need to solve this
problem manually:

S!!)(RCLlALPHA) mi!W llill (ALPHA)


.TOP.FCN)~~[RClJALP8A) lifilll IEJI (ALPHA)~

That's the volume. Then

~(RCLlALPHA) mi!W llill (ALPHA)(±)


•LAST x]~S!!J~0~ calculates the surface area.

So the volume will be left in the Y-register and the


surface area will be in the X-register when the program
CYL is run.

)
190 An Easy Course In Using The HP-428
Does the program work - at least the portion you've done so far?

Test It: Use CYL to find the volume and surface area of a
cylinder with a radius of 8 cm and a height of 18 cm.

Solution: First [EXIT) from Program Mode. Then press [XEO) l6i)
and see the R?0. 0 prompt on the lower display line
(where the X-register is usually shown). You're being
shown the current value of Rand then asked to INPUT
m
its new value. So press and then [RIS) to continue.

Now respond to the H?0. 0 INPUT prompt similarly, by


pressing~- ... Lo and behold - the answers!

x: 1, 306. 9 (area, cm2 ) and y: 3, 619.1 (volume, cm3 )

One More: Find the volume and area of cylinder with a radius of 4
cm and a height of 9 cm.

Solution: Press [RIS)(ilRJS]ffiRIS].

Since you just finished using the program CYL once, it's
the current program and you can just press [RIS) to start
it running again. Notice the R? and H? prompts: They
now show the values from the previous example.

Answers: 326. 7 (cm2 ) and 452. 4 (cm3 )

BUILDING YOUR OWN TOOLS: Programming 191


Getting Your Program To Talk Back

Well, the program CYL is fine and dandy as long as you remember
which answer is which. But suppose you're not the only one to use your
program. Sure -you understand it because you did the programming,
but your friend might easily get confused.

So how can you make your calculator give more helpful instructions
and messages? By using Imm, CPillll, and m!ID.

Challenge: Modify the program CYL so that the volume answer


is clearly labeled as such.

Solution: Enter Program Mode with~· Then ~


(9JENTER), to get to line 09, which is the last calculation
for the volume.

Now add a step: ~VOLUME [ALPHA) stores the


resulting number into the variable, VOLUME.

Now.GTOEDJ1lENTER), to get to line 19, which is the )


last step, and add one more step for clearer output: )
•PGM.FCN] Imm [ALPHA) VOLUME [ALPHA) displays the
value of the variable VOLUME, along with its name.

Test It: [EXIT) Program Mode and press [XEO) fill (R?S[R2S). Aha! )
Now the volume is labeled-and so you also know that
the other entry (in the X-register) must be the area!

192 An Easy Course In Using The HP-428


J

So, you can see how the l!ll!ll function is used: to display the name of
a variable alongside its value. This is very useful in labelling the
results of calculations at the end of the program.

But how can you have your program display other types of messages,
that can help you (or your friend) figure out what to do?

That's where !1111m] and m!ID come in .... Both !1111m] and m!ID can cause
the contents of the ALPHA-register to be displayed - and the program
to stop running.*

Of course, this means you need to have your message already stored in
the ALPHA-register prior to using AVIEW or PROMpt. Thus, you need
to do two things for each message you want your program to display:

• You must store the message in the ALPHA-register by entering


an ALPHA string.

• You must use AVIEW or PROMpt to then display the contents of the
ALPHA-register.

With that understood, you're ready to make your program sit up and
speak ...

) *The PROMpt function always stops the program, whereas this is optional with AVIEW. You'll
learn how to exercise your options a bit later in the Course.
)

BUILDING YOUR OWN TOOLS: Programming 193


Try This: Modify the program CYL to deliver the messages, INPUT
RAD I US and INPUT HEIGHT, thus telling the user more
explicitly to key in the radius and height.

Solution: The first step is to create the message in the ALPHA-


register: Enter~ Mode,(!) to line 01 and enter the
ALPHA string, INPUT RADIUS, as follows:

~INPUT RADIUS{ALPHA]

Then select •PGM.FCN(!)Wm to instruct your calculator


to display the contents of the ALPHA-register.

But wait - both INPUT and PROMpt will stop the pro-
gram from running - you don't want it to stop twice for
each input. Hmmm ...you need to delete one of these two
statements. But which one?

Well, you definitely want to see the message you've just


created, so you can't delete the PROMpt. But you also
need to create and/or store into the variable, R, which
the INPUT instruction had been doing; you don't need
the INPUT's prompt anymore, but you still need to store
your data ....

Aha! Just replace the INPUT 11 R11 with STO 11 R11 !

Move to 04• INPUT 11 R11 , press(Band[STo]llill to insert


the new line.
)

194 An Easy Course In Using The HP-428 )


J
Now you need to do the same three changes to the other
input variable (H).

So ~ down to: 05• INPUT 11 H11 and

(B
~INPUT HEIGHT (ALPHA]
.PGM.FCN)~m!JD
(STO]lllll

Finally, (EXIT) Program Mode and test your creation by


[XEO]Di!I using a radius of 5 and a height of 8.

~:
VOLUME=628.3
x: 408.4

And though you don't get to see what's currently stored


in the variables, the prompts that tell the user to INPUT
VOLUME and INPUT HEIGHT are much more explicit this
way, aren't they?
PROMPTing For ALPHA Data: 1im31 and li1TID
The program CYL provides a good illustration of how the INPUT or
PROMPT instructions can be used to enter numerical data. But how
do you enter ALPHA data into a program? Can you use INPUT also?

Generally, INPUT works the same no matter which data type you're
using-but it always assumes that your response will be in the X-register
when you press (R/S}to continue the program. That's not true when you
key in ALPHA data to the ALPHA-register, is it? And besides, you need
to have access to the ALPHA menu, too; using INPUT doesn't automati-
cally give you this access.

Sure, even with all these problems, you could still use INPUT, but this
would force you to do (or program) a lot of extra steps - to get to the )
ALPHA register, key in the data, then store this data into the X-register
and return to the Stack. What a pain.

In fact, no single command does a very convenient job of prompting for


ALPHA data; you need to use a combination of several. But no matter
how you do it, the instructions ALPHA ON (AON) and ALPHA OFF
(AOFF) are very handy, for they cause the ALPHA Menu to be turned
on and off, respectively.
)

That is, if you want to stop a program to enter some ALPHA data, you
should include an AON instruction immediately before a PROMPT
statement in your program (and an AOFF immediately after). That
way, when the program stops and prompts you for input, the ALPHA
Menu is already showing and you can immediately input characters
)
rather than numbers. Walk through an example .. ..

196 An Easy Course 1n Using The HP-428


Walk: Write a short program, called "NAME" , that prompts you for
your first name and then displays a personalized message:
HI, (your first name).

Steps: Keystrokes Display

~ 00 { 0-Byte PrgM }
.PGM.FCN]l!a NAME{ALPHAJ 01 LBL "NAME"
~YOUR1STNAME~ALPHA] 02 "YOUR 1ST NAME?"
• CATALOG) (Elffj Gilli 03 AON
• PGM.FCN J(!) rn!IIII 04 PROMPT
.ALPHAJ[STOfOF)[EXITJ 05 ASTO 04
• CATALOG) (Elffj rl!Tiii 06 AOFF
~HI, (ALPHA] 07 "HI' II

~~(EXIT] 08 ARCL 04
.PGM.FCN]Ciml) 09 AVIEW
ff] 10 •END.

Press (EXIT] and then [XEQ] cmm. Input your first name and
press [RIS]. ... Not bad, eh?

Notice that if your name has more the six letters, you'll only
see the first six letters displayed. This should remind you that
you can have a maximum of six ALPHA characters when you
store an ALPHA string as a datum in a variable or register.

BUILDING YOUR OWN TOOLS: Programming 197


)

Look at how the program in this last example actually works:

Line 02 prompts for the input and the AON in line 03 displays the
ALPHA Menu (and the message, of course, since it's in the ALPHA-
register by then). When the PROMPT in line 04 stops the program, you
can key in your name, then press [R/S)to re-start the program. Notice
that you're inputting directly into the ALPHA-register, so that the
program must use ASTOre to store the first six letters of your name into
a register (register 04, in this case).

The ALP HA-register is turned off (you must be tidy!) using AOFF in line
07. Then, after putting 11 HI, 11 into the ALPHA-register, your name is
added onto the end of the 11 HI , 11 using ARCL. Remember from page
124 that ARCL adds to the ALPHA-register and doesn't simply replace
the contents. Finally, the results are displayed with AV I EW .

In sum: 0
)
• To prompt for numerical data entry, use the INPUT statement,
pressing the [RIS) when you're through keying in each datum.

• To prompt for ALPHA data entry, use the AON, PROMPT, AOFF
sequence - as you just saw in the program, NAME.
)

INPUT and PROM PT are very useful tools, especially for short, straight-
forward programs. However, the folks at HP have taken great pains
to give you another, even slicker, way to key values into a program (and
they would be greatly hurt if you didn't come to know and love it) ....

198 An Easy Course In Using The HP-428


Variable Menus

) Variable menus can be a lot of fun. Certainly they make it very easy
for a program user to input variables - and in any order!

When a program uses variable menus, a menu is displayed and the


program stops, allowing you to store, recall, and view any of the
variables you are using (the Power Tools 8SOLVEA] and~' which
you'll learn about in more detail later, both make extensive use of
variable menus).

The two special functions used to make variable menus can both be
found in the •PGM.FCN~ Menu: W'll!il and l'mil).

The VARiable Menu (l'llli!D) function tells your calculator to build the
special menu for a particular program - a menu that may contain any
or all of the variables used by that program.

The Menu VARiable (ln'.rnil) function tells the VARM function which
variables should be put on the Menu it is creating. You use the MVAR
function only for those variables you want to appear on the menu.

Look at the next page, which compares the program CYL with a new
program, NCYL, that does the same thing, but uses variable menus
instead of input prompts.

BUILDING YOUR OWN TOOLS: Programming 199


Program listing for CYL Program listing for NCYL

00 { 79-Byte PrgM } .A. 00 { 76-Byte PrgM }


01 LBL CYL 11 II 01 LBL NCYL 11 11
---------------------------------
02 INPUT RADIUS
11 02 MVAR R
11 11 11

03 PROMPT 03 MVAR H II II

04 STO R II II 04 VARMENU NCYL II II

05 INPUT HEIGHT"
II B 05 INPUT VARIABLES
II 11

06 PROMPT 06 PROMPT
07 STO "H" 07 EXITALL
-------------------------------
08 PI 08 PI
--
09 RCL R 11 11 09 RCL R 11 11

10 Xt2 10 Xt2
11 x 11 x
12 RCL H 11 11 12 RCL H 11 11

13 x 13 x
14 STO VOLUME
11 1114 STO VOLUME 11 11 )
15 LASTX 15 LASTX ()
16 RCL R 11 11 c 16 RCL R 11 11
)
17 + 17 +
18 LASTX 18 LASTX
19 x 19 x )

20 PI 20 PI )
21 x 21 x
22 2 22 2
23 x 23 x
24-VIEW-"vOLUME11 ____ D___ 24VIEW 11VOLUMf 1_ _ ___ )

-------------------------- -- -----
~-~~----------~---~~~~-----------
)
200 An Easy Course In Using The HP-428 (

I
Study the preceding page carefully - and notice these things:

• Each program has five functional sections, A - E, which make up


the logical progression of many simple programs in your HP-42S:

Section A includes the program's beginning and label;

Section B has all the instructions necessary to input the radius


and the height;

Section Chas all the instructions for calculating the volume


and surface area;

Section D gives the instructions for output (just the I/ I EW com-


mand here);

Section E ends the program.

• The programs differ only in Section B, in the way in which the


values for the radius and the height are input into the calculator.

• NCYL stops just once for data input (line 06), whereas CYL stops
twice, at line 03 and line 06.

• There are some instructions in NCYL that you've not yet learned
about!

BUILDING YOUR OWN TOOLS: Programming 201


Do This: Key in sections A and B of NCYL (page 200).

Here's How: llGTOEEJSPRGMJ prepares a new program space.

Then: •PGM.FCN.PGM.FCN)i ! a NCYL [ALPHA]


~ mrnil. .GJ!1i'Iilllilll'1:l:BIICiml
~INPUT VARIABLES (ALPHA](!l!)mTIIJ
.CATALOG)IEl~lmlJ
[EXIT]

Here's how these instructions will work:

First of all, the two MVAR instructions must come right after the label,
11 NCYL 11 • Why? Because the VARM 11 NCYL 11 instruction tells the
machine to "find the MVAR instructions immediately following the label
11 NCYL 11 and build a variable menu with the variables named in those

MVAR instructions." In this case, it will find two MVAR instructions (for
R and H) and therefore build a menu with just those two choices.

Then, of course, the next two lines provide a PROMpting message to


help you know what to do. You've seen that kind of thing before, right?

As for line 07 EXI TALL, its purpose (as its name implies) to EXIT ALL
Menus, so that both lines of the Stack Display are visible once again.
This is important in this NCYL program because both display lines are
needed at the end to show the two answers: the volume is displayed
in a friendly message covering the Y-register, and the surface area is
displayed in the X-register.
)
202 An Easy Course In Using The HP-428
Next Job: Finish keyingin the rest of NCYL, then use it to calculate
the volume and surface area of a cylinder with a radius
of 15 cm and a height of21 cm.

Solution: ~ --~ . . @STollJ•IMll lllASfXIRCLJ


--~PGM.FCNll91!,il1.lil!!I

Then [EXIT] Program Mode and press [XEa)l:m)

Now key in the data ... GIT). . @ID . . . . .


and let 'er rip: IRIS~

Answers: 14, 844. 0 cm3 and 3, 392. 9 cm2

Now This: Verifythatthecurrentradiusis 15 cm. Then change the


height to 43 cm and recalculate the area and volume.

Like So: Press [RIS] to run the program again, thus regenerating
the variable menu. Then• and hold down llrtl to view
its current value. Result: R= 15. 0

Now change a value and recalculate: GTIJ mill [RIS)


Answers: 30, 394. 9 cm3 and 5, 466. 4 cm2

Some kinda wonderful, eh? By using MVAR and VARM, you can both
store and view variable values - in any order you want!

BUILDING YOUR OWN TOOLS: Programming 203


Creating Two-Line Messages

Now that you know all the different ways of getting numbers into a
program, how about trying to improve what the answers look like as
they come out?

The output of NCYL now looks like this:

VOLUME=30,394.9
x: 5,466.4

That is, only one of the two answers is labeled. Now, this probably
doesn't cause too much confusion the way it is, but wouldn't it be nice
if you could label both outputs - putting each output on its own line?

Of course it would. But to accomplish this task you'll need to use two
important new characters that live in and around the ALPHA Menu.

Recall from page 35 that the ALPHA-register can hold up to 44


characters. That means you could theoretically create a message up 0
to 44 characters long. And you learned on pages 193-194 that you can 0
also create these messages with "recorded" instructions - program
lines, right?
u
But what you didn't know is that you can'tput more than 15 characters
on one program line. The length of a program line is just more limited
than is the ALPHA-register; that's the way it is.

So how are you going to create a message longer than 15 characters?

)
204 An Easy Course In Using The HP-428
.J

You're going to combine more than one program line into one single
ALPHA message using the APPEND character, I-.

Example: Create a new program, labelled 11 HOWDY 11 , that displays


the message, HOW' RE Y'ALL DOIN'? (which is a total
of 19 characters).

Solution: ll§!QEB~ takes you to new program space.

•PGM.FCN]~ HOWDY (ALPHA] creates the name.

~ HOW'RE Y'ALL (ALPHA] puts the first part of the


message into the ALPHA-register.

Then~ begins the next instruction with a


I- character, thus telling the machine to append what
folllows to the current contents of the ALPHA-register.
So you complete that instruction by typing in the rest of
the message: DOIN'? (ALPHA].

Finally, key in an instruction to display the entire mes-


sage:~.

Now (EXIT] and try it out with (xEo]llTIIII!J.... Voila!

It is important to remember spaces. The APPEND instruction doesn't


automatically put in spaces for you!

BUILDING YOUR OWN TOOLS: Programming 205


If you understand this, how about trying for a message that uses two
lines when it is displayed?

Challenge: Change the program HOWDY to display a two-line


message: HOW'RE Y'ALL DOIN'
THIS FINE DAY?
Solution: Simply APPENDing "THIS FINE DAY? 11 won't do this,
because all you'll get is one long message on a single line
- so the message will be half hidden.

You need to use a special character on the ALPHA Menu:


lil!I3 (!) ll!JI- called Line Feed (LF, for short):
)
•PRGM~ takes you to line 03, where you then need to
delete the 11 ? 11 with a~. then APPEND a Line Feed )
character: •ALPHAIENml) DOIN' lilfilij (!) ll!JI (ALPHA). )

Then for the last instruction, just APPEND the rest of


the message: ~THIS FINE DAY? (ALPHA).

Now (EXIT) and press (XEO) llll1mJ to see a thing of beauty!

)
To review, then:

APPEND (r) allows you to add ALPHA strings to the end of mes-
sages already in the ALPHA-register.

allows you to break the contents of the ALPHA-


register into two-lines for display purposes.

ARCL (remember, from page 124?) recalls the value of a par-


ticular variable or register and APPENDs the charac-
ters representing that value (not a number) to the
current contents of the ALPHA-register.

SousetheAPPENDinstruction to "tackonto"whatever'salreadyin the


ALPHA-register.

And use ARCL to recall (changing any number into a numeral) and
APPEND to the ALPHA-register, all in one swell foop .

Now you're ready to put all of these ALPHA tricks to good use as you
really fix up your NCYL program....

BUILDING YOUR OWN TOOLS: Programming 207


Fix It Good: Change NCYL so that it produces output like this:

VOLUME=30,394.9
SURFACE AREA=5,466.4

The Big Fix: •Gro)cmJ~ takes you to 11 t~CYL 11 •


Step up to line 24, delete it ((B), and add:
~REA(ALPHA) stores the second answer as
the variable, AREA.
.ALPHA)VOLUME=(ALPHA) puts VOLUME= in the Al-
p HA-register.
•ALPHA}RCL)l'fil!!I recalls the variable, VOLUME, and
appends its numerals to the ALPHA-register,
rightafterVOLUME=.
l(ALPHAfENTERhSURFACE AREA={ALPHA) appends the
entire ALPHA-string to what's already in the
ALPHA-register. TheLINEFEED(LF)causeseve- )
rything that follows it to be displayed on the )
second line of the display.
~RCL!ALPHA)AREA(ALPHA) recalls the variable
AREA and appends its numerals to the ALPHA-
register, right after SURFACE AREA= .
•PGM.FCN)~lill!lll causes the program to stop running
and the entire message to be displayed.

(EXIT) and (XEO)cmJ(RJS) to test the program.... It works!

u
208 An Easy Course In Using The HP-428

)
Review

Already in this chapter, you've learned a lot of new things about pro-
gramming your HP-42S. Pause here and look at what you now know:

• You can find the permanent • END. and prepare for a new program.
• You know how to begin and name programs using labels.
• You know three ways to END them.
• You know how to change a program.
• You know how to move around within a program, either step by step,
or more rapidly.
• You know how to "run" or "execute" a program using the [RIS) and
[XEO) keys respectively.
• You know how to find out how much memory you have left.
• You know two different ways to input values into a program.
• You know how to use the VIEW instruction to label an output.
• You know the program instructions needed to store messages in the
ALPHA-register.
• You know how to use the PROMPT and AVIEW instructions to
display those messages.
• You learned that the EXITALL instruction exits all menus, taking
you to a Stack Display.
• You know how to use the APPEND and LINE FEED characters to
develop longer, more complicated, even two-line messages.

You really know all that?

There's one way to find out....

BUILDING YOUR OWN TOOLS: Programming 209


Preliminary Programming Probe

1. What's the difference between Run mode (also called Stack


mode) and Program mode? Can you always tell which mode your
calculator is switched to by looking at the display?

2. What happens when you're in Program Mode, the program


pointer is pointing at END, and you press ~

3. If you have three programs, A, B, and C, stored in memory and


you're currently looking at line 05 of program B:

a. What's the quickest way to move the program pointer to line


07 of program C?

b. What's the quickest way to start a brand-new program?

)
4. Name three instructions that can cause a program to stop run-
ning and wait for you to press a certain key.
)

How are they different from each other? )

)
How do you restart the program after each of these instructions?

)
210 An Easy Course In Using The RP-428 ( )

)
5. The formula for the volume of a sphere is

V =:l7tr3
3

where r is the radius of the sphere.

Write a program, labelled 11 SPHERE 11 , that will compute the vol-


ume of a sphere, given its radius. That is, write a program to
solve this equation:

OUTPUT = :!_ x 7t x (INPUTf


3

Use an INPUT statement and label the output answer.

6. Write a program, called GREET, that displays the message,


"THE RADIBOLICAL HP-42S AT YOUR SERVICE" on two lines
of the display. Both lines should be centered in the display.

7. The density of a material is defined as its mass divided by its


volume. The volume of a rectangular solid is:

VOLUME =Length x Width x Height

Write a program , labelled 11 DENS I TY 11 to calculate the density of


a rectangular solid (to 3 decimal places) from the mass (M),
length (L), height (H), and width (W). Use menu variables, but
prompt for the input. Label the output answer with DENS I TY =.

BUILDING YOUR OWN TOOLS: Programming 211


P. P. P. Answers

L In Run Mode, functions will be executed immediately when you


press the keys. In Program Mode, functions are stored as lines
of a program (to be executed when the program is run). If the
calculator is in Program Mode, you'll see one or more numbered
program lines and the program pointer c• ).

2. The program pointer returns to line 00 of the current program.


You cannot leave the current program by using the@and (!)keys
(nor the~ and~ keys). The program lines are a kind of
continuous loop -the "next" line after the "last" instruction is the
"first" line.

3. a. You can either [EXIT] Program Mode and press •GToIor stay in )
program mode and press •GTO]c:J [ALPHA]C (ALPHA]. Then (in
)
either case), press •GTo]c:J and @]]TITIJ or (flENTERJ.
)

b. Press ~to prepare to key in a fresh, clean program. )


)
)

)
212 An Easy Course In Using The HP-428 I
4. Three instructions that will always cause a program to stop
running are: INPUT, PROMPT, and STOP (which you get by
pushing the [RIS) key while in Program Mode):

• INPUT has an additional function for both the display and the
program. When the program encounters an INPUT, the user
will see the name of a variable and a ? , which means that the
user should then key in the desired value for that variable.
Then, when the program is restarted, the value in the X-
register will be stored in that variable.

• PROM PT affects only the display. When the program stops be-
cause of a PROMPT, it displays the current contents of the AL-
PHA-register until the program is restarted.

• STOP affects neither the display nor the the program. When
the program halts because of a STOP, it just stops - nothing
more happens.

In all cases, to restart the program after it stops, you need to


press the [RIS) key.
5. After moving to a new program space with •Gro]ffimPRGMJ:

You Key In You See

.PGM.FCN)llmlll SPHERE [ALPHA) 01 LBL SPHERE


11 11

.(PGM.FCN)am!i)[ALPHA) RADIUS (ALPHA) 02 INPUT RADIUS 11 11

0 03 3
llrJ 04 YtX
ti 05 PI
~ 06 x
GJ 07 4
~ 08 x
0 09 3
8 10
[srol'Mil 11 STO 11 VOLUME 11
.PGM.FCN) f1ImlE!!J 12 VIEW VOLUME 11 11

)
~ 13 .END.
When you actually use the program, the INPUT statement makes )
the display actually say RAD I US?, so that you won't forget what
needs to be keyed in.

Then the VIEW statement at the end of the program labels your
answer, VOLUME=. Since it's your only output, you don't need to
worry about any more complicated ways of labeling it.

Now test the program by pressing [EXIT)[XEO) ffirrll, then use a


radius of 8: @[RIS) Answer: VOLUME=2, 144. 7

)
214 An Easy Course In Using The HP-428 )

)
6. This program is similar to the one you did earlier, on page 206.
You need to plan your spacing carefully: You can put a maximum
of 22 characters on each line, and there are 38 characters in the
message, so you'll have six left over on the second line.

The program listed below gives you the following display (includ-
ing the three spaces before " AT YOUR SERVI CE ! " and three
after):
THE RADIBOLICAL HP-42S
AT YOUR SERVICE!

You Key In You See

ll§IQ)c::EJllPRGM) 00 ( 0-Byte Prgm }


.PGM.FCN]l!llll GREET [ALPHA] 01 LBL 11 GREET 11
.ALPHAJTHE RADIBOLICAUALPHA] 02 11 THE RADIBOLICAL 11

.ALPHA{ENTffi] HP-42SLF AT [ALPHA] 03 l- 11 HP-42SLF AT II


~YOUR SERVICE![ALPHA] 04 l- 11 YOUR SERVICE! II
.PGM.FCN](!)WI!D 05 PROMPT
(!) 06 .END.
Line 03 calls for the careful planning. You need to remember the
space before "HP-42S" and the LINE FEED (LF) immediately after
it. Then come the three spaces before "AT".

GREET shows you an example of how one message can be broken


up into three program lines! Test it ([EXIT)(XEO]l!fil))!

BUILDING YOUR OWN TOOLS: Programming 215


7. This program has four inputs and one output, making it an ideal
candidate for menu variables. Here goes:

You Key In You See

~·PRGM.PGM.FCN) 00 { 0-Byte Pr9M }


.(PGM.FCN)lml DENSITY (ALPHA] 01 LBL 11 DENSITY 11
~ fil.'m(ALPHA)M(ALPHA) 02 Ml/AR "M"
fil.'m( ALPHA JU ALPHA J 03 Ml/AR "L"
fil.'m( ALPHA )H( ALPHA J 04 Ml/AR "H"
fil.'m(ALPHA)~ 05 Ml/AR "W"
~EHll(ill] 06 FIX 03
l'lllEII m:!:m 07 VARMENU 11 DENSITY 11
~INPUT VARIABLES(ALPHA) 08 11 INPUT VARIABLES"
(!)(!)~ 09 PROMPT
~M(ALPHA) 10 RCL "M"
~UALPHA] 11 RCL 11L11
~H(ALPHA) 12 RCL 11H11 )

~ 13 x
[RCL}ALPHA)~ 14 RCL 11w11 )
~ 15 x )
8 16 -:-
11 DENSITY = )
~DEN (ALPHA] 17 II

~DENSITY = (ALPHA) 18 ARCL ST X )


~(RCL}ALPHA)DEN(ALPHA) 19 PROMPT )
8PGM.FCN)(!)~ 20 I EMD.
(!)

216 An Easy Course In Using The HP-428


Notice that an EXITALL statement was not included in this
program. This is because there's only one output, so you don't
need to clear any menus in order to see both lines of the display.

The position of the FIX statement isn't critical, as long as it


precedes the ARCL (remember that any append - such as that
done by the ARCL - will use the current display setting for its
guide as to how many decimal places to append).

Since all of the MVAR statements must come right after the label
11 DENS I TY 11 , the earliest you can FIX the display setting is step

06. And it's a good idea to do it there, so that when you're keying
in your inputs, those values will be echoed back to you in the
same precision as the final answer.

So try the program ([EXIT)[XEa]lrna), using the following data:

mass= 258.9 grams


dimensions: 10.5 cm x 2.4 cm x 5.9 cm

Answer: DENSITY = 1. 741 (g/cm3 )

[EXIT] to the Stack.


Using Labels For All They're Worth

Up to this point, you've used labels only at the beginnings of programs


- in order to name them. But that's not nearly all they're good for.
Limitingthe use oflabels to that would be like limiting your sentences
to stuff like "See Spot run!"

Besides marking the beginning of a program, labels can mark impor-


tant "landing points" for skipping around within a program. This
allows you to write "complex sentences" - programs that have several
different paths, instead of just one.

This shouldn't come as too much of a surprise. You already know that
the instructions XEQ ("execute") and GoTO are used to make the
program pointer jump to particular labels, right?

When you press [GTO) CmJ, for example, you're telling the program
pointer to search all of program memory for the line containing the
instruction LBL 11 NCYL 11 , and to jump and place itself there. Similarly, )
when you press [xea)CI!i) you also jump to that instruction, but then
the program will begin running right at that point. )

Well, by using labels at various different points in a program, you can


collect together useful sequences of program steps, called routines,
thus building very elaborate, yet compact programs.

The next thing you need to learn about, then, is that there are really
two kinds of labels - global labels and local labels.

If you already know all about this, then you may skip to page 223.
)
218 An Easy Course In Using The HP-428 I

)
Global Labels Vs. Local Labels

The rumors are true: There are two types oflabels - global labels and
local labels.

Global labels may be used for jumping between any two points in
Program Memory. Local labels can be used only for jumping within a
program. You can always tell a global label, because it always uses
ALPHA characters and is surrounded by quotation marks.

Try This: Identify the following labels as either global or local:

01 LBL FREE 11
11

02 LBL 01
03 LBL B
04 LBL 11 Q11
05 LBL 99
06 LBL 11 99 11

Answer: 01, 04, and 06 are global; 02, 03, and 05 are local labels.

Global labels use up to seven ALPHA characters. Any ALPHA charac-


ters, including numerals, may be part of a global label. And global
labels are always within quotation marks (and thus easy to identify).

However, all numeric labels from 00 to 99 and the single-letter labels


Athrough J and a through e are reserved for local labels, and as such
they are displayed without quotation marks.

BUILDING YOUR OWN TOOLS: Programming 219


Global labels can be found from anywhere in program memory, so they
will be listed in the program catalog (.CATALOG]E§lli) and listed on the
menus for[XEO]and[GTO]. Local labels will not.

Local labels are ... well, local. The only time the HP-428 can "see" a
local label is when the program pointer is positioned within the pro-
gram containing that label. If there's an END statement between the
program pointer and a local label, the HP-42S won't find that label.

Challenge: Write a program, labeled 11 COUNT 11 , that starts at zero


and counts continuously, pausing at each number.

Solution: Keystrokes Display

~ 00 { 0-Byte PrgM )
.PGM.FCN)~ COUNT [ALPHA) 01 LBL 11 COUNT 11
@J 02 0
.PGM.FCN]~@ID 03 LBL 01
.PGM.FCN](!JllD 04 PSE
(The PSE function briefly PauSEs a running program.)
CD 05 1
(±) 06 +
.GTO]@ID 07 GTO 01
(!) 08 • END.

COUNT 11 is a global label, right? Ifyoupress[EXIT]and[xEa], you'll find


11

it listed (as E!TI!J3) in the menu. But LBL 01 doesn't appear on the list
because it's a local label accessible only from within COUNT.

220 An Easy Course In Using The HP-428 )


..)

Now, notice how COUNT works - press r!TI!I:I. It definitely works!

Line02 "keys in" the starting zero to the X-register. Then line 08 serves
as the beginning of the counting "loop" (local labels often serve this
purpose). Next, line 04 pauses the program to display the contents of
the X-register. Then lines 05 and 06 add 1 to the X-register, and line
07 sends the program pointer back up to line 08 to repeat the loop -
which will begin with a 1 this time, then a 2 next time, etc.

Now Try This: Stop the program ([RJS)), key in(]), and restart it by
pressing [RIS) once more. The program starts its
counting at 5, right? OK, stop it again and key in
(}@, but then restart it by pressing~·

What Gives? The second restart method works also - but only
because the program pointer was still somewhere
within the program, COUNT, where it could find
that local label, 01, when you "called" it.

But Try This: Press [RIS) to stop the program, then •GTo lffi to
go to new memory space. Now key in Cim and
press ~to start it counting up from 12.

What Happens: You get the message, Label Not Found! Why?
Because you're asking the HP-428 to find a local
label when the program pointer is not in the pro-
gram containing that label. You need to press
•GTO)E!!l!l:lfirst, and then~-

BUILDING YOUR OWN TOOLS: Programming 221


Which Type of Label To Use

OK - so when should you use a global label and when should you use
a local label? Why worry about local labels at all? Why not simply use
global labels for everything?

First of all, you must use a global label at least once in every program
- so you can "call up" that program from anywhere else in Program
Memory. In fact, you should use a global label at any point in a program
that you want to be able to "jump" to from another program.

Global labels are more convenient, but it's best to use them conserva-
tively, because they can cost you in two important ways:

• Global labels use more memory than do local labels. Why eat up
bytes unnecessarily?

• Global labels can slow down a program when it's running. You see,
when your machine searches for a global label, it must search
through all of Program Memory, one global label at a time, to try to
find the one you've called. And this search is in one direction only )
(starting from the , END, ), so even if the label you want is "nearby,"
the pointer won't necessarily find it any the quicker, since it doesn't
)
just "look around" to see ifitcan spot it quickly; it goes through this
methodical search, which can take awhile. )

So use local labels to make jumps within a program. This will usually )
make those internal jumps faster and take up less memory than if you
use global labels for the same purpose.

222 An Easy Coune In Using The HP-428

}
Branching Out With[GTO)And [XEO)

All right, now that you've got a good idea about labels, it's time to try
some programs that use them to branch and "jump about."

Do This: Press 8PGM.FCN]~GRI. Yep -your HP-428 can make


noise! Key in these two short, noisy programs:

01 LBL 11 SONG 11 01 LBL TW 11

02 GTO 11 TN 11 02 TONE 9
03 BEEP 03 END
04 TONE 0
05 BEEP
06 TONE 4
07 BEEP
08 TONE 8
09 END

Solution: For SONG: .GTO)ffi~8PGM.FCN]lmll SONG


[ALPHA).GTO)(ALPHA] TN (ALPHA).PGM.FCN).PGM.FCN)~
mlJrnmJ@JGRll]fil])@JGRl~0[EXIT]

For TN: •GroJffi8PGM.FCN)i!H TN (ALPHA)


.PGM.FCN) ~ l]fil])@J [EXIT)

)
Now, press [XEO)Billl!I to hear the longer of these two pieces ....

)
Hmmm ...something's wrong!

BUILDING YOUR OWN TOOLS: Programming 223


Although you keyed in all those TONEs and BEEPs, all you get is one
note! What's really happening when you run SONG?

Well, thecalculatorstartseXEOutingat01 LBL 11 SONG 11 ,butsincethe


second line of that program is GTO 11 TN 11 , it jumps to global LBL 11 TN 11
and follows those instructions instead. When it reaches the END state-
ment in the TN program, it just stops.

The GTO at line 02 of SONG is like a fork in the road. It's no temporary
sight-seeing trip - it's a heavy commitment. Whenever the pointer
jumps to a label because of a GTO, it forgets all about where it jumped
from and just forges on, following whatever instructions it encounters
in its 'brave new world."

Ah, but ...

Try This: Go back and change line 02 of SONG to 02 XEQ 11 TN 11


)
Solution: Press •GTO)~·PRGM) to move the pointer back to the )
"SONG" program from the END of the TN program. Then )
move to line 02 with(!), and press (B to delete the line.
Now key in the replacement line: [XEO]llCll.

Now [EXIT) and [xEa) ~- ...

That's better, no? So why does the XEQ work where the GTO didn't?

.I
224 An Easy CouT'!le In Using The HP-428
Well, if you listen closely, you'll hear a TONE 9 (high pitch) before the
first BEEP. The pointer jumps to the TN program, sounds the TONE 9,
and then returns to the point it branched from in the SONG program,
)
to continue on from there.

The program pointer knew how to do all that because of the XEQ - that's
what XEQ really tells it: "Start from this point, search for this label, and
when you find it, follow your nose through the instructions after it until
you encounter either a ReTurN statement or the HlD of a program.
From there you must return directly back to this XEQ and continue
following the instructions that follow on from here."

An XEQ is really a side-trip that temporarily branches execution to


another place until a RTN or END is encountered. By contrast, a GTO is
not a temporary side trip; once you've "jumped" via a GTO command,
the only way to jump back is to use another GTO command and another
label. But XEQ carries its return address right along with it!

Notice that even when you manually pressed the keys, [xEa)~, you
were telling the computer this same "do something and return here"
message: Before you pressed the keys, it wasn't doing anything. And
sure enough, it returns to "doing nothing" after it finally encounters
the END of that program.

In fact, all the built-in functions and tools in your HP-428 are really
little XEQ side trips, too - complete with built-in Re TurN statements.
After using any of these tools, your machine returns to whatever it was
doing previously, whether it was running a program or just sitting
around.

BUILDING YOUR OWN TOOLS: Programming 225


Routine Subroutines

When you build such side-trips into an HP-428 program with XEO,
they're usually called subroutines. And you can even have "sidetrips
within side-trips within sidetrips ... ," etc. - nested subroutines up to
8 levels deep. That can be a mess, so before you try anything so
intricate, practice building and using some simpler subroutines.

Challenge: Go back and change the program GREET so that it


branches to the program HOWDY and displays its
message for three seconds before returning and fin-
ishing with GREET's original message.

Solution: You need to modify both programs: In GREET, insert


a new line after the label that sends the pointer to )
HOWDY: •GTO)ffii1:!1~ and [XEO]~Cl!l!m.
)

Then [EXIT], and press •GTo]~Cl!l!m~ and ~to )

line 05. Now you can replace the PROM PT with two
steps: a CF 21 and an AVIEW, then three PauSEs.
The Clear Flag 21 will keep the program from stop-
ping when it encounters the AV I EW (you'll more about
this shortly). Here are the keystrokes:

(B~lmll~·PGM.FCN)riWm)~DJI
D]IDJI [EXIT)[EXITJ.

Try it out: Press [xEa) lfillll.. .. ... Not bad!


)
226 An Easy Course In Using The HP-428
Try another example - this time with some real number-crunching.. ..

Challenge: The quantity of heat absorbed by a solid object when it


increases in temperature can be calculated by the fol-
lowing formula:

where

Q = quantity of heat (in calories)


m = mass of the object (in grams)
c = specific heat of the object (in calories/gram/°C)
TF =final temperature of the object (in °C)
TB= beginning temperature of the object (in °C)

Write a program, HEAT, that calculates Q if you input


the mass (m), the specific heat (c ), and the beginning and
final temperatures in °F.

Hint: That last part is the tricky part: You need to convert °F
to °C before you use a temperature in the equation. So,
why not use your first program, Fl RST (remember pages
) 175-177?) as a subroutine for this HEAT program?

Work on this. See if you can get the whole thing. Then
turn the page to see one possible solution ....

BUILDING YOUR OWN TOOLS: Programming 227


Solution: Keystrokes Disnlay
.GTO)c::EJ~ 00 { 0-Byte Prgm )
.PGM.FCN)rn:I HEAT (ALPHA) 01 LBL 11 HEAT 11
.PGMFCN)
.PGMFCN)~ln.VillJ(ALPHA) M (ALPHA) 02 MVAR 11M11
lllVill)(ALPHA) C [ALPHA) 03 Ml/AR 11c11
GNilJ(ALPHA) TF (ALPHA) 04 MVAR urF11
GNilJ(ALPHA) TB (ALPHA) 05 Ml/AR uTB11
l1LllmlITm 06 VARMENU HEAT II II

(RIS) 07 STOP
(RCL)(ALPHA) TF (ALPHA) 08 RCL urFu
(EXITJXEO)(!)lifm 09 XEQ FIRST 11
11

[RCL)(ALPHA) TB (ALPHA) 10 RCL 11rs11


[xEa)(!)li!m 11 XEQ 11 FIRST 11
EJ 12 -
[RCL)(ALPHA) C (ALPHA) 13 RCL ncn
~ 14 x
[RCL)(ALPHA) M (ALPHA) 15 RCL 11M11
~ 16 x
[sro)[ALPHA) Q [ALPHA) 17 STO llQll )
.PGM.FCN)l!lim(ALPHA) Q (ALPHA) 18 VIEW 11 Q11 )
(!) 19 •END.

Now [EXIT) and try the following data: )

m = 200 g; c = 1.00 cal/g/°C; TF = 96°F and T8 = 52°F

)
Answer: Q=4, 888. 9 (calories)
)

228 An Easy Course In Using The HP-428


Selective Branching:
The Programmable Menu

Now, having familiarized yourself with the use ofGTO and XEOjumps
to labels within a program, you're sure to appreciate the Program-
mable Menu.

The Programmable Menu is a menu containing your own special list


of jumping instructions that you can select from with the menu keys.
Remember VARMENU? That was an easy way to choose which data to
input. Similarly, the Programmable Menu gives you an easy menu
format for choosing which parts of a program to run.

In the previous problem, for example, you were asked to write a


program to calculate the number of calories of heat absorbed by an
object ifyou input the object's mass, its specific heat, and the beginning
and ending temperatures in °F.

But suppose now that sometimes the temperatures were in °F and


sometimes in °C. You'd need to have some way oftelling your calculator
which temperature scale you were using - and you'd want the calcu-
lator to treat such entries differently, of course.

This is where the Programmable Menu could be very useful: You could
write a little program to give you a menu with choices for which kind
of conversion routine you wanted to run. Then you could choose the
proper routine for each datum.

BUILDING YOUR OWN TOOLS: Programming 229


Example: Write a program, labeled 11 QCF 11 , that uses a Program-
mable Menu containing two choices - ~ and &al.
When you press~, the program should XEQ 11 FIRST 11 ;
when you press &al, the program should simply END.

Solution: Keystrokes Display

ll§!Q)OJ~ 00 { 0-Byte PrgM }


.PGMFCNJl!BI QCF (ALPHAJ 01 LBL 11 QCF 11
02 II DFll
~°F(ALPHAJ
.PGM.FCNJ~mEl~~6Jm 03 KEY 1 XEQ "FIRST"
~°C(ALPHA] 04 II ac11

.PGM.FCNJ~IBm~@TIJ 05 KEY 2 GTO 02


.PGM.FCNJ~im:I!J 06 MENU
.PGM.FCNJl!Dl@Ifil 07 LBL 02
08 • END. ()
~
)
Lines 02 and 03 set up the milJll menu item, and lines )
04 and 05 set up the llilll menu item. Line 06 causes
the Programmable Menu to be displayed. Then the
program will stop at the • END. - but it's still ready and
waiting for you to select one of its pre-defined keys. )

[EXITJ and [xEa]mg. Now try 68°F and 34°C to see what )
happens. Pressing~ converts the temperature, but
pressing arll does not, right?
)

See how the Programmable Menu works? Here's how you use it....
)
230 An Easy Course In Using The HP-428
To create a Programmable Menu, you use these three instructions:

• KEYG ("on KEY Go to")letsyouspecifythe label you want the pro-


gram to jump to with a GTO when a particular menu key
is pressed.

• KEYX ("on KEY eXecute") works just like KEYG function except
that the named label will be called with an XEQ instead of
a simple GTO when a particular menu key is pressed.

• MENU causes the Programmable Menu to be displayed and the


program to stop running - analogous to the VARMENU
instruction you use when working with variable menus.

The KEYG and KEYX instructions require two programming lines for
each item you want on the menu.

On the first line you must enter an ALPHA string that will appear as
the menu selection itself. Notice that a selection does not need to be
named with the label it calls.

The second line must begin with the actual command, KEYG or KEYX.
Then you tell the calculator on what key to "place" this menu item, by
pressing one of the eligible keys (the 6 top-row keys and~,~. and [EXIT]
can be used, and they're numbered 1-9 in that order).

Then you finish the second line by specifying the label to GTO or XEQ
when that menu item is chosen.

BUILDING YOUR OWN TOOLS: Programming 231


Another: Create a very short Programmable Menu in a program
labelled 11 HAUNT 11 • The only item on the menu should be
IE!ll (assign it to the~ key- that's KEY 5) and it should
cause the eXEOution of the program HOWDY.

Solution: Keystrokes Display

~rn~ 00 { 0-Byte Pr9r11 )


.PGMFCN)l!a HAUNT (ALPHA) 01 LBL "HAUNT"
~BOO! (ALPHA) 02 11 800 ! II
•PGMFcNJ~mm~~llEI!El 03 KEY 5 XEQ 11 HmlDY 11
.PGMFCN)!m1I!J 04 MENU
~ 05 • END.

Try it out to make sure it does what you expect it to do.


Everything OK?
)

OK, But: Suppose you then decide that you don't really want to use
llEll in your menu, but 1:J11 instead (it's friendlier). And
you really wanted to assign it to the 0J key, not the~·
0
So: You want: 02 11 HI ! 11 and 03 KEY 3 XEQ 11 HOWDY 11 • )
To make these changes, step to line 03 while in Program
Mode, then press:~~ HI! (ALPHA).PGMFCN)~ IHBI
)
@~ llEI!El-

)
232 An Easy CouNe In Using The HP-42S
Now try out this modification: Press (EXIT) and [XEO] lm!ill)....

Hmmm ... What's that IE!1I item still doing there on the menu? Didn't
you "kill" it by replacing it with the l]]I item? Apparently not. What
does it take to get an item off of the Programmable Menu once it gets
put there, anyway? Do you need to clear the entire program?

Try It: Clear the program HAUNT from memory.

Solution: Press~~ lm!ill).

Now, just to make double-sure that these items are gone from the
Programmable Menu, run another program that creates and uses that
menu. (XEO)m:il once again ....

... Uh-oh ...... ("They're baa-aaack!") Those menu items continue to


haunt your calculator. You can't seem to get rid of them. Why not?

You've actually killed ("deleted" is the more civilized term for it) only
the instructions that assigned "BOO!" and "HI!" (and their associated
XEQ and GTO commands) to the [ill and@ keys, respectively. DIT!ll
and IIlll are still assigned there, even though the instructions that put
them there are now gone. Your HP-428 stores the nine programmable
key assignments in its built-in system memory, but it doesn't auto-
matically clean this storage area out when you delete the instructions
that made those assignments. You need to do that yourself.

So, who ya gonna call?

BUILDING YOUR OWN TOOLS: Programming 233


~(!) t!!E), that's who! Clear MeNu clears all Programmable
Menu key assignments, leaving a fresh slate for a new Menu.

Try It: Press ~(!)tml:I, and then [XEO]m:I.

Result: You've done it! You've gotten rid of the ghosts! The only
Programmable Menu items are those actually being cre-
ated now by the current program QCF. You're no longer
HAUNTed by past menus or their ancestors.

It's a very good idea to include a CLMN instruction at the END of every
program that uses the Programmable Menu - so that you don't go
populating the menus of other programs with ghosts! You could also
0
()
make it a practice to begin each program with a CLMN instruction, too.
That way, you know you're slate is clean. ()

One more thing: If the current use of MENU happens to assign items )
where previous assignments had been, then of course, the new assign-
)
ments will overwrite (replace) the previous ones. So that's one more
way you can clear old assignments - overwrite them with new ones.

-----·-
Multi-Page Programmable Menus

So much for unwanted Programmable Menu items. But how do you


create a Programmable Menu with more than one page?

Challenge: Write a program, MUSIC, that uses a Programmable


Menu to play the eight notes of a major scale: Do, Re,
Mi, Fa, So, La, Ti, Do (the TONE's from 1 through 8
produce these scale notes). Use "DOl-" and "Dot" to dis-
tinguish the octaves.

Solution: As always, break a big job down into separate, identifi-


able, easier-to-handle sub-jobs ("lumps"):

Lump 1: Begin the program and label it.


Lump 2: Create the first page of the menu ("DOl-"
through "LA")
Lump 3: Assign menu-changing and exiting rou-
tines to~'(!), and (EXIT) (this is how you
candomulti-pageProgrammableMenus).
Lump 4: Use the MENU command itself.
Lumps 5-7: Repeat Lumps 2-4 for the other page of
the Programmable Menu.
Lump 8: Use subroutines and TOME statements to
actually play the notes.
Lump 9: Exit the program.

The following solution is organized in these Lumps.


Keep your place as you read the discussion following it:

BUILDING YOUR OWN TOOLS: Programming 235


il§filc:::EJ~-------1------0010~~eP~m}

tlPGMFCN).PGMFCNJ~I:1~~~(~~~----0_!_l~l:_~~~f_ 1 ~-
~ 02 LBL A
~DO!-( ALPHA] 03 II DO-!- II
~rn:.m(B@ID 04 KEY 1 XEQ 01
~RE(ALPHA) 05 11 RE 11
rn:.m~(fil] 06 KEY 2 XEQ 02
~Ml(ALPHA) 07 11 MI II
2
rn:.m@CillJ 08 KEY 3 XEQ 03
~FA( ALPHA) 09 11rn11
rn:Illl[LOG)@TI_) 10 KE\r 4 XEQ 04
~SO( ALPHA) 11 11 S0 11
C!m(IBJ (ill) 12 KEY 5 XEQ 05
~~ 13 11 LA 11 (
IB@JQEal.@]]J_ ________________ ~~~~~~~-~-
( )
m:!I!l~[ALPHA)B(ALPHA) 15 KEY 7 GTO B
m:!I!l(!J[ALPHA )B(ALPHA) 3 16 KEY 8 GTO B
()
~~~~~----------------~!~~~~~-~-
llilll!I 18 MENU )
4 19 STOP
~~LPHA~ALPHcl _ _ _ _ _ _ _ _ _ _ _ _~Yl~~-----
rnJI B[ALPHA) 21 LBL B
~(!JrmID 22 CLMrnu )
23 11 TI II )
5
~m:EJ(B@ITJ 24 KEY 1 XEQ 07
~OOt[ALPHA) 25 11 DOt 11
lli@~0!J-----------------~~~~~~~y~_ )
m:!I!l~[ALPHA) A (ALPHA) 27 KEY 7 GTO A
m:!I!l(!J[ALPHA) A (ALPHA) 6 28 KEY 8 GTO A
~[EXIT)®ij 29 KEY 9 GTO 99
)
236 An Easy Course In Using The HP-42S
iiilli!f--------------------~M~m------

(0 7 31 STOP
~~LPHA@ALPHfil ____________~Yl~~-----
lfilll@TIJ 33 LBL 01
~lmIJCD 34 TONE 1
~IEI 35 RTN
1m1 (ill] 36 LBL 02
~lmIJ0 37 TO~lE 2
~IEI RTN 38
l!Bl(fil) LBL 03 39
~lml)~ TONE 3 40
~IEI RTN 41
lml(ill) LBL 04 42
~IEIJ8J TONE 4 43
~IEI 8 RTN 44
lml(ill) LBL 05 45
~DmfI) TONE 5 46
~IEI RTN 47
lml(ill) LBL 06 48
~lml)@) TONE 6 49
~liilll 50 RTN
lml(fil) 51 LBL 07
~nmm 52 TO~lE 7
~IEI 53 RTN
lml(ill) 54 LBL 08
[!l!)Dmffi 55 TONE 8
(!:(!) liilll 56 RTN
-------------------------------
lml(ill] 57 LBL 99
~~cmm 9 58 CLMENU
.CATALOG]IEll~mml 59 EXITALL
---------------------------------
BUILDING YOUR OWN TOOLS: Programming 237
Lumpl begins the program and labels it with a meaningful
global label <"MUSIC 11 ), so that you can call this program
from anywhere else in Program Memory.

Lump2 begins with a local label <A), to allow execution to jump


back to this point. This section includes all of the in-
structions needed to make a menu containing the first
six items - the first page of the Programmable Menu.

Lump3 defines what happens if~,~. and [EXIT] are pressed. ~


and~ will send the program pointer to Label 8 (Lump
5) which is the set-up for page two of the menu. This is
exactly what you want the ~ and ~ buttons to do -
"page" you through the menu. [EXIT) <KEY 9) causes the
program pointer to jump to the exit routine (Lump 9)
which "tidies up" a bit before exiting the program.
( )

Lump4 includes the MENU command to actually construct a Pro- ()


grammable Menu from the current key assignments. )
(those in Lines 04, 06, 08, 10, 12, 14, and 15-17).

Lump 4 also contains a loop of circular reasoning - a


trapping loop. Its purpose is to keep the menu showing
after you select one of the menu items, thereby allowing
you to select several in a row. When the program pointer
returns from eXEOuting any item on a Programmable
Menu, it returns to the line immediately after the f1£NU
instruction itself In this case, that line is STOP, which
stops the program without changing the Menu, allowing
you to choose another "note," etc.

238 An Easy Course In Using The HP-428


And notice the GTO A command after the STOP. This
forces the user to use the Menu, since [RIS) merely
restarts that section of the program. Trapping loops are
often used like this to prevent the unwitting user from
doing something that could "crash" the program.

Lump5 sets up the second page of the Programmable Menu,


after first clearing the key assignments of the first page.
Without this clearing step, the last four of the first-page
menu items would still be present on the second page.

Lump6 sets up the~.(!), and [EXIT] keys in a manner similar to


Lump 3.

Lump7 displays the second page of the menu, and then uses an-
other trapping loop to "trap" the display of page two of
the Programmable Menu and render [RIS) harmless (to
see how critical these loops are to the smooth function-
ing of the program, try temporarily deleting them and
then use the program!).

Lump8 contains all of the small little subroutines that cause the
notes to be played. Notice how each one ends with a RTN
that sends the program pointer back to below the MENU
statement that sent it.

Lump9 is the EXIT routine that clears the Programmable Menu


key assignments and exits all menus. It's always a good
idea to try to leave the machine exactly as it was before
the program was executed.

BUILDING YOUR OWN TOOLS: Programming 239


[EXIT) out of Program Mode to test this program, MUSIC
(after first making sure that you've restored its proper
structure after any experimenting you may have done).

Have Fun: See if you can play "Mary Had A Little Lamb."

Not Baa-d: [xEa) W!fil!, then play:

Ml-RE-DOl--RE-Ml-Ml-MI
RE-RE-RE
Ml-SO-SO
Ml-RE-DOl--RE-Ml-Ml-MI
RE-RE-Ml-RE-Dot.

Although your HP-42S is a bit limited in what it can do


with sound (you can't vary the length of the TONE, for
()
example) it's not completely uncultured, is it?
)
Experiment some more on your own. Be sure to check )
out both pages of the menu. )

Also, try to mess it up ("crash it") while using it. A well-


wri tten program should resist all attempts - intentional
and unintentional - to "crash" it (of course, all your )
"sabotage" attempts should be done in Run mode; you )
can always cause problems by going into Program Mode
and mucking about, right?).

240 An Easy Coune In Using The HP·42S


Letting The Calculator Decide What Th Do

Menus - whether they're for inputting data or choosing program


routines - are there for you. They are some of the most convenient
ways to let you decide how and when to do something- right up to and
during your use of a program.

But up to this point, your calculator hasn't had to make any such
decisions. It has merely presented you with the options. Well, that's
fine for the really important decisions, but ifyou, the user, are required
to make every decision in a program of any complexity, it soon becomes
so tedious that programming isn't worth the trouble.

So wouldn't it be peachy-keen if your calculator could make certain


decisions automatically, without you having to pay attention to it nor
worry about it?

Of course it would....

There are three main strategies that you can use to get your calculator
to make its own decisions:

• Conditional tests
• Loop counters
• Indirect Addressing

You'll be introduced to each strategy, in turn, beginning with ...

BUILDING YOUR OWN TOOLS: Programming 241


Conditional Tests

Conditional tests are just that - functions that test particular condi-
tions in your calculator. They are always questions which can be
answered with "yes" or "no" (or "true" or "false"). That means it's best
to use them when you want to do one thing for a "yes" answer-say, XEQ
a subroutine - and quite another thing for a "no" answer-say, display
a message.

The key is that you don't know the answer to the question in advance.
Only as the program is running will the answer be known. Using a
conditional test is one way of making an automatic decision.

In your HP-428, the conditional test functions are all those that
contain question marks (?) as part of their function names. These
functions are spread out in several menus - primarily in the •PGM.FCN]
and ~Menus - and all work similarly:
)

• If the answer to the question is "yes," then the calculator continues


right on, performing the next program step, etc.

• If the answer to the question in "no," then the calculator skips one
step - the step immediately following the conditional test- and then
continues executing the program normally.

This general pattern is called the "Do-If-True" rule: The next step will
be done only ifthe answer to the test is "true" or "yes."

242 An Easy Coune In Using The HP-428


Remember that little program called COUNT (on page 220)? You keyed
that in and ran it as a demonstration of how a GTO statement and a
label can be used to form a continuously looping program, which will
just keep going until you stop it. But now try this:

Challenge: Modify COUNT to use a conditional test that allows it to


count up to a certain number (say, 10) then stop auto-
matically.

Solution: The new COUNT might look like this (keystrokes are
given only for new steps - the rest are easy now, right?):

Keystrokes Display
00 { 0-Byte PrgM )
01 LBL COUNT
11 11

02 10
03 STO 00
04 0
05 LBL 01
06 PSE
(@@E) 07 RCL 00
.PGM.FCN] (!)EiilESil 08 X=Y?
[RIS] 09 STOP
@] 10 R-l-
11 1
12 +
13 GTO 01
14 END

BUILDING YOUR OWN TOOLS: Programming 243


Look at this solution step by step: After the beginning (global) label,
lines 02 and 03 store the number 10 in register 00. That's your ending
count value; when the calculator gets to 10, you want it to stop
counting. Then line 04 puts a 0 into the X-register. This is the starting
count value.

After pausing to display this current count value (line 06 ), the program
then recalls a copy of the ending value (10) to the X-register, which
bumps the current value to the Y-register.

Next, at line 08, the conditional test asks the question, "Is the value in
the X-register equal to the value in the Y-register?" As long as the
answer to this question is "No" (which will be the case as long as the
current count value in the Y-register hasn't reached 10 yet), then the
STOP statement will be skipped. The machine will go on to perform
lines 10 through 12, which add 1 to the current counter value. Finally,
at line 13, it will go to the top of the loop (back to LBL 01 ), ready to
repeat the loop with a new current count value.

When the count value has reached 10, however, the answer to the test
will become "Yes," so the STOP statement is then performed, and that
halts the program!
Notice also that you can easily modify this new COUNT program to
count from any number to any other number- up or down, by one's or
any other increment-simply by changing the numbers that are placed
on lines 02 , 04 and 11. *

Such simple changes that accomplish exactly the modifications you


want - without rewriting the entire program - are the marks of good
program design. Even better is to design the program so that you, the
user, don't need to edit the program at all. You can key in your preferred
counting parameters as you use the program.

Bonus Question: Suppose you want the program to count up to


the number you key in right before you run it.
How do you do this?

Bonus Answer: Delete line 02. Then the STO 00 will store
whatever value you've keyed into the X-register
before you run the program.

Go ahead and make this change to the program


(you know the keystrokes, right?).

*If you were to change the increment value, you'd better be sure that it will eventually give you the
ending value exactly-not skip over it. That is, the difference between your starting value and the
ending value should be a whole multiple of the increment value. Otherwise, your current value
would eventually become greater than the ending value without ever having satisfied the
conditional test (and thus the loop would go on forever), because the test would always be answered
as "No." Remember that the question it's asking is whether two values are equal (exactly)-not
equal-to-or-greater-than.

BUILDING YOUR OWN TOOLS: Programming 245


Flags

So, you've used a simple conditional test to make the COUNT program
more flexible. In that case, the test compared the value in the X-
register with that in the Y-register.

But there's another kind of conditional test that doesn't have anything
to do with the X-register. This test is called a/fog conditional test. A
f/,ag is an indicator with two possible, opposte values: Set or Clear*

A flag is a convenient way to store a certain kind of data without


putting it into registers or variables. Anytime you want to remember
something that has just two possible values, you can do it by letting the
status of a fiag indicate it for you (and you can choose which flag -
they're numbered, similar to the registers).

You can see right away, for example, that a flag is an excellent way to
)
remember the yes-or-no answer from a simple conditional test (such as
the X=Y? that you've already seen) long after the question was origi- )
nally asked. It's not always convenient to retest the condition itself;
(maybe those values you need to compare aren't in the Stack anymore )
or something), but you can always retest a fiag easily.
)
)
This is because flags are stored offby themselves, not in data registers
or variable containers (look back at the Big Picture, page 18). There )
are 100 flags in all(numbered from 00 to 99), and you can test any of
them to see if they're set or clear. u
)
*You could also think of these two values as "true or false," "up or down," "yes or no," "l or O,"
)
''Yankees or Mets" - whatever.

246 An Easy Course In Using The HP-428


)

Of these 100 flags, 45 of them (flags 36-80) are called System Flags and
are controlled only by the HP-428 (you can only test these; you can't set
them or clear them explicitly). The machine uses these flags to help it
)
monitor everything that's happening while you're using it.

Of the other 55 flags, 30 (flags 00-10 and 81-99) mean nothing to the
computer. These flags are called User Flags, because they are defined
only by you - the user. You can determine their meanings solely by the
way you use them in your programs.

The remaining 25 flags (flags 11-35) are called Control Flags because
they instruct the calculator to do something (or not to do something)
- and you can alter the states of these flags as you wish.*

Try One: Clear flag 26, by pressing ~lml(Tifil


Now try to BEEP by pressing ~Drnl

Nothing, right?

OK, now set flag 26, once again (this is its more common
state): ~lll]l(Tifil.
Now try the BEEP again: .PGM.FCNI:!I!)ffill

That's better!

This is how you set and clear flags - and since flag 26 is the sound
Control flag, when you "turned it off' (cleared it), you disabled the
sound generator in your HP-428 and it couldn't BEEP at you!

*Pages 273-282 of your Owner's Manual give details about each flag in the HP-428.
)
) BUILDING YOUR OWN TOOLS: Programming 247
Challenge: Suppose you let the user choose to view the count more
leisurely: When he/she keys in a negative number as the
upper limit of the count, two PSE's should be used;
otherwise, one is enough (the count will still be done in
positive numbers). Use a flag to modify COUNT for this.

Solution: Here's one way (keystrokes are given for new steps):

00 { 26-Byte PrgM }
01 LBL COUNT
11 11

~lml@ill 02 CF 00
.PGM.FCNJ~mmm 03 X<0? )
~lmlll@ill 04 SF 00 ( )
.CATALOGJIEJlllD 05 ABS
I
06 STO 00
( )
07 0
08 LBL 01
09 PSE
~lml@ill 10 FS? 00 )
.PGMFCN]~ID 11 PSE )
12 RCL 00
)
13 X=Y?
14 STOP
15 R-l- )

16 1 )
17 +
18 GTO 01
./
19 END

248 An Easy Course In Using The HP-428


Remember: When you execute this COUNT program, the value then
found in the X-register will tell the HP-428 both how long to keep
counting (the magnitude of the value) and whether to pause once or
twice in each loop (the sign of the value).

So, after the label, the first thing to do is to clear the flag you're going
to use (line 02 ). That way, if you find it set later in the program, you
know for sure it was set by the program - not prior to running the
program. This is called "initializing" the flag.

Then, line 03 tests to see ifthe value in the X-register is negative, using
the conditional test X<0? ("Is the value in the X-register less than
zero?") IfYes, do line 04. If No, skip line 04 and continue at line 05.
Thus, only ifthat input value is negative (i.e. if two pauses are desired),
will flag 00 be set.

Lines 05 and 06 store the absolute value of the input number (the
"positive version" of that number) in register 00. This will be the
ending count value - the upper limit.

From here, the rest of the program proceeds as usual, except for one
minor change: At line 10, following the first PSE, you use the flag you
set (or didn't set) back in line 04. The second PSE (line 11) is executed
only ifthe answer to the fiag's conditional_~st is "Yes" (FS? 00 means
"is flag 00 set?")-because flag 00 was set only ifthe input was negative,
and a negative input meant "two pauses, please!"

Clever, no? Test COUNT now: [EXIT) from Program Mode and key in a
negative number. Then[XEO]HillI:). Now try a positive number. You
should see the difference in the length of the pause.

BUILDING YOUR OWN TOOLS: Programming 249


l:mD]And Flag 21

So that's how to use a User flag. But how would you use a Control flag
in a program?

Back on page 193, you read that the main difference between PROM PT
and AVIEW was that AVIEW sometimes caused the program to stop
running while PROMPT always stopped the program.

Here's the whole story: When an AVIEW instruction is encountered in


a program, the status of flag 21 determines whether the program halts
or continues. If flag 21 is set, AVIEW will cause the running program
to stop and display what's in the ALPHA-register; [RIS]must be pressed
to continue. But ifflag 21 is clear, AVIEW will display the contents of
the ALPHA-register while program execution continues. )
)

Try This: Key in the following short program. Then run it twice -
once with flag 21 set and once with flag 21 clear: )

)
01 LBL FLAG 11 11
04 AVIEW )
02 THIS IS A VERY
11 11 05 XEQ SONG 11 11
)
03 r- LFSHORT ONE"
11
06 END

Solution: Key in the program, [EXIT) and m:E@lml (TII), and )

then [XEO]~. Try it again after you 9f'.@ll!ll(TII). )


Only in the first case will you see the message without )
hearing the song (until you press [RIS)), because flag 21
)
is set, telling the AVI EW instruction to halt the program.
)

)
250 An Easy CouT'fle In Using The HP-428

.I
J

Testing The Data Type

Simple conditional tests, flags, .. . what other kinds of conditional tests


can you use in a program to let it make more of the decisions during
execution?

) Here's another kind to keep in mind: There are four special conditional
tests that test the data type of the number in the X-register:
J
• REAL? asks, "Does the X-register contain a real number?"
• CPX? asks, "Does the X-register contain a complex number?"
• MAT? asks, "Does the X-register contain a matrix?"
• STR? asks, "Does the X-register contain an ALPHA string?"

You'll find all of these tests in the •CATALOG) Menu, listed alphabeti-
cally. They're useful for detecting an illegal-or otherwise troublesome
- data-type that would cause your program to stop or crash later (like
many things in life, you can often avoid a lot of pain later by detecting
and avoiding something earlier).

So, you now have three types of conditional tests at your disposal:

• Comparison tests, where the contents of the X-register are com-


pared with either 0 or the contents ofY-register.

• Flag tests, where the status of a flag - Set or Clear - is checked.

• Data-type tests, wherethedata-typeofthe number in theX-register


is checked.

BUILDING YOUR OWN TOOLS: Programming 251


Loop Counters

While Conditional Tests and Flags are clear, direct ways to get your
calculator to make decisions without your input, there are two very
convenient functions that can do the job even more efficiently when-
ever you're using repetitive program loops -as in the COUNT program.

These "loop counters" do two useful things at once.

• They provide built-in counting procedures.


• They allow exiting from loops after a given number of cycles.

The two functions are ISG and DSE which mean, respectively:

Increment and Skip if Greater than


and )
Decrement and Skip if Equal to or less than
)

They each require an argument - that is, the name or number of a


storage container (variable or register) that contains a special loop-
control number.
)
For example, I SG 11 FRED 11 would retrieve its loop-control number from
)
the variable "FRED." And DSE 18 would retrieve its loop-control
number from register 18.

This allows you to store loop-control numbers at one point in your


program and then make convenient use of them later. The loop-control
number is a more compact, more efficient way to control your jumping
in and out of loops than is a series of conditional tests.

252 An Easy Coune In Using The HP-42S

/
J
Just how do loop-control numbers work? Take a hypothetical case:
Suppose the number 27.0571216 is stored in register 02. If your
calculator then receives the program instruction ISG 02, it does this:
)

L It looks at the number in register 02, particularly at the integer


portion (27 here) and the first five digits of the fractional portion
(.05712 here), ignoring (but not deleting) any other digits.

2. It uses the digits in the fourth and fifth decimal places (at the far
right) to form a separate integer (12 - "twelve" - here).

3. It adds (Increments) this new number to the integer portion of


the original number. So the new number in register 02 is now
27.0571216 + 12 or 39.0571216.

4. Now the HP-42S makes a little conditional test: It compares the


Integer portion (now 39) to the number that appears in the first
three decimal places (057 - fifty-seven here). Then, only if the
integer portion is Greater, the line following I SG 02 in the
program would Skipped (so it wouldn't skip in this case).

Thus the name: "Increment and Skip ifGreater than." Notice that in
these two conditional tests, the Do-If-True rule is reversed: Only if the
answer to the test ("Is the Integer portion Greater than the Fractional
Portion?") is "Yes," the next step is skipped.

BUILDING YOUR OWN TOOLS: Programming 253


Wondering why HP would make such a complicated and "backwards"
conditional test for loop control? Try some loop control numbers.

Question: What value should start in register 00 so that repeated


executions oflSG 00 will count from 10 to 27 by three's?

Answer: 10.02703 as a loop-control number is seen as: 10.027Q.3..


The integer portion is the current counting value.
The first three decimal places form the ending counting
value. The last two decimal places form the increment
- the amount the current value is increased on each loop.
)
(
Try Another: What loop-control number should be stored to
()
count from 0 to 9 by one's?
)

Answer: 0.00901 or .00901 or .00900 or .009. ()


(
Because the most common way of counting is by )
one's, the increment is assumed to be one if the
)
fourth and fifth place decimal places are zero (or
)
unspecified).

254 An Easy Course In Using The HP-428

)
)

Now, lest you be misled, the ISG and DSE functions don't form pro-
gram loops all by themselves. They still need labels and GTO's, etc.

Try This: Write (but don't key in) a program loop to count from
zero to nine, by ones.

Solution: 01 LBL 11 TRYIT 11


02 0.00901
03 STO 00
04 LBL 01
05 ISG 00
06 GTO 01
07 END

Another: Write a program that counts from -44 to 100 by four's.

Solution: 01 LBL 11 WORKS 11


02 -44.10004
03 STO 02
04 LBL 01
05 I SG 02 (The "argument," 02, here refers to a storage register.)
06 GTQ 01 (The "argument," 01, here refers to a label)
07 EMD

Get the idea? Of course, these loops don't do anything constructive (not
even displaying the count), but you can see how much easier these
loops are to build than the loop you "built from scratch" in COUNT.

BUILDING YOUR OWN TOOLS: Programming 255


Now, what about DSE?

Example: Write a program loop to countdown from 200 to 29 by7's.

Solution: 01 LBL 11 0KIDOKI 11


02 200.02907
03 STO "LOOP#"
04 LBL 05
05 DSE "LOOP#"
06 GTO 05
07 END

In this case, the control number is 200.02907, and with DSE, it's being
decremented: The first time through the loop, DSE 11 LOOP# 11 subtracts
)
7 from 200 to get 193. Then it compares this 193 to 029. Since 193 is not
Equal to or less than 29, no skipping takes place. The GTO 05 is
performed, and around you go again. )

)
On the second time around, the number stored in the variable "LOOP#"
)
is 193.02907. So DSE 11 LOOP# 11 subtracts 7from193 to get 186. But 186
)
is still greater than 29, so no skip. And here you go again - around and
around the loop, subtracting and comparing...

Finally, the value in "LOOP#" has been reduced to 32.02907. This time,
whenDSE "LOOP#" decrementsthisvalueby7,youget25.02907. Well,
25 is less than 29, so the test is finally satisfied (with a "Yes" answer),
so the GTO is skipped, the loop is exited, and that's all she wrote.

)
256 An Easy Coune In Using The HP-428

)
)

Remember:

ISG means "Increment (add) and Skm if Greater than."


DSE means "Decrement (subtract) and Skm if Equal to or less than."

With that in mind, go for broke with this Loop Counting Challenge ...

L. C. C: Rewrite (and make these changes to) the COUNT program


just once more (this is the last time - scout's honor):

Rewrite it so that it uses ISG. The ending value should still


be specified in the X-register (and negatives still mean an
extra pause), but the amount of the increment should now
be specified in the Y-register.

Test your finished solution by asking for an ending value of


39, with two pauses per cycle, counting by three's.
Solution: (One of many possibilities):

Keystrokes Display
00 { 0-Byte Pr9M )
01 LBL 11 COUNT 11
02 CF 00
08 X<0?
04 SF 00
05 ABS
CIIillIQJ 06 1000
8 07 +
[x~y) 08 XOY
lJiillillilll 09 100000
8 10 +
[±] 11 +
12 STO 00
[delete 18 0]
18 LBL 01 (
@illD 14 RCL 00
.CONVERTI!)Eill 15 IP
16 PSE
17 FS? 00
18 PSE
[delete lines 19-24] )
.PGM.FCNI!}ID 19 I SG 00 )
20 GTO 01
21 END

Test It: [Ex1r(IIENTERillIJ+1-IxEa)l!!J!l:I

258 An Easy Course In Using The HP-428

)
)

The first five steps are nothing new. They test for a negative number
and adjust flag 00 accordingly. For your trial run (with -39 as the
ending value), flag 00 will be set, requesting two pauses per loop cycle.

Lines 06 and 07 begin creation of the loop-control number. As you


recall, the ending value in a loop-control number is the first three digits
to the right of the decimal point. So, dividing the given ending value
(currently sitting in the X-register) by 1000 moves it over to those 3
decimal places: 39 + 1000 =.039

Next (lines 08 -10 ), the contents of the X- and Y-registers are exchanged
so that you can horse around a bit with the increment value. Since the
increment value in a loop-control number is always found at the fourth
and fifth decimal places, you need to divide by 100,000 to move it there.
In your trial example: 3 + 100,000 = .OOOQ3.

Line 11 adds the contents of the X- and Y-registers together to form a


complete loop-control number: 0 (implied)+ .039 + .OOOQ3. = 0.039Q3.

Line 12 stores the loop-control number in register 00, and then you're
ready to enter the loop itself, denoted by the LBL 01 at line 13.

Line 14 recalls the loop-control number and line 15 extracts the


Integer Part of the number (in this case, 0) and then displays it for one
or two PSE's depending on the status of flag 00 (lines 16-18).

Finally, line 19 and its I SG 00 increment the integer portion of the loop
control value each time through, then compares this with the frac-
tional portion (first three digits), and decides (correctly) when to skip
the GTO 01, thus ENDing the count and the program.

BUILDING YOUR OWN TOOLS: Programming 259


Indirect Addressing

So much for conditional testing and loop counters. It's time to look at
the most subtle -yet, in many ways, most powerful - way to have your
computer make automatic decisions: What is this stuff - "indirect
addressing?" What's wrong with direct addressing (whatever that is)?

Here's how it works: A bashful young man wants to go on a blind date.


Naturally, he calls a dating service for shy people- and naturally, he
isn't given the address of the shy young lady, because this is much too
personal to divulge to just anyone. Instead, he's told the address ofher
brother's home. There (after meeting with the brother's approval, of
course), he'll be given her actual address. Thus, the dating service tells
him indirectly how to get to his date's home - by giving him the address )
to go to in order to obtain her address. ( )

This is much like a "RCL IN Directly" instruction in your HP-42S. Look,


for example, at the instruction RCL IND 00. The brother's address is )
00 (he "lives" in register 00). So the number stored in register 00 is the )
actual address of the shy young lady herself.
Challenge: Put the value 29.7 into the X-register and the value 3 in
register 01. Then execute the function STO HlD 01.
What happens?

Answer: The set-up is: @J®Qltli)(]ITETIJ Then [sro](Jlla@ID

STO I ND 01 says: "STOre the value currently in the X-


register into the register whose address is indicated by
the contents of register 01."

The HP-42S makes a copy of the 29.7 currently in the X-


register and takes it over to look at register 01 , where it
finds a 3. So it then puts the 29.7 into register 03.

Notice that the IIml functions are in the 8 "Menu."

Challenge 2: Starting with the above results - using indirect ad-


dressing only-store the number 29.7 into register 00.

Solution 2: @) [RCL](JEJll@ID

With a 0 in the X-register, 29.7 is indirectly recalled


from register 03. Then it's stored into the register
whose number is stored in the Y-register. Since 0 is
stored in the Y-register, 29.7 is stored in register 00!

BUILDING YOUR OWN TOOLS: Programming 261


Using Indirect Addressing To Make Decisions

To be sure,just because you understand how indirect addressing works


doesn't tell you what it's good for, does it? How does it help you to make
automatic decisions in your programs?

To begin with, keep in mind that indirect addressing works for other
functions besides STO and RCL. * For example, suppose you have a
program with 26 little subroutines - each with a numeric label and a
RTN statement- one for each letter of the alphabet. Each subroutine
calculates how much space and ink that letter requires on a certain
type of printer. The program might look like this:

01 LBL "LETTERS" •
02 LBL 01 • (
• •
• LBL 25
()
• •
RTN •
LBL 02 • )
• RTN
• LBL 26
• •
)
RTN •
LBL 03 •
• END
• )

*The Operation Index in your Owner's Manual gives a complete listing of those functions that can
indirectly address.

262 An Easy Course In Using The HP-428


Each of those sections will do a different calculation, but for each input
(each letter), there's only one section that applies.
)

Question: What's an easy way to tell the HP-428 to choose the


proper section for a given letter?

Answer: Key in the number of the letter you want (1 for A , 2 forB,
... , 26 for Z) and then press [XEO]c:Jc:Jlilll, which is the
instruction XEQ IND STX.

To calculate the amount ofink needed for the letter K, for


example, you would key in the number 11 (K being the
eleventh letter). Now, when you use XEQ IND STX this
tells the HP-41 to "execute the section whose label is
indicated in theX-register." In theX-register, it finds the
number 11, so it executes the section with LBL 11 .

Also, remember that you can execute ALPHA labels indirectly. That is,
you could have labelled each of these subroutines with its own letter.

In that case, to execute the Kroutine indirectly, you'd need to key a K


into the ALPHA-register, then ASTOr it into a data or stack register and
then use XEQ IND. You must store an ALPHA label name somewhere
other than the ALPHA-register like this, because, unfortunately, there
is no XEQ IND ALPHA function.

BUILDING YOUR OWN TOOLS: Programming 263


One of the best uses of indirect addressing is in combination with loop
counters, so that you accomplish a great deal of work in very few
instructions ....

Challenge: Write a short program (10 steps) to store the integers 0


through 19 in registers 0 through 19, respectively.

Solution: Here's one way to do it:

Kevstrokes Display

.GTO)ffiaPAGMJ 00 { 0-Byte PrgM }


.PGM.FCN)l!BI INDY (ALPHA) 01 LBL "INDY"
rniillJ 02 0.019 )
.PGM.FCN) l!Bl@:ffi 03 LBL 06
(ENTER) 04 ENTER
• CONVERT)(!)llJI 05 IP (
[STo)c:Jlill!Jlc:JDl'J 06 STO IND ST X
@) 07 R-l-
.PGM.FCN) (!) lfillc:J 6l'J 08 ISG ST X
~ 09 GTO 06
(!) 10 . END.

Follow the logic of this program:

At line 02, the number .019 goes into the X-register. This will be the
loop-control number for the ISG loop (as a loop control number, .019 is
also 0.01901) - and it will also act as the index for indirect storage.

264 An Easy Counte In Using The HP-428


Notice that every time the local label at line 03 is reached, the loop-
control number must be in the X-register.

Inside the loop, (line 04) the first thing to do is to send a copy of the loop-
control number into the Y-register. Then line 05 extracts the integer
) portion of the original in the X-register. If the loop control number is
0.019, for example, the IP function puts the numberO in the X-register.

Line 06 is an elegant masterpiece: STO IND ST X says "store a copy


of the value in the X-register into the register indicated by the X-
register." If that number is 0, then 0 is stored into register 00. If it's
19, then 19 is stored into register 19. The very number being stored also
tells the machine where to store it!

Then, to end the loop, line 07 brings down the unmolested copy of the
loop-control number from the Y-register to the X-register, and lines 08-
10 provide the working guts of the loop counting mechanism, incre-
menting each time and skipping the GTO when the integer portion of
the loop-control number finally exceeds 19.

Bonus Question: Ifyou were to use STO IND ST Yatline06 (instead


ofSTO IND ST X), how would this affect the pro-
gram's results?

Bonus Answer: Not at all: Indirect addressing considers only the


positive integer portion, anyway. For example, as
an indirect address, 5 =(-5) =(-5.922) =5.013 .

BUILDING YOUR OWN TOOLS: Programming 265


Reviewing Your Programming Tools

Whew! In this Programming chapter, you've been introduced to a lot


of new things. Here's a summary to give you a break and a review now.
See if you can still recall and grasp these concepts (and if not, here are
the page numbers for quick review):

Programming Basics

• The difference between Run and Program Modes (page 170);


• What the Program Display tells you (page 171);
• Beginning a program in its "own space:" •Gro]c:::E)(page 175);
• Ending a program and the difference between END and • END. (page
178); )
• Editing a program with the~. (!), and~ keys (page 181);
(>
• Positioning the program pointer to insert or delete a line (page 183);
)
• Finding out how much total memory you have left (page 168);
)
• Finding out the memory usage of the current program (page 171);

Programming Structures

)
• Labels: The differences between global and local (page 219)
• Subroutines: How they're "called" and how they RTN (page 226); )

• Loops: When and how to use them (page 220); u


)

266 An Easy Course In Using The HP-428


Communicating With The User

• Keying data in before eXEOuting the program (page 180);


• Using INPUT to prompt for numerical data (page 188);
• Using AON-PROMPT-AOFF to prompt for ALPHA data (page 196);
• Using MVAR and VARMENU to enter data flexibly (page 199);
• Using VIEW to label numerical results (page 192);
• Creating long messages with the f- and LF characters (page 204);
• Using PROMPT, AVIEW and their differences (pages 193 and 250);

Making Decisions

• Programmer decisions: Branching with GTO and XEQ (page 223);

• User decisions: Using the Programmable Menu (page 229);

• Machine decisions: Conditional Branching


• Conditional Tests
• Value comparisons (page 242);
• Flags - User, Control, System: How to set, clear, or test
them (page 246);
• Data Type: Finding the type of data in the X-register
(page 251)
• Loop Counters
• Loop-Control Numbers and how they work (page 252);
• ISG and DSE functions: When and how to use them with
loop-control numbers (page 252);
• Indirect Addressing: For XEOuting subroutines or for using
) with loop counters (page 260).

BUILDING YOUR OWN TOOLS: Programming 267


Prove Your Programming Proficiency

1. Suppose that you're in Program Mode, with the program pointer


positioned at line 08 of a program labelled 11 WHATZIT 11 • Explain
the difference between the following two keystroke sequences:

a. [EXIT](RJS)

2. After a subroutine is eXEOuted and the program pointer encoun-


ters a RTN, where does the program pointer go next?

0
3. Remember the Quadratic Formula from 'way back in algebra ( )
class? Whenever you have an equation of the form ()
ax 2 +bx+ c =0 ()
)

where a, b, and care real numbers, you can calculate x from a, b, )


and c according to the following formula:

-b± Vb 2 -4ac
)
x=
2a

Write a program, QUAD, that solves this Quadratic Formula for )


x, given data inputs a, b, and c.

Use variable menus in your input, and restrict the program to


real-number solutions for x, or else display a message: 11 NO REAL
SOLUTIONS." Do not allow it to yield complex solutions.

268 An Easy Course In Using The HP-428


4. Suppose you wanted to graph the following equation:

4 = y
x2+x-12

Write a program that converts an input (x) into an output (y).

Use flags to prevent the program from stopping because of a zero


denominator -you can't divide by zero (hint: refer to pages 280-
282 of your Owners' Manual for a summary of what each of the
flags do). If your program encounters such a situation, have it
display the message, 11 ASYMPTOTE AT X=(fill in the current X-
value that caused the problem). 11

5. Write a program, ORG, that creates a Programmable Menu con-


taining two items: IEl1IJ and !i!m). When you press IEiiIJ you
should branch to another Programmable Menu containing l:ilm,
!ffi!ID, IKl!!!!l, and mrrnJ. When you press mrn:J, you should branch
to another Programmable Menu containing t!TI3ill In, and !mIB).

Then (although later you may be able to use this nested set ofPro-
grammable Menus to organize your various technical formulas
and programs on your HP-42S), simply program each sub-menu
item to display its full title. That is, pressing rn!9] gives the
message, 11 ALGEBRA 11 ; pressing mirn1 gives the message, 11 DI F-
FERENT I AL EQUATIONS 11 ; pressing l3m gives the message,
11 ELECTRICAL ENGINEERING 11 , etc.

(Hint: Since you're creating one main menu and two sub-menus,
you're really creating something like a single three-page menu.)

BUILDING YOUR OWN TOOLS: Programming 269


Programming Proficiency Proofs

1. Pressing [RIS] always begins running the current program at the


line right after the line where the program pointer is pointing. In
this case, WHATZIT would begin executing from line 09 -proba-
bly crashing or misbehaving since it may have missed out on
some essential program steps.

Using[xEa], on the other hand, resets the program pointer at the


the program's intended starting label, thereby insuring that you
will get "all" of the program. In general, you should use [XEQ) ifyou
want to begin the whole program.
3. The solution below gives just the listing in the display. You're
adept enough with the keyboard now to know how to key in any
of the steps in this program. (Right?)

00 { 148-Byte Pr9M )
01 LBL 11 QUAD 11 1 26 +1-
02 MVAR A 11 11 27 STO 01
03 MVAR 11 811 28 X<>Y
04 MVAR 11 C11 29 +
05 11 INPUT COEFF 11 30 STO 02
06 f- 11 CIENTS 11 2 31 RCL 01
07 CF 21 32 RCL 00 5
08 AVIEW 33 -
09 VARMENU 11 QUAD 11 34 STO 03
10 STOP 35 RCL 11 A11
11 EXITALL 36 2
12 FIX 02 37 x
13 RCL 11 811 38 STO+ 02
14 Xt2 39 STO+ 03
15 4 40 11 X = II

16 RCL 11 A11 3 41 ARCL 02


17 x 42 f- 11 ORL~x = 11 6
18 RCL 11 C11 43 ARCL 03
19 x 44 PROMPT
20 - 45 GTO 11 QUAD 11
21 X<0? 4
46 LBL 09
22 GTO 09 47 11 NO REAL II

23 SQRT 48 f- 11 SOLUTIONSL~
II 7
24 STO 00 5 49 AVIEW
25 RCL 8 11 11 50 .END.

BUILDING YOUR OWN TOOLS: Programming 271


After the beginning label (Section 1), Section 2 sets the the vari-
able menu with menu items for the three coefficients a, b, and c.
It also prompts the user to 11 INPUT COEFFICIENTS 11 (notice that
you must ensure that Flag 21 is clear before you assume that
AV I EW will not halt program execution).

Section 3 then calculates the discriminant of the formula - the


part of the formula under the radical: (IJZ - 4ac), preparing to
determine if real solutions exist. If the discriminant is negative,
then the solutions are complex (the square root of a negative
number is imaginary). Otherwise, the solutions are both real.

Section 4 tests the discriminant. If it's negative, the program


jumps to LBL 09 (Section 7) to give an appropriate error message.

(
If the discriminant is positive (and only then), the program con-
tinues on to Section 5, which finishes calculating the two solu-
tions. The first solution is STOred in register 02, the second in
register 03. )

Section 6 gathers together an answer display in the ALPHA-


register. The program stops at the PROMPT and the solutions
are displayed. To repeat the program, you must press [RIS) once
more and the GTO 11 QUAD 11 takes you back to the beginning once
again, isolating this display from the LBL 09 one that follows.

Section 7 displays the 11 NO REAL SOLUTIONS 11 message. The LF


and two spaces are included to make a cleaner two-line display
(but are cosmetic and completely optional). Notice, however, that
from this output, too, a simple [RIS) will restart the program.

272 An Easy Coune In UBing The HP-428


4. Here's one possible solution making use of flag 25, one of the
control flags:

00 { 63-Byte PrgM }l 11 FC? 25


4
01 LBL "EQ" 12 GTO 03
02 SF 25 2 13 RCL X 11 11

03 4 14 VIEW "Y" 5
04 INPUT X 11 11
15 STOP
05 Xt2 16 GTO EQ
11 11

06 RCL+ 11x11
3 17 LBL 03
07 12 18 "ASYMPTOTE
08 - 19 ARCL X 11 11

6
09 20 CF 21
10 STO 11y11
21 AVIEW
22 .END.

After the beginning label (Section 1 ), Section 2 sets flag 25, which
tells the calculator to ignore the first error it comes to. That is,
if it encounters one, it ignores it but also clears flag 25.

Then section 3 takes 11 X11 as an input, calculates and stores 11 Y11 •

Next, section 4 tests flag 25. Ifthere has been an (ignored) error
- such as division by zero - during the calculations in Section 3,
flag 25 will have been cleared by this point, in which case the test
at line 11 will send the program jumping to LBL 03 (Section 6)
to display the asymptote message (mind the flag 21 with AV I EW !).

Thus, Section 5 displays 11 Y11 if it is calculable and Section 6 (at


LBL 03) displays what it means if 11Y 11 is not calculable.

BUILDING YOUR OWN TOOLS: Programming 273


5. Here's one very straight-forward solution:

00 ( 262-Byte Pr9M } 26 LBL C


01 LBL 11 0RG 11 27 CLMENU
02 LBL A 28 11 CHEMI 11

03 CLMENU 29 KEY 1 XEQ 11


04 11 MATH 11 30 11 PHYSI 11

05 KEY 1 GTO B 31 KEY 2 XEQ 12


06 11 SCIENCE 11 32 11 EENGI 11
3
07 KEY 2 GTO C 1 33 KEY 3 XEQ 13
08 KEY 9 GTO 99 34 KEY 9 GTO A
09 MENU 35 MENU
10 STOP 36 STOP
11 GTO A 37 GTO C
12 LBL B 38 LBL 01
13 CLMENU 39 11 ALGEBRA 11

14 11 ALGE 11 40 GTO 14
15 KEY 1 XEQ 01 41 LBL 02
16 11 GEOM 11 42 11 GEOMETRY 11

17 KEY 2 XEQ 02 43 GTO 14


18 11 CALCU 11 44 LBL 03
19 KEY 3 XEQ 03 45 11 CALCULUS 11

20 11 DIFEQ 11 2 46 GTO 14 4
21 KEY 4 XEQ 04 47 LBL 04
22 KEY 9 GTO A 48 "DIFFERENTIAL II

23 MENU 49 l- 11 EQUATIONS 11
24 STOP 50 GTO 14
25 GTO B 51 LBL 11
52 11 CHEMISTRY 11

274 An Easy Course In Using The HP-428


53 GTO 14 61 LBL 14
54 LBL 12 62 AVIEW 5
55 "PHYSICS" 63 RTN
56 GTO 14 64 LBL 99
4
57 LBL 13 65 CLMENU 6
58"ELECTRICAL II 66 EXITALL
59 !-"ENGINEERING" 67 .END.
60 GTO 14

Section 1 (The beginning global LBL 11 0RG 11 and LBL A) sets up


the first (or main) menu, containing the two choices, Gl'iiiI) and
mill). As you've done before (pages 229-231), you set up a Pro-
grammable Menu in three stages: the menu key assignments
(lines 04-08), the MENU statement (line 09), and the trapping
statements Oines 10-11 ).

Section 2 <LBL 8) sets up the first sub-menu, the one for GJ'E).
Notice that in line22, the[EXIT)key <KEY 9)takes you back to the
main menu. This is logical: [EXIT~ng a sub-menu should put you
back at the main menu. And (EXIT~ng the main menu should put
at the Stack Display - exactly what LBL 99 does in Section 6!
Then Section 3 <LBL C) sets up the second sub-menu in a pattern
identical to that for the first sub-menu.

Section 4 contains all of the individual "action" labels, each con-


taining only the output ALPHA-strings for each course name and
then a GTO 14, which takes you to Section 5, where the tiny
output subroutine lives (mind the flag 21 with AVIEW!).

Finally, Section 6 "tidies up" before EXITing.

BUILDING YOUR OWN TOOLS: Programming 275


Programming BIG: A Case Study

Up to this point in the Course, you've had many small example


programs to write, each one illustrating a new strategy, function or
technique. However, none of these programs approached the size and
complexity of a really big program - one that consumes a good-sized
chunk of your total possible available memory.

So, to close off this Programming chapter, what you have here is an
example of one of these behemoths. The idea is for you to:

• see an example of how to organize and structure complex programs;

• learn how to store larger amounts of data very compactly - an


important necessity for large programs which use lots of memory;
But before you get started on this new adventure, you ought to clean
out your workshop a bit. You still have some older, not-so-eternally-
useful sample programs and variables lying around, cluttering up the
place and occupying valuable workspace.

Do This: Clear out the programs, FIRST, CYL, NCYL, HOWDY,


GREET, SPHERE, and DENSITY from your storage
area. Then clear out the variables that these programs
used: H, R, L, W, M, VOLUME, AREA, DEN and HI.

Solution: Press .-cLEAR) twice, and choose either mil or ID.I.


Now search through the resulting menu, using the~
and [!)keys until the desired programs or variables are
visible, then press the corresponding menu keys to clear
them. Repeat this procedure until you've cleared out all
of the programs and variables listed above.

When you've finished press •CATALOGHlm and hold


down the mm key to see how much memory you have
left. Before proceeding farther, you should have at least
3500 Bytes available (if you still need more room, clear
out the matrix variables, MAIT, TAM, and MAT).

OK, now that you have some extra elbow room ...

BUILDING YOUR OWN TOOLS: Programming 277


The Challenge

("Good morning, Mr./Ms. Phelps .... ")

Your mission, should you choose to accept it, is to modify the program
MUSIC (the one with 00-RE-Ml)sothatyoucanrecord, name, save and
play back any tune that you play on the "keyboard." Of course, the
program should also let you simply "practice" on the keyboard, without
recording at all - just as it does now.

The program should be flexible and convenient. It should offer you


choices, prompt you with instructions, and monitor your inputs with
error-trapping routines to avoid "crashes."

In recording a song, every note you press will be taken as one "beat"
(one count). In 4/4 time for example, each note you press would be
taken as a quarter note. To record a half note, you must simply press
the same note twice in a row, etc. Of course, you'll need to add a "no-
tone" to your keyboard so that you can include "rests" in your songs.
)
Then, when your recorded songs are played back, each beat will be
played in steady, tight succession (no matter how haltingly you have
"recorded" it), so that two or more identical notes played in succession
will sound as much as possible like single, longer notes. Admittedly,
this won't make for very sophisticated rhythms or dynamics, but the
HP-428 isn't exactly capable of symphonic music anyway, since its
TON E's are all the same length and you're limited to one octave of a )
major scale.

("Good luck... . .. this page will self-destruct in 5 decades .... ")

278 An Easy Course In Using The HP-428


Stage One: Planning

This is the most important stage of all. Without doing the work here,
you run the risk of wasting lots of your valuable time doing things that
you don't need, or doing them in ways that are useless later on in the
program. This is one of the new aspects oflarge programs: it is difficult
to envision them all at one glance.

The most important part of planning is what you don't do: You don't
start out by writing out actual program steps or keying them into your
machine-there'll be time enough for that later on. The first step, then,
is to list the main tasks of your program and to consider your basic
strategies. For example, the new MUSIC program will:

• Allow you to practice on the keyboard without recording-just as the


current MUSIC program will. All right-visualize this as one major
routine within the program, and call it the "PRACTICE" routine.

• Allow you to record as you play the notes - for later playback. Call
this routine "RECORD."

• Allow you to name and store a recorded song. Call this routine
"SAVE."

• Allow you to recall a stored song and prepare it for playing. Call this
routine "LOAD."

• Allow you to play back the LOADed song. Call this routine "PLAY."

• Allow you to quit the program. Call this routine "EXIT."

BUILDING YOUR OWN TOOLS: Programming 279


Now, from the description of the challenge, you know that a "song" will
consist of an ordered collection of tones - one for each beat- right? And
you're going to need some kind of tight, efficient playback loop in order
to play these beats to make the song sound as realistic as possible. But
there's no way to know how many beats a song will have. And anyway,
how are you going to quickly "read" and "play" TON Es in a tight loop?

Well, from your loop practice programs (pages 252-259), you know you
can "loop" quite efficiently with the numbered storage registers (whose
numbers can be increased as necessary), and an ISG loop and indirect
addressing. In fact, you can even use indirect addressing to play the
TONEs themselves (e.g. TONE IND 00 will sound the tone whose
number is now sitting in the register 00)! ... OK. ..

First Major Design Decision: To play back a recorded song, its ( )


"notes" will need to be located in the numbered storage registers.
( )

)
Hmmm ... then how are you going to store recorded songs? You might
well have several of them. Are you going to put them all into numbered
storage registers? You could do this, but the REGS matrix would get )
pretty big. And how and where are you going to remember the name )
of each song? Looks like you want to store each song into its own
)
variable, with its own name, right? And obviously, the type of variable
)
to hold an ordered collection of data is a matrix- similar to the REGS
matrix: the first beat of the song is the first element, etc .... All right .... )

)
Second Major Design Decision: Each song will be stored as a )
collection of beats within a unique, named matrix variable.

Hmm ... should you rethink your First Major Design Decision? Maybe

280 An Easy Course In Using The HP-428


you can play back each song with a program loop that quickly reads and
"plays" the beats directly from a song's matrix- instead of first having
to LOAD those beats into the numbered REGS matrix. Well, you could
do that, but it might not be as fast a playback loop since you'd need
more commands to sound the TONEs (you can't TONE IND ij to an
element ij in a matrix). Besides, it's not that inconvenient to need to
LOAD a song, since you can play only one at a time anyway.

OK-individual storage. But won't that use a lot of memory? Matrices


tend to do that, you know ... unless .. .you compact the data. For ex-
ample, a collection of 12 beats, initially in registers 01 through 12, can
be saved as either a 12 x 1 matrix ofreals (one element for each beat),
orasa2x1matrixofALPHAstrings,oneelementforeach6beats. Real
numbers and ALPHA strings use the same amount of memory, so a 2
x 1 matrix of strings uses far less memory than a 12x1 matrixofreals!

1 Ro, 1
1 Ro2 1
5 Ro3 5
5 Ro4 5
6
6 Ros can become or [ "115566" ]
6 "5 .4433"
6 R06 5
5 RO?
Roa 4
4 Roo 4
4 R,o 3
3 R,, 3
3 R,2

Third Major Design Decision: Each song's beats will be compacted


into 6-character ALPHA strings within that song's named matrix.

BUILDING YOUR OWN TOOLS: Programming 281


One more consideration: The problem didn't mention anything about
editing an existing song. What if you want to correct a mis-recording
or lengthen a tune, etc.? Why didn't the challenge include this?

Probably the sophistication of the program and the resulting music


doesn't warrant it. Besides, it's probably easier to re-record a song
entirely than to "go in and fix" some wrong notes; how do you quickly
tell the machine to insert, delete or change individual notes in an
already-recorded spng? Sure -you could program this, but it would be
a lot more code and no more convenient than simply making a fresh
recording of the whole song.

So if you can't edit a song, then notice that once a song is named and
saved, the only real reason for LOA Ding it is to PLAY it (sure -you can
rename it, but you can also do that - and clear it, too - outside the
program, with standard HP-42S commands, since each song is just an
()
ordinary matrix variable). You can't use the program to do much else
with it. As a user, you'd never need to select a routine called LOAD sepa- )
rately from the routine called PLAY. So although LOAD is a separate )
routine in the program, this fact can be invisible to you, the user. )
)
Fourth Major Design Decision: The user's basic choices of activi-
)
ties within the program will be:
)
PRACTICE RECORD SAVE PLAY EXIT )

0
Clearly, you're talking about some kind of menu here - the "Main"
)
menu of choices for the user. After all, for convenience and flexibility
- both for variables and program selections - menus are hard to beat,
aren't they? And the existing MUSIC program uses them already! )
)
282 An Easy Course In Using The HP-428 )
.)

As you can see, the whole point of writing a program is to make it useful
and convenient to the user, so in designing it, try to visualize it from
the user's point of view: What will you see in the display at each point
in the program? What information will you need to input- and how
will you do this? In what order would you want to do things? And what
mistakes might you make? ... Concentrate now, and visualize ....

You know the first thing you'll encounter is that Main menu. Then
what? What could you do next? Anything except SAVE, right? There's
no recorded song to SAVE yet. You could PRACTICE for hours without
having anything to SAVE. Only after you've RECORDed something
should you be able to SAVE it, right? And you'll need to be prompted
to input a name to store it under (mental notes).

And you shouldn't be allowed to unintentionally destroy any current


unSAVEd recording - by RECORDing or PLAYing (which means
LOADing) another-until you've either SAVEd that current one or ac-
knowledged to the program to forget it and RECORD over it, right?
(another mental note).

However, you should be allowed to PLAY the RECORDing you've just


made before you decide to SAVE it. There's no sense in having to name
and store a song that might not even be what you want, just so you can
hear it to find out. So when you select PLAY, the program must offer
) to PLAY the current (and as yet unnamed) song or to SAVE it in order
to LOAD and PLAY an already-named song (yet another mental note).

This visualization gets tricky at times, doesn't it?

) BUILDING YOUR OWN TOOLS: Programming 283


Stage Two: Writing The Program
Section by Section
On the basis of your planning, Major Design Decisions and mental
notes, you've now conceived of a program that can be broken into
sections so that the actual programming is more manageable:

Section 0: Initializations. To begin, you must establish the proper


settings for any necessary flags, counters, variables, etc.

s~~tis;m 1: The Main Menu. This menu will offer the main choice of
activities (PRACTICE, RECORD, SAVE, PLAY, or EXIT).
( )

(
s~~ti2n 2: The PRACTICE Menu. This will resemble your previous
MUSIC program -just a Programmable Menu of the
notes of the scale, sounded as the user selects them.

)
s~~ti2n a: The RECORD Menu. This will "look and feel" just like )
the PRACTICE Menu, buteachbeatwillberecorded into
)
a numbered storage register as the keyboard sounds it.
)

s~~ii2n ~: The musical subroutines. Here are the actual TONE


commands in their respective subroutines - just as you )
used them in your first MUSIC program (but with an
)
added subroutine for a "Rest").
)

284 An Easy Course In Using The HP-428


Section 5: The SAVE routine. This routine will transfer a song (the
collection of beats) from the numbered registers, where
it was originally stored upon recording, into a matrix of
ALPHA strings - named according to the user's prefer-
ence - in compact form, with six beats per string.

Section 6: The LOAD routine. This routine will be the opposite of


the SAVE routine, "unpacking" a stored, named song-
matrix into the numbered registers, ready for PLAYing.

Section 7: The PLAYroutine. This routine will actually run through


the numbered storage registers, "read" and sound the
notes (beats) of the currently loaded song.

Section 8: Utility subroutines. In every complex program, you're


likely to have certain functions or sections of code that
you'll want to use more than once. In that case, it's more
efficient to turn each such section into a subroutine with
a LBL and RTN statement so that you can easily call it
whenever you need it.

Section 9: The EXIT routine. Although you may use this routine
only once during a program, it's important to identify
and treat it separately anyway. Here you "clean up," exit
menus, restore inconvenient system parameters, etc.

BUILDING YOUR OWN TOOLS: Programming 285


On these next few pages, you'll see listings and explanations for each
Section- often breaking a Section down, line by line. Some functions
and techniques here will be new. If you want to read more about these
and understand more fully why they are appropriate choices here, you
may want your HP-428 Owner's Manual handy also - opened to the
Operation Index (somewhere around page 310).

Section 0: Initializations

00 { 697-Byte PrgM )
01 LBL 11 MUSIC 11
02 FIX 00
03 CF 00
04 CF 01
05 CF 21 ()
06 SF 26 ( )
07 CF 27
08 CF 29
9 II II
)
10 ASTO NAME 11 11

No matter how good a programmer you are, it's not usually possible to )
foresee all the initialization steps you're going to need. So although
)
these steps must come at the beginning of program execution, often
you'll start this list with "whatever you can think of," then return to
amend it later, whenever you think of something else.

What you see here, therefore, didn't just ''jump out" as "immediately
obvious;" these are the final results of such an amendment process.
I
The point is, you should always have an opening section defined for just
such a purpose, so that it's easy to find and amend as you need to.

286 An Easy Course In Using The HP-428


Now, what's going on here in these initialization steps?

First, notice that you have absolutely no need for any kind ofnumerical
display in this program; everything of interest to the user will appear
as either a message, a menu item, or a sound. But you do need to format
numbers as single numerals (by ARCLling) - for your compacting
process when you SAVE a song - without any extra decimal places or
even a decimal point. So you FIX 00 and CF 29 (flag 29 controls the
presences of the decimal point and digit separators - the commas at the
thousands, millions, etc.).

Next, notice that you can use the same "keyboard" routine both for RE-
CORDing and PRACTICing-ifyou tell the machine which one you're
doing. You'll use flag 00 to indicate this: When this flag is clear, you're
just PRACTICing; when it's set, you're RECOR Ding. Start in "PRAC-
TICE mode" - with flag 00 clear.

Similarly, you'll notice that you need some status indicator to help the
machine remember when there's an unSAVEd but RECORDedsong(so
it doesn't let you inadvertently RECORD over something you forgot to
SAVE). That'll be flag 01, which will be set only when there is such an
unSAVEd song. So start with flag 01 clear.

Lines 05 - 07 ensure that your sound is turned on and any CUSTOM


menu is turned off, and that AVIEWs don't halt program execution.

Finally, since you can have only one song currently loaded into the
)
numbered registers, you'll probably need just one variable to remem-
ber that song's name: 11 NAME 11 • And you'd better put something in there
to indicate that there's no song yet: 11 11 (a blank name).

BmLDING YOUR OWN TOOLS: Programming 287

)
Section 1; The Main menu

11 LBL A 20 KEY 3 GTO E


12 II CURRENT SONG: II II 21 SAVE
11 11

13 ARCL 11 NAME 11 22 KEY 4 XEQ H


14 f-111111 23 PLAY
11 11

15 AVIEW 24 KEY 6 XEQ I


16 CLMENU 25 KEY 9 GTO 99
17 11 PRAC 11 26 MENU
18 KEY 1 GTO B 27 STOP
19 REC
11 11 28 GTO A

Section 2; The PRACTICE Menu

29 LBL B 50 LBL D
30 CF 00 51 CLMENU
31 LBL C 52 11 TI 11 ()
32 DO.,l. 11
11 53 KEY 1 XEQ 07 ()
33 KEY 1 XEQ 01 54 11 DOt 11
34 RE
11 11 55 KEY 2 XEQ 08 )
35 KEY 2 XEQ 02 56 11 REST 11
57 KEY 6 XEQ 09 ()
36 MI
11 11

37 KEY 3 XEQ 03 58 KEY 7 GTO C )


38 11 FA 11 59 KEY 8 GTO C
39 KEY 4 XEQ 04 60 KEY 9 GTO A )
40 S0
11 11 61 MENU )
41 KEY 5 XEQ 05 62 STOP
42 LA
11 11 63 GTO D )
43 KEY 6 XEQ 06 )
44 KEY 7 GTO D
45 KEY 8 GTO D
46 KEY 9 GTO A
47 MENU
48 STOP )
49 GTO C

288 An Easy Course In Using The HP-428


Sections 1 and 2 should look familiar to you in some form or other:

Section 1 (at LBL A) is the Main Menu, which you build and display
just like you've seen other Programmable Menus built and displayed
(recall, for example, pages 229-232): Each choice has a KEY associated
with it (though not allKEYs are used). Notice that it was logical to put
the EXIT routine (labelled 99) on KEY 9 which is the [EXIT] key. As for
the choices to GTO some labels (lines 18 and 20) but XEQ others (lines
22 and 24 ), these will be more self-explanatory as you go on. In pro-
gramming for yourself, you might well begin by using all GTO's and
then deciding later that XEQ's make more sense. That's fine.

Notice one new thing: The name of the currently recorded song will be
displayed above the menu Oines 12 -15 ), helping the user to remember.
)
Of course, when the program starts, that name will be all blanks - as
you've just arranged in the initialization section.

Section 2 (atLBL B) is the basic "keyboard menu," where the program


pointer will go if the user chooses theum selection <KEY 1) from the
Main menu. Here's another Programmable Menu -two pages, in fact
- similar to that in the first MUSIC program, with three differences:

• When you want to [EXIT) from this menu <KEY 9, line 60 ), you won't
exit the program entirely, because this is not the "last layer of the
program." Instead, you'll be sent back to the Main menu, at LBL A.

• There'sanextramenuitem-a 11 REST 11 -onthemenu'ssecondpage.

• Lines 30 - 31 : What are they all about?

BUILDING YOUR OWN TOOLS: Programming 289


l

To understand those two lines, it's best to consider Section 3, the REC-
ORD menu at the same time (shown opposite here)....

Remember that flag 00 is what you're using to indicate whether the


basic keyboard menu is being used for PRACTICE or to RECORD.
Whenever you go to that menu via LBL B, it will be for PRACTICE, and
so the CF 00 should be encountered, right?

But notice that (among other things) the RECORD menu (at LBL E)
will set flag 00 (at line 69), and then send the pointer to the keyboard
menu via LBL C, thereby missing step 38. By providing two different
entry points to the same routine, you control which circumstances will
encounter all the steps of that routine rather than just a portion.

Then, once within the keyboard menu, since flagOO might beeither set
)
or clear (depending on how you got to this menu), you don't want to
mess with it anymore. So in restarting the menu loop in cases ofmis- )
strokes or changing pages (e.g. at lines49, 58, and 59), you don't send )
the pointer back to LBL B, but rather to LBL C, thus preserving the
current status of flag 00.
)

So how does flag 00 actually start the RECORD process? It's nowhere
in this menu is it? No - actually it's in the "sound" subroutines C01 -
09) called by this menu. In those routines, if flag 00 is set, the beats )
will be stored as well as played. You'll see those routines in a moment.

)
290 An Easy Course In Using The HP-428 )
Section 3; The RECORD Menu

64 LBL E 70 SF 01
65 FS? 01 71 NONAME
11 11

66 XEQ 80 72 ASTO NAME11 11

67 FS? 01 78 1. 999
68 GTO A 74 STO 00
69 SF 00 75 GTO C

Now notice what else this RECORD Menu does: First, it tests whether
an unSAVEd song is currently stored in the numbered registers, by
testing flag 01 (this is what you've defined flag 01 to mean, right?): If
flag 01 is set, the user shouldn't be allowed to RECORD over the
unSAVEd song without a warning. So you XEQ 80 - an error message
to let the user acknowledge the danger and decide if the current song
is worth SAVing. Depending upon his/her decision, that error routine
will then adjust flag 01 and RTN to line 67, which then tests it again. If
it's still set, this means the user did not want to forget it without
SAVing it, so back you go to the Main menu CLBL A).

Thus, a user can RECORD a new song only if flag 01 is clear by step 67.
If so, the program then sets flags 00 and 01, to signal, respectively, that
this is now a new RECORDingsessionand that as of now, there is a new
and therefore unSAVEd song in memory. It also gives this song the
name 11 NONAME 11 to remind the user via the message at the Main menu.

Finally, before entering the keyboard routine, lines 78 -74 start an ISG
loop counter in register 00, to help store and count each beat in
successive numbered registers (up to 999 beats in any song).

BUILDING YOUR OWN TOOLS: Programming 291

)
Section 4; The keyboard's musical subroutines (labels 01-09)

76 LBL 01 85 LBL 04 94 LBL 07


77 1 86 4 95 7
78 GTO F 87 GTO F 96 GTO F
79 LBL 02 88 LBL 05 97 LBL 08
80 2 89 5 98 8
81 GTO F 90 GTO F 99 GTO F
82 LBL 03 91 LBL 06 100 LBL 09
83 3 92 6 101 II II
1

84 GTO F 93 GTO F 102 ASTO ST X


103 SF 25
104 LBL F 112 RCL 11 REGS 11 121 LBL G
105 TONE IND ST X 113 DIM? 122 ISG 00
106 FC? 00 114 XOY 123 RTN
107 RTN 115 1 124 11 SONG LENGTH II

108 SF 25 116 + 125 f- 11 LI MIT 11


109 STO IND 00 126 TONE 0 ) I
117 X<>Y
110 FS?C 25 118 DIM 11 REGS 11 127 AVIEW ( ) I
111 GTO G 119 RCL ST Z 128 PSE )
120 STO IND 00 129 RTN
)

Section 4 is the collection of musical subroutines themselves. You've


seen much of this code before, too: Each of the individual subroutines
merely loads its appropriate TONE number (a "Rest" is a 11 • 11 charac-
ter) into the X-register, then sends the program jumping down to LBL
F, where the TONE is sounded by indirectly addressing the X-register at
line 105.

Notice how the "Rest" routine CLBL 09) sets the error-ignore /fog (25)
so that if the program tries to TONE a 11 • 11 , it doesn't crash.
)

292 An Easy Course In Using The HP-428


That's what happens whether you're PRACTICing or RECORDing.

) But after that, if you're just PRACTICing, then, since flag 00 is clear,
the test at line 106 will RTN the pointer back to the keyboard menu.
Otherwise, it stays around to store that beat's TONE value into the
register indicated by the counter in register 00.

Pretty slick, eh?

Notice the two error traps here:

The first trap (at line 110 ), again uses flag 25, the error-ignore flag. As
you can see, this flag is useful in that it not only lets you ignore the first
error, but it then clears itself to tell you that it has indeed encountered
an error and that your one "mulligan" has therefore been "used up."

So you as a programmer know that ifflag 25 has been cleared after the
attempt to STO I ND 00, this indicates that you've run out of registers
in the REGS matrix, in which case, before being sent on to LBL G, you
re-DIMension REGS with one more element (lines 112 -118) and then
carry out a successful beat-indirect-storage Oines 119 -120).

Finally, if you've recorded a song with 1000 beats or more, you'll fail the
ISG test at LBL Gand thus be sent on to the error message below, which
wanrs the user before RTNing back to the keyboard menu.

Notice also that at the end of the RECOR Ding session, the counter in
register 00 will be left "pointing to" (i.e. its integer value will be the
number oD the register following the register containing the last
stored beat (in preparation for the next beat - which never came).

BffiLDING YOUR OWN TOOLS: Programming 293


Section 5; The SAVE routine

130 LBL H 154 XEQ 81


131 SAVE SONG AS •• ?
11 11
155 CLA
132 AON 156 1. 006
133 PROMPT 157 ENTER
134 AOFF 158 LBL 10
135 ASTO NAME11 11
159 ARCL IND 00
136 RCL 00 160 SF 02
137 IP 161 ISG ST Y
138 STO 00 162 GTO 11
139 1 163 ASTO ST X
140 - 164 STOEL
141 6 165 CF 02
142 .;. 166 I+
143 1. 4 167 CLA
144 + 168 1.006 0
145 RND 169 ENTER ()
146 1 170 LBL 11
147 DIM IND NAME ()
11 11
171 ISG 00
148 INDEX IND NAME 11 11
172 GTO 10 )
149 1 173 ASTO ST X
150 STOIJ 174 FS? 02 )
151 RCL 00 175 STOEL )
152 STOEL 176 CF 01
153 I+ 177 RTN )
)
)
The overall objective here is to transfer the notes of the current song
)
from the numbered registers (where they were RECORDed, one beat
per register) to a named matrix - in compacted form.

There are a lot of details and little programming maneuvers you may
not have seen before, so look and think carefully.... )

294 An Easy Course In Using The HP-428


The first thing to do is to prompt the user for the name under which this
current song should be SAVEd. This name is then stored in the
variable, 11 NAME 11 • That's what lines 131 -135 are all about.

)
Next job: Create and DIMension a new matrix variable by that name
(lines 136 - 147). This matrix, which will contain ALPHA strings, will
be n x 1, and you need to figure out what n must be - i.e. how many
elements this matrix must have.

Hmm ... you'll need one string for every six beats in the song, right? But
you can't just divide the number of beats by six; unless that division
just happens to come out even (no remainder), you'll need to round up.
In such a case, the last element in the matrix will contain a string that's
not fully six characters long, right? No big deal- but you'll need to do
this rounding and do it right.

And another thing: After you've saved this song (and "erased" it),
suppose you want to PLAY it later. You'll need to somehow load it back
into the numbered registers, set up a loop counter, then run through
that loop, read each beat and sound it, right? (All that will be in the
LOAD and PLAY routines.) But how are you going to know then exactly
how many beats were in that song? Sure -you can guess within six,
simply by looking at the dimension of the matrix it's stored in- but you
need to know exactly to set up your PLAY loop properly.

Well, you could go through an ugly process, where you take the last
element in the matrix and break down its string to figure out how long
it is and therefore how many extra beats will be in the song. Or (much
more simply), you could just designate the first element in the matrix
as a special element- the number that tells you the song's length ....
)
BUILDING YOUR OWN TOOLS: Programming 295
This is what you're going to do: As you observed on the bottom of page
293, when the recording is finished, register 00 will contain a pezfectly
good indicator of how long the song is: that register's integer portion
stopped counting just beyond the end of the song! Why not just store
that value as the first element in your song's matrix?

OK, then this means you'll need one extra element in the matrix for
this inform.a ti on -this song-length number. Thus, you'll need to divide
that song-length by six, round any remainder up and then add one.

How do you do this? See lines 136 - 14 7: You get the song length from
register 00, take its Integer Portion (put this back into register 00 for
a moment -you'll see why soon), then subtract one (because the count
went one past the last register), then divide by 6. Now, an easy trick 0
for rounding up is to add .4 and then use RND, which will round to the
0
nearest integer (either up or down). You don't want to add .5 because
this could cause a rounding up with no remainder in the division- not 0
good. But since you need to round up and add one,just do it all at once: )
add 1.4 and RND .... Voila! The proper number of rows for the matrix! )

Now put in a 1 for the single column in the matrix and DI Mension it with
the name indicated in the variable "NAME".
)

OK - your matrix variable is properly sized and named. Next, you )


must store into its first element the song-length value you've kept in )
register 00. To store elements into a matrix variable, you must first
make that matrix the "current one" by INDEXingit-whichyou can do
indirectly (i.e. without knowing the matrix's real name) via the value
contained in the variable "NAME". An INDEXed matrix will stay
INDEXed until you edit or INDEX another matrix or use EXITALL.

296 An Easy Course In Using The HP-428

)
And once a matrix is INDEXed, you can do a great number of manipu-
lations to it, via a pair of index pointers - a row pointer and a column
pointer. You position these pointers with the STO I J command and with
the values in the Y- and X- registers ( 1 and 1 here)which represent the
desired row and column pointer positions, respectively. So now you're
positioned at the first row in the first (only) column, ready to store an
element value, which you do by recalling register 00 and using STOEL.

Now you're ready to do a loop with the actual beat tone values. First,
you move the matrix row pointer to the next row, using I+. Then you
transform the value in register 00 into an I SG counter: "count from one
to one-less-than-this-value (this transformation is done by routine 81 ).

Now, the challenge here is actually to construct a loop within a loop:


You need to build a six-character string from each six beats, then store
this string into the matrix, so the inner loop will be this string-building
loop, which must complete every six times through. Its ISG counter
(starting at 1.006) will "live" in the Y-register (the X-register is a "way-
station" for the strings being transferred to the matrix, since you can't
ASTOEL -only STOEL). The outer, "overall" loop is controlled by the I SG
counter in register 00, which is the length of the song itself; when this
loop is finished, the whole SAVE routine is finished, at which point, you
clear flag 01 to indicate that the current song is now safely SAVEd.

You're pretty good with loops by now. See ifyou can follow a "hypotheti-
cal song" with, say, 16 beats, through this double loop ... .Notice the tem-
porary use of flag 02 to signal whether the inner loop has just then
completed and successfully stored a full string (in which case flag 02
will be clear), or whether a final storage of a partial string is necessary
upon exiting the outer loop (in which case flag 02 will still be set).

BCHLDING YOUR OWN TOOLS: Programming 297

)
J

Section 6; The LOAD routine

178 LBL I 199 11 • II

179 "PLAY WHAT SONG?" 200 ASTO 11 TEMP 11


180 CF 23 201 CLA
181 AON 202 I+
182 PROMPT 203 RCLEL
183 ROFF 204 ARCL ST X
184 ASTO 11 TEMP 11 205 LBL 12
185 FC? 23 206 ATOX
186 GTO J 207 X<t0?
187 FS? 01 208 GTO 13
188 XEQ 80 209 CLA
189 FS? 01 210 I+
190 RTN 211 RCLEL
191 RCL 11 TEMP 11 212 ARCL ST X
192 STO 11 NAME 11 213 ATOX
193 INDEX IND 11 NAME 11 214 LBL 13 ()
194 1 215 48
195 ENTER 216 -
196 STOIJ 217 X<0?
197 RCLEL 218 RCL 11 TEMP 11
198 XEQ 81 219 STD IND 00 )
220 ISG 00 )
221 GTO 12
)
The idea behind Section 6 ("LOAD") is to "unpack" a previously SAVEd
)
song into the numbered registers, in preparation for PLAYing. Re-
member that this LOAD routine is the "invisible" first part of the PLAY )
routine, as you decided back on page 282.

With PLAY, as with SAVE, you must begin by prompting for the song's
)
name (lines 179 -183 ). But notice that you'll allow the user to indicate
the current song simply by pressing (RIS) without keying in any name
(a very useful and common technique). You accomplish this with flag )

298 An Easy Course In Using The HP-428

)
23, which is set whenever the HP-428 experiences ALPHA input.

) If the user does mean to PLAY the currently recorded song, so be it: off
you go to the actual PLAY routine at LBL J. If it's a different song to
be played, you'd better repeat the kind of error trap (routine 80) you
used in the RECORD routine - to prevent the user from accidentally
erasing (LOADing right over) an unSAVEd song that was meant to be
"a keeper." As you know, the status of flag 01 after this routine will tell
you of the user's intentions, so you test it again (line 189) and either
abort the mission by RTNing to the Main menu (to let the user do a
SAVE) or forget the current song and go on to LOAD and PLAY a new
one (whose name has been saved in the variable 11 TEMP 11 ,just in case).

Assuming you do go on, the rest of the LOAD routine is quite straight-
forward, now that you've been through the logic of a SAVE routine: You
INDEX the intended matrix, position its pointers at the first element,
then recall this and use it to build an I SG counter for register 00.

Then it's a loop to recall successive elements out of the matrix, into the
ALPHA-register, then use a function called ATOX to remove the leftmost
character from the ALPHA register and send its character value (the
characters 11 111 - 11 911 have character values 49 - 58; a 11 • 11 has a character
value of 46) to the X-register.* There these values are converted by
subtracting 48. A negative value here indicates a 11 • 11 , so you substi-
tute the character itself, which has been stored in 11 TEMP 11 •

Notice the test at line 207 to check whether the ATOX failed due to an
empty ALPHA-register (i.e. that string has been exhausted). Ifso, lines
)
209 to 213 refill the ALPHA-register and then do a successful ATOX.
"These character values are found in the table on pages 288·290 of your Owner's Manual.

BUILDING YOUR OWN TOOLS: Programming 299

)
I

Section 7: The PLAY Subroutine

222 LBL J 225 LBL 14


228 RCL 00 226 SF 25
224 XEQ 81 227 RCL IND 00
228 TONE IND ST X
229 ISG 00
280 GTO 14
281 RTN

Here, finally, at Section 7, is the tiny (tinny?) heart of the "record


player." You'll notice that there was no final RTN at the end of the LOAD
subroutine, since right after you LOAD a fresh song into the numbered
registers, you want to go ahead and PLAY it.

And what is this PLAY routine?


0
Well, first, you must make an ISG counter out of the song-length value ()
in register 00 (remember that it was this value that was stored, as is, )
into the first element of the song's matrix). To do this, of course, you )
use that subroutine 81, as you've done before.

Then it's nothing more than a simple ISG loop, starting at LBL 14,
where you recall the beat-value in each successive register and TONE )
that value through indirect addressing. Notice that you must also set u
flag 25 each time through the loop, just in case you encounter a "Rest"
value, which can't be TONEd, of course.
)
)
)

300 An Easy Course In Using The HP-428 )


)
Section 8: Utility Subroutines

232 LBL 80 242 LBL 81


233 "ERASE CURRENT " 243 IP
234 r-"SONG?" 244 1
235 CF 23 245 -
236 AON 246 1E3
237 PROMPT 247 .;.
238 ROFF 248 1
239 FC? 23 249 +
240 CF 01 250 STO 00
241 RTN 251 RTN

These two subroutines are just small routines that you use more than
once during the program. Subroutine 80 is the message that gives the
user one last chance to avoid erasing an unSAVEd recording. Subrou-
tine 81 builds an ISG counter and places it in register 00.

Section 9: The EXIT Subroutine

252 LBL 99 255 SF 29


253 CLMENU 256 FIX 02
254 EXITALL 257 END

Try to "EXIT cleanly," - restore the calculator to a reasonably conven-


ient state. Besides using CLMENU and EXITALL, since this program
) cleared flag 29 and set FIX 00 (to omit the decimal point and all decimal
places) - fairly unusual conditions - it's best to "undo these" now.

BUILDING YOUR OWN TOOLS: Programming 301


Stage Three: Debugging

Programs don't just "write themselves;" they don't leap from your mind
onto the page and into the machine by magic. And in developing them,
you'll make a lot of mistakes in your reasoning, logic, and design. You'll
need to some testing and"debugging" Here are some rules of thumb:

• To make things easier, key in and debug by sections (another major


reason why you develop in sections).

• Plan and even write down some typical examples and their intended
results and use these to test each section. If those all seem to work
all right, try to purposely "crash" the program by giving strange
responses or selecting menu items in unexpected (and illogical) )
combinations. This will highlight any needs for error traps and
(
expose other flaws in your logic.
)

• Remember that you can stop a program at any time with the [RIS)
key. And then you can view the contents of any register or variable .>
- without disturbing those contents or the Stack - with VIEW and )
AVIEW. Remember also that you can do single-step execution by
moving the pointer (and executing the code it traverses) one line at
)
a time, using the(!)(~) key while in Run Mode.

• Ifyou really get stuck, take a break or turn your attention to another )
section of the program. Often, you'll hit a mental block by pounding
your head against some knotty (naughty?) little error, but if you
turn your energies elsewhere, the mental block may clear-or your
thoughts on another section may lead directly to the solution.

302 An Easy Course In Using The HP-428


One more thing: No program design is ever perfect.

Sure, you may get the bugs out of some working version, but after
you've developed it, keyed it in, debugged it, and tried it a few times,
you'll almost always notice (or think of) certain things that could be
better. For example, in this MUSIC program:

• Because it take less time to generate and ignore an error than it does
to generate a normal TONE, the duration of a "Rest" is only about
half as long as that of a sounded note. Thus, when recording a song,
you need to put in twice as many beats for rests as you do for any
other note. You could experiment with the PLAY routine to try to
find a way to even out the duration of a rest without unduly slowing
down the PLAY loop.

• It is not immediately obvious that you need to press [RIS)instead of


(ENTs:l) after you enter the name of a song. Since this is different than
what you normally do, you may want to write an error-trapping
routine that finds out when(ENTs:l)has been chosen and prompts the
user to press [RIS) instead.

• It may seem inconsistent and unwise to have a simple [RIS] in one


case signify "PLAY the current program" and in another "erase the
current program." This could lead to unintended erasures.

• To be more "responsible," you could, in the Initializations section,


actually test and remember the current display setting (from flags
28 - 29, 36 - 41, etc.), so that in the EXIT routine, you could restore
exactly what the user had set his/her display to before this program
was ever run, instead of arbitrarily choosing how to leave things.

) BUILDING YOUR OWN TOOLS: Programming 303

)
q
0 .
~~--r-- \~. ..£L...£..

I
~ . ..
·11:
..
'"'_,o
I

\Ovu...i
.
"'•""'•"~

SOLVING PROBLEMS:
Using Your Power Tools
Congratulations! You've finished building your first customized "power
tool"- that MUSIC program!

But you also have some very useful power tools already built into the
machine (and after having worked so hard to make MUSIC, you can
) certainly appreciate these more now, eh?). By way of re-introduction
(and look back to the Big Picture on page 18, if you wish):

performs math in several bases and handles integer


arithmetic and Boolean algebra (binary logic). This is
especially useful for electrical engineers and computer
programmers.

is very useful, as you've already seen, for organizing,


storing, and manipulating large collections of data at
once. Matrices are used in business to help make plan-
ning and decisions, in science and engineering to do cal-
culations that are impossible or too time-consuming to
do any other way, and in statistics to perform detailed
analyses of whole collections of data.

performs many calculations in one- and two-variable


statistics, including regressio~ and forecasting accord-
ing to any one of four curve models.

calculates the definite integral of a function that you


program. This is essential for most technical fields .

• SOLVER] solves any specified equation for any unknown variable,


an essential ability in any kind of numerical analysis.

SOLVING PROBLEMS: Using Your Power Tools 305


The~Menu

The functions of the~ Menu can be divided into three categories:


its special display modes, its integer arithmetic, and its logic functions
(Boolean algebra).

The most commonly used functions are the special display modes.
When you first press ~. you'll see four mode choices grouped on
this menu list: ll!EII, Em, EI!:m, and IE!II. Each of these displays the
X-register in a different number base. The base of a numbering system
is the number of unique symbols (digits) used to represent numbers.

For example, the DECimal number system is base-1 O; it has ten


digits*- 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. All numbers are represented by
combinations of those ten digits and no others. )
(
But in base-8 (the OCTal number system) there are only eight digits- (
0, 1, 2, 3, 4, 5, 6, and 7. So how do you write "nine" in base-8?

Well, how do you write "eleven" in base-1 O? By using two consecutive


digits ( 11 ). Each digit stands for a different quantity. In base-10, the
right-most "1" is the "ones" place (10°) and the next is the "tens" place
(10 1) and the next one the "hundreds" place (1(>2), etc.

Similarly, in base-8, you have the "ones" (8°) place, the "eights" (8 1 )
)
place, the "sixty-fours" (8 2 ) place, etc. So to write 9 in base-8 you need
one "eight" and one "one": 11 8 (the subscript means the number is being
expressed in a base other than base-10). )

*Your ten fingers are also called "digits." This is no coincidence- how did you learn to count?

306 An Easy Course In Using The HP-428


Try This: Convert 469 to base-8 (OCTal), using your HP-428.

Solution: Key in~ and press ~ (if you haven't already


done so). Then EI!m. Answer: 725 8

You can check this by calculating 7 "sixty-fours" plus 2


"eights" plus 5 "ones": 7(8 2) + 2(8 1) + 5(8°) = 469.

Get the idea?

So, you'd expect base-16 (HEXadecimal) to have sixteen digits, right?


Well, it does! The letters A-Fare recuited to stand as the six extra
symbols ("numerals"). And that explains the menu item G!i: You use
it to key in the "alphabetic digits" in a HEXadecimal number.

For Example: Convert 725 8 to HEXadecimal, then add 7CF 16 to it.


Express the answer in DECimal.

Solution: Press llI!!ID to display 105, then press mi 0 . .


. . (±). The display shows 9A4, which is the answer
in HEXadecimal. Finally, press (EXIT)lrnil to get the
Answer: 2, 468

(Again, you could check this: 725 8 =469 - already proven above -
and 7CF 16 = 7(162) + 12(16 1) + 15(16°) = 1,999. And 469 + 1,999 = 2,468)
)

SOLVING PROBLEMS: Using Your Power Tools 307


But bases really get interesting when you see how computers actually
count "when nobody's looking:" They count in Bl Nary (base-2), using
just two digits, 0 and 1 (and you'll often hear Binary diglTS called by
their shortened name: BITS).

This system works just like all the others - except that there are so
many fewer symbols available. The positional "place"-values in the
Bl Nary system are:

... (24)'s (2°)'s

or

... 16's S's 4's 2's l's

So the largest binary number you could write in five bits would be
11111 2 , which is 1(24) + 1(23) + 1(22 ) + 1(2 1) + 1(2°), or 31. ()

The number of digits (bits) available to represent a binary number is


called the Word Size. In the case above, for example, the Word Size was
5. Your HP-42S cannot display a number in any of the HEXadecimal, )
OCTal, or BINary modes ifthe BINary version would require a Word
Size greater than 36. So the range of values displayable on your HP-
42S in any of the HEX, OCT or BIN formats is
)
11111111 1111 1111 1111 11111111 1111 1111, or 236 -1, or 68,719,476,735,
with actual values extending from -34,359,738,368 to 34,359,738,367

If you ask your HP-428 to so display a value outside this range, it will
instead show <T00 Bi 9), telling you that, while this number is still
stored properly, it cannot be displayed in any mode other than decimal.

308 An Easy Course In Using The HP-428


BINary mode is also used in computers to convert to OCTal and
HEXadecimal: Since BINary has an "eights" place, the number
11110000110010001101 2 can be converted into OCTal simply by regroup-
ing the "bits" into groups of threes (right to left):
)
) 011 110 000 110 010 001 101
3 60 6 215

Similarly, you can convert to HEXadecimal form: Just collect the bits
into groups of four and change each group into a character in HEXa-
decimal:
1111 0000 1100 1000 1101
F 0 C 8 D

Each OCT digit is three bits and each HEX digit is four bits!

Thus, 111100001100 1000 1101 2 = 3606215 8 = FOC8D 16

(Verify this if you wish!)

Also, you know that bytes are units ofmemory in your calculator, right?
But a byte is nothing more than eight bits (the equivalent of two HEX
digits)! Each ALPHA character uses one byte of memory - one two-
digit HEX number.

Sure enough - if you look at the Character codes in your Owner's


Manual (pages 288-291) you'll see that each character has its own two-
digit HEX code. There are 255 possible characters representable by 8
)
bits (though the HP-42S doesn't use them all).
)
)
) SOLVING PROBLEMS: Using Your Power Tools 309

)
Negative Numbers In The~ Menu

There are some other limitations you should know about when doing
base conversions on the HP-428.

First of all, truly negative numbers are displayed only in DECimal


mode. In the other three bases, changing the sign of a number
produces something quite different.

To understand these differences, you need to focus for the moment on


base-2. To represent negative values, the "sign" of a number must be
represented somehow; you need to use one of the 36 available bits (the
bit at the farthest left): a 0 there means a positive number and a 1
means a negative number.

For example, the number

000 000 ()()() ()()() ()()() 000 000 ()()() 000 000 011 1012 )

is equivalent to 29 in base-10. Since the 36th bit is clearly a zero here


(though the display doesn't show leading zeroes), the value is positive.

But how do you suppose you change the sign ofthis number, transform-
ing it into its opposite -the Bl Nary equivalent of -29?

1()() 000 ()()() 000 000 000 000 ()()() ()()() 000 011 101?

Well ... not exactly ....

310 An Easy Course In Using The HP·42S


Try It: Convert -29 10 to BINary.

Result: 111111111111111111111111111 111100 011.

(Press~ and hold it down to see the entire number).

Yoicks! Has the world gone completely wacko?

No, it's just a different form of logic. Negative numbers are repre-
sented in the •BASE) Menu by something called the "2's-complement"
of its positive binary number.

The easiest way to understand this is to envision the tape counter on


a cassette recorder (most of these tape counters have only 3 digits, so
imagine for a moment that you're working with a Word Size of 3 instead
of 36 - the argument is the same):

Suppose you reset a tape counter to 000 and then press the rewind key
so that the counter moves backward by one unit. You'd see the number
999 - and you'd know this is really a -1, right?

Right. Now imagine that this three-place counter has, on each of its
wheels, instead of 10 symbols, only two: 0 and 1. OK, you reset this
unique counter to 000 and then, again, move the tape backward by one
unit. What would appear? It would show 111, wouldn't it?

In the world of binary tape counters, 111 is equivalent to -1. The


) negative ofOOl ("one") is 111. The negative of010 ("two"), is 110, etc.

SOLVING PROBLEMS: Using Your Power Tools 311

)
Hold that thought. Now, notice that in the binary world, zeroes and
ones are "complementary." Since there are only two possible values for
any digit, the complement of a binary number is simply that number
with its digits exchanged: You change the zeroes to ones and the ones
to zeroes. So 001becomes110, 11101becomes00010, etc.

That's not a very startling observation, but notice that you'll get the
negative of a binary number (as in the tape-counter analogy) ifyou add
1 to its complement: The negative ofOOl is its complement, 110, plus 1,
or 111! The negative of 010 is its complement, 101, plus 1, or 110.

(
In 36 bits, the negative of
( I

()()() ()()() ()()() 000 000 000 000 ()()() ()()() 000 011 101 (

is its "complement+ 1:"


(

(111111111111111111111111111111 100 010) + 1 (


(
or 111 111 111 111 111 111 111 111 111 111 100 011

(
- which is exactly the answer that your calculator gave you in the last
example! This process of reversing each digit, then adding 1, is called
taking the 2 's complement of a number.

Then, of course, once you have a negative number in Bl Nary format,


you (and your HP-42S) can simply read its digits to get the correspond-
ing number in OCTal and HEXadecimal:

777777777743 8 and FFFFFFFE3 16

312 An Easy Course In Using The HP-428


)

Fractions And Integers In Other Bases

Now that you have some feel for how integers can be represented in
various number bases ...

Try This: Key in 47.35 and convert it to HEX. Convert back to DEC,
then key in 47 and convert it to HEX.

Results: 47.35 converts to 2F. while 47 converts to 2F. The only


difference is the period (. ).

While you're in the ~Menu and in any mode other than DECimal,
all fractions are completely ignored in the display. The HP-428 places
a period after the integer part to remind you that the number displayed
value has a fractional part that is not being displayed.

Furthermore, while in the~ Menu, the arithmetic operations (+,


-, x, and +) completely ignore fractions and work only on the integer
portions of the numbers. This is true even in DECimal mode.

For Example: From the~ Menu, add 5.78 and 4.89.

Answer: 9. 00. Yep. When in the~ Menu, your calcu-


lator treats this problem as "5 plus 4," completely
ignoring the fractional parts - no rounding or
anything. This is integer arithmetic.

SOLVING PROBLEMS: Using Your Power Tools 313


The [E!JB Menu

The third major set offeatures on the 98ASE)Menu is in the ~Menu.


There you can manipulate BINary numbers in a way that is even
simpler than adding and subtracting.

George Boole began the computer revolution unknowingly in the


middle of the 19th century when he developed a system of logic in
which everything spoken or written could be considered as either true
or false (or "O" or "1", if you prefer). Then he went on to define different
ways in which to combine statements that are true and false, develop-
ing a "two-valued," or binary system oflogic.

It wasn't until 100 years after George Boole invented this binary logic
that the first primitive electronic computers were made. The man who
really made the connection between logic and computer science was
Claude Shannon. He developed the idea of"switching circuit theory,"
the idea being that electronic switches being ON or OFF could exactly
represent Boole's system, where every assertion is either TRUE or
FALSE.
{ l
Well, the rest is history: To this day, Boole's system - called Boolean
Algebra, or binary math - is the actual way that your calculator (and
nearly every computer) performs arithmetic. )
)

To get an idea of how this Boolean Algebra works try the following:

314 An Easy Coune In Using The HP-428

(
Example: Perform the following Boolean operation: 37 AND 14

Solution: Press !mlN from the ~Menu. Then~


mJI. Answer: 4. 00

Which makes no sense at all until you see it at the Bl Nary level:

When the computer does a logical operation (such as AND) with two
Bl Nary values, it treats each pair ofcorresponding bits independently:

000 000 000 000 000 000 000 000 000 1 I 1 1 (37)
000 ()()() ()()() 000 000 000 000 ()()() ()()() 1 1 (14)
000 ()()() ()()() 000 000 000 000 ()()() ()()() ()()() ()()() 100 ( 4)

Think about it this way: If you have two verifiable statements,


(i) '1 am male," and (ii) '1 have blue eyes," each of these statements
is either true or false. If true, assign it a value of l; if false, 0.

Now consider the statement, '1 am male AND I have blue eyes."

This statement is true (1) only if both the individual statements are
true (1 ). Mathematically, then, (1AND1) =1. But (1AND0) =0, (0 AND
1)=0, and (OANDO)=O, since if either individual statement is false (0),
then the entire combined statement is false.

The point is, to perform an AND on two BlNary numbers, your machine
performs an AND on each pair of corresponding bits, and places the
result in the corresponding bit in the B/Nary answer.

SOLVING PROBLEMS: UBing Your Power ToolB 315

)
There are other logical operators, too: llillll, llIDITI, and CIIll. Using the
same analogy (two verifiable statements), the logic of each of these is:

• if at least one (it could be both) of the individual statements is true,


then the combined OR statement is true:

(1OR1) = 1 (1OR0) = 1 (0 OR 1) = 1 (0 OR 0) = 0
Thus, (37 OR 14) = 47.

• if one or the other (but not both) of the statements is true, then the
eXclusive OR is true:

(1 XOR 1) = 0 (1 XOR 0) = 1 (0 XOR 1) = 1 (0 XOR 0) = 0


Thus, (37 XOR 14) = 43.

• NOT is simple operation that takes the complement (not the 2's
complement - just a simple flipping of bits), replacing l's with O's
( ,
and O's with l's. NOT operates on only one number at a time and
has the effect of reversing the sign and subtracting one:

Thus, NOT(l) =-2 NOT(-1) =0 NOT(37) = -38 NOT(-14)=13

O 'Brave 'Jl&w 'Worfa, tfiat fias sucli operators in't .... )

And what good are these operators? ...Well, certain electronic circuits
can simulate them (open/closed= 1/0)- then combine in various ways
to build (among other things) arithmetic operators!

Your HP-42S can multiply and add only because it can AND and OR!

316 An Easy Course In Using The HP-428


Solving Problems In •MATRIX]

You've already had a good introduction to the 9MAfRjX) Menu. You


know how to use the Matrix Editor to enter and edit matrices (pages
142-147), how to use them to store data in a compact form (pages 280
-281), and how to manipulate them within programs (pages 294-297).

Now, it's time to use matrices and the 8MATRIX) Menu to solve some
problems. But before you do anything to complicated, make sure you
understand the details of matrix multiplication.

Matrix Multiplication

Back on page 155, you observed the following essential rule:

'Ifie oraer ofmu{tip{ication is important: tfie number of co{umns in tfie


first matrb\_ must matcli tfie num6er of rows in tfie secona matrov

For Example: Find C=AB, where A=[3-41 ]


-1 2 7

and B=[-~4 -2~ ]


Solution: C= [ 22 25
20 -23
l

SOLVING PROBLEMS: Using Your Power Tools 317


l
Here's why: Element 1:1 of C =[(3)(2) + (-4)(-3) + (1)(4)] =22

How so? Because this is the sum ofthe products that result when each
element of row 1 of matrix A is multiplied by the corresponding
elements of column 1 in matrix B.

And element 1 :2 of C would be the sum of the products resulting when


the elements of row 1 of A are multiplied by the corresponding
elements of column 2 of B: [(3)(9) + (-4)(0) + (1)(-2)] = 25

Get the idea? Ah, but why do any ofit by hand with an HP-42S handy?

Go For It: DIMension and enter A: ~™®il!J llJII Q


[ALPHA)AIALPHA) m:J lllm@) IOI G]+/-) IOI CTI IOI
OJ+/-) IOI (I] IOI 0 . . [EXIT).

Now for B: @)ENTER(fil m [ALPHA)B(ALPHA) [Ell) . . (I] )


IDl@IDl~IDl@)IDIGJIDl~+/-)IDll[EXIT). (/

Now, to multiply AB, thefirstmatrix(A here) must be in


the Y-register and the second matrix in the X-register:
[RCL) . . [RCL) . .. Now (8). You'll find the solution
matrix in the Matrix Editor (afi&B[aj rnII, etc.).

)
From the above definition of matrix multiplication, you can see why
the order might matter: To reverse the matrices would mean combin-
ing totally different sets of rows and columns, wouldn't it? (Use the
HP-42S to find BA: [RCL] . .[RCL]. . (8)~ rnIJ)

318 An Easy Course In Using The HP-428


Simultaneous Equations

One of the most common and most powerful uses for matrices is to solve
systems of linear equations. For example suppose you want to find x,
y, and z such that these equations are all true, simultaneously:

4x - 3y + 2z =40
5x + 9y - 7z = 47
9x + 8y - 3z = 97

To begin with, you need to be able to rewrite the problem so that it


becomes one equation involving matrices. To do this, notice that there
are three kinds of numbers in these equations - the coefficients of the
variables, the variables themselves, and the right-hand side constants
(40, 47, and 97). Each of these groups can be placed in its own matrix:

A= [54-39 -72] 8 = [~~]


9 8 -3

Coefficients Variables Constants ("answers")

Notice that if you follow the rules of matrix multiplication that you've
just reviewed, when you find AX, you'll get this matrix:

4x - 3y + 2z
AX = [ 5x + 9y - 7z
9x +Sy - 3z
l
Aha! Comparing this matrix to the system of equations above, it's
obvious that another way to write those equations is: AX =8

Thus the three equations of three variables have thus been reduced to
one (matrix) equation with one (matrix) variable, X!

SOLVING PROBLEMS: Using Your Power Tools 319


Well, all this was discovered a long time ago. And now, to solve for the
solution matrix, X, on paper, you'd probably use techniques named
after the dead mathematicians who did the discovering (Gaussian
elimination or Cramer's Rule). But can't you just hear the HP-428
snorting and pawing the ground, eager to do battle with it?)

Charge! Press ~ mml and key in @TI). The machine will


automatically create and dimension three matrices: MATA
(the square coefficient matrix), MATS (the one-column con-
stant matrix), and MATX (the one-column variable matrix).
With three unknowns, MATA will be 3 x 3; MATS and MATX
will be 3 x 1 .*

So now you'll see a menu with those matrices, GIIli'J, IElll,


and Grnlll. The idea now is to fill in the values in the known
matrices (A and 8) and solve for the unknown matrix (X).
The keystrokes for the example problem would be:

m:rnJGJ . . 0+1-JIDl@JIDl®IDl®IDICTI+1-JIDI
m.. 0 IDl@EEJ -.1Ex1TJ IElll (ill) . . CillJ-.
ffiI) . . [EXIT) mnJl... (you'll be sent right to the Matrix
Editor to see the solution) ...

Victory: MATX = [ ~Ol That is, x = 10, y =2, and z = 3

*As you may or may not remember, you must always have the same number of equations as
variables if you hope to get an answer. This means that you can solve a system of three equations
in three variables, or a system of five equations in five variables, etc.

320 An Easy Course In Using The HP-428


Ready to try one on your own?

Solve: a+ b+ c+ d + e = -1
3a - 2b - 2c + 3d + 2e 13
3c +4d- 4e = 7
5a-4b + e 30
c -2e = 3

Solution: First, MATA is a 5 x 5 matrix


311111
-2 -2 3 2 1
(notice how zeroes have been filled [ 0 0 3 4-4
in where there are no coefficients 5-4001
otherwise): 0 0 1 0 -2

MATB is ilie 5x1 ma- [:~1


And ilie solution ma-, MATX, is: r~ J

Starting with •MATRIX) lmll@TIJ, proceed as on page 320


Gmil.... a = 3, b = -4, c = 1, d = 1.213 x 10·12 (nearly O*), e =-1

Now, aren't you glad that your calculator did that for you?

*When you substitute the answer back into any of the equations, it becomes obvious thatd must,
in fact, be exactly zero. The difference is due to the rounding done during calculation.

SOLVING PROBLEMS: U11ing Your Power Toolll 321


The~Menu

The~ Menu is a power tool you'll be studying more closely than


you did the~ Menu, since this is the first look you've had at it.*

First Lesson: Some of the numbered registers (i.e. elements in the


built-in REGS matrix) are used as STATistical registers. They are
normally registers R11 through R23 (thirteen in all)- unless you specifi-
cally reassign them.

(
Here's are the STATistical registers in their standard "locations:"

Ix
Lx2
LY
L,y2
Ixy
n

Second Lesson: These registers differ from other numbered regis-


ters because they automatically change their contents after certain op-
I
erations; you don't need to refer to ("address") these registers directly
to change the data being accumufated in them.

And what operations cause these effects? Just two: ~and~-

*Unless, of course, you've already mastered the entire Menu on your own. If so, skip to page 350.

322 An Easy Course In Using The HP-428


But before you start messing with ~and SE, you ought to spend a
moment considering the basic ideas behind statistics. For in no other
area is your calculator capable of generating more garbage than in the
~Menu. A little knowledge here can be a very misleading thing.

What Are Statistics, Anyway?

To put it as directly as possible: "Statistics are calculation methods in


which you use collections of numeric observations to detect patterns or
correspondences among real-world events or phenomena." In other
words, statistics are used to discover what's important or consistent
about a collection of otherwise confusing observations.

For example, everybody's familiar with the idea of an average. If you


want to predict the amount ofrain that's going to fall this year, one good
way is to add up all the rainfall amounts for the past few years and then
divide by the number of years in your sample.

In other words, you're doing this calculation: Ix


n

where each individual x is the rainfall amount for one of those past
years, I means to sum all the individual x's together, and n is the
number of years of data (the number of x's) that you're using.

Thus, an average is one simple kind of statistic. And this begins to


explain two of the statistical registers in the collection (n and I,x):
Those registers are where you store the number of data (n) and the sum
of those data (I,x), respectively. Then it's easy to find the average: just
divide the contents of R11 by the contents of register Rw right?

SOL YING PROBLEMS: Using Your Power Tools 323


But what about all of those other registers? Why would you need Ix2?
or any "y-data" (not to mention In y)?

Well, those accumulated quantities are necessary also - for many


really interesting and useful tests about your accumulated data.

Suppose, for example, that someone suggests that your annual amount
of rainfall depends on the average daily temperature for that year.
How could you test this? Clearly, you now have two sets of observations
(rainfall and temperature), the one supposedly depending on the other.

It's just like the graph of a mathematicalfunction, where eachy-value


(the height of any point on the curve) is a function of (i.e. it depends
upon) the correspondingx-value (the horizontal position of that point):
y (
••
Dependent •

Variable • ••• • •
• • • •


r
Independent Variable
)
This is the purpose of two-variable statistics-to analyze relationships
between an independent variable (the x-data) and an allegedly de-
pendent variable (they-data).

And this is why you have those other statistical registers on your HP-
42S: It can do either one or two-variable statistics - and the formulas
require not just Ix and LY but also Ix2, L,y2, Ixy, L.lnx, L.lny, etc. So
as you key in collections of observations - your statistical data - the
machine will keep running tallies of all these different quantities.

324 An Easy Course In Using The HP-428


Entering Some Statistical Data

Before you start accumulating and analyzing a new set of statistical


data, you should always make sure that your STATistical registers are
cleared from any previous data.

To do this, select the llCCEARJ Menu, then press l!B to clear all of the
statistical registers (no matter where they're located!) .... Now, FIX 00
and then ...

Example: Suppose that you've owned a small bookstore for the


past 20 years. The last 11 years' sales figures are:

Tufil: ~
1978 $170,000
1979 220,000
1980 215,000
1981 240,000
1982 145,000
1983 190,000
1984 230,000
1985 240,000
1986 245,000
1987 180,000
) 1988 270,000
)
You want to use the statistical capabilities of your HP-
428 to tell you some things about this sales history. How
do you do this?

SOLVING PROBLEMS: Using Your Power Tool& 325


Solution: The idea is to key in all these values as statistical data.
When you do so, your HP-42S will not remember the in-
dividual values themselves, but it will accumulate*
them (in the STAT registers, of course) in the form of
those various sums, from which it can then calculate all
sorts of useful statistics for you.

So here you go: Press~-

What happens? The X-register now shows a 1. , telling


you how many data points you've entered. It does this
simply by recalling the current(updated)value inn-reg-
ister (R 16 , if located normally). This makes sense, right? ()
That's what the statistical number, n, is supposed to (
measure-the number of data points accumulated so far. (

So keep going: ~
~
~ (

~
~ )
~
~
~
CilllillIBfil8
~

*It's better to use this term, "accumulate," rather than "store." It's not quite accurate to say that
you "store" your data in the STAT registers. After all , once you enter them with the [B key, you
canrwt retrieve them again as individual values; it's only their cumulative sums that are stored.

326 An Easy Course In Using The HP-428


As you do this, keep in mind what's actually going on
inside your calculator: Every time you press ~. the
machine looks for two values - one in the X-register and
one in the Y-register.*

Then it adds each x-value to the Ix register, and the


square of that value to the Ix2 register. It does the same
for they-data, and then adds the product of the x-value
and they-value to the Ixy register. It then proceeds to
calculate the naturallogs ofx and y (the LN function) and
accumulate those respective sums, squares, and prod-
ucts into their appropriate statistical registers.

Finally, it increments then-register by one, to count the


total number of data that you have now accumulated in
this way- and recalls this new n-value to the X-register
to help you keep your place!

All this - every time you press that one little (g) key!

Thus, if you've done everything right, at this point you


should see 11. displayed in theX-register, since you now
have 11 years' worth of sales data accumulated in the
STAT registers.

*If you're working only with one-variable statistics(" x-data") the machine will still accumulate
whatever meaningless numbers it happens to find in the Y-register, but this is harmless exercise
and will not affect the results of your x-analyses.

SOL YING PROBLEMS: Using Your Power Tools 327


Checking and Editing Your Data

... Hmm ... but what if you' re not sure that you've done everything right
(or, what if you're sure that you've not done everything right)?

The first clue that you may have messed up would be that the X-
register didn't end up with 11. in it (if not, then just start over on page
326). But assuming you got that much right, how else might you check
the accuracy of your entered data?

Try This: Enter the ~ Menu. You should see:

( I

Now press E!lD and you should get 2, 345, 000. - if


(
you've correctly keyed in your data. This is your 11-year
total sales revenue. If you see this, then you can
probably assume that everything's all right. If not, then
go back and start again at the top of page 326. )

)
This is one of the drawbacks to cumulative statistics (as opposed to
storing the data values themselves): If you've mis-entered something,
there's not much to do except to start over - unless you know exactly
how you went wrong.

Even ifit's all correct, what if you simply want to amend or edit the data
list (add or subtract something, replace a figure, etc.)?

328 An Easy Coune In Using The HP-428


"Uh ... ... hmmm ... can that even be done? How can you change individ-
ual values that aren't even stored as such?" Well, it's not obvious,
but you can - by "backing out" ("un-entering") any values you want to
delete, then entering any new or additional values.

Like This: Suppose you just discovered an accounting error for


the years 1981-1984. The sales values for those years
should actually be (respectively): $236,000, $154,500,
$209,000 and $223,000. How would you edit your sta-
tistical accumulation to reflect these recent findings?

No Sweat: First, use mB key to "un-enter" your sales for the


years 1981through1984 (you're literally subtracting
from each of the statistical registers the same amounts
that the (El key originally added- effectively erasing
those data values from your cumulative totals):

ClliII@Iill) mB CIIillillilll mB CIIillifil@)


mB~

(Notice how the value in the X-register confirms that


you are indeed subtracting data values.)

Now add in the new figures (and the order never


matters, does it?): ~(E)~(E)
~(El~. (If you did all this
correctly, there should be 11. once again sitting in the
X-register, and the E!1D value should be 2, 362, 500. ).

SOL YING PROBLEMS: Using Your Power Tools 329


Just Plain Mean

All right - now that you have the corrected set of sales figures all
accumulated properly into the STATistical register of your HP-428,
what do you want to know about your income?

Might as well start with something simple ....

F'rinstance: What was your average (also known as your mean)


yearly sales over, say, the last ten years?

Solution: First you need to adjust your data. Currently, it has


data for the last eleven years. To eliminate the oldest
year'sdata(thatfor1978),keyin~.

Press !Em (from the llSTATJ Menu, of course). This


calculates both the means of both the x-values and
they-values, and places each in its appropriate stack
register (in this case, of course, you're concerned only
with the X-register, because you only have one set of
data).

Answer: 219, 250.

Not bad.

330 An Easy Course In Using The HP-428


A Moving Average

Time Flies: Now suppose it's the end of1989-and you're curious
how this year's sales ($234,600) affected your ten-year
moving average. That is, you're always concerned
with the most recent ten-year period, so you need to do
your editing trick on the STAT registers once again -
subtracting your 1979 sales and adding your 1989
sales - and then find the average of those ten values.

The keystrokes? By now these ought to be ...

Old Hat: Press~, then~(no­


tice that you can do this right at the ~ Menu).

OK, now you've just updated the data (i.e. you've


moved the average forward) - and you can tell from
then-value in the X-register that you still have ten
values, so that checks.

Now find that average: press !mim.


Ikfilili: 220' 710.

Does this answer make sense?

Sure it does: You deleted a value of$220,000 and replaced it with a value
of $234,600. You'd therefore expect the 10-year average to go up - and
it did.

SOLVING PROBLEMS: Using Your Power Tools 331


A Weighted Average

All right, now you've seen a plain old, garden-variety, vanilla-flavored


average-and one that "moves" in time (a moving average). But what's
a "weighted average?"

Try This: Suppose that your monthly sales revenue for 1989 went
something like this (and this adds up to $234,600, which
is what you used for your 1989 yearly total):

January $ 29,000
February 10,500
March 17,200
April 15,500
May 10,500
June 9,700
July 9,700
August 15,500
September 34,500 )
October 15,500
November 29,000
December 38,000

What was your monthly average income?

Strategy: You could just key all this into the STATistics register-
and find the mean ofx, exactly as you've done before. Or,
you could observe that since there are repeated values
here, it might be easier to use a weighted mean (IIJm)).

332 An Easy Course In Using The HP-428


Compare: First, do it the "old-fashioned" way: Press •cLEARll!tl
CilllIIilllliJ~CilllilliillB
Oiilillli:@]~~~
Oiilillli:@]~Oiilillli:@]
~- ThenllSfAD!mlm. Result: 19,550.

Yes, But: Since the order ofdata entry never matters, use a weighted
mean to key in each different value just once - but note
also how often that value occurs in your collection:

Monthly Sales Frequency Of Occurrence

9,700 2
10,500 2
15,500 3
17,200 1
29,000 2
34,500 1
38,000 1

To "tell this" to your HP-428, you key in two numbers for


each item. The first (they-value) is the frequency (or
weight); the second (the x-value) is the sales value itself:

.CLEARJ~(IIENTER~(IIENTER~
@]ENTER~ffiENTER~
(IIENTER~ffiENTER~
ffiENTER~ mml Result: 19, 550
Look familiar?

SOLVING PROBLEMS: Using Your Power Toola 333


So that's a weighted average: For every x-value you key in, you must
also specify (with a corresponding y-value) how "heavily" thatx-value
should be "weighted" - i.e., how many times it can be considered to
have "occurred" in this data set.... Gettheidea? Want to do another?

Sure: A chemist knows that any sample of"pure" copper she uses is
actually composed of two isotopes (varieties that differ slightly
in mass): 63Cu (62.93 g/mol) and 65Cu (64.93 g/mol). She knows
that about 69.2% of all copper atoms are 63Cu and 30.8% are
65 Cu. She needs to use a weighted mean to find the "average"

mass to assume for her sample of copper.

Hmm: She has a data set that looks like this:

Isotope Mass (x) Frequency of Occurrence (y)


(

63Cu 62.93 g/mol 69.2%


6scu 64.93 g/mol 30.8%

Now, to calculate the weighted mean:

~ lim:l@:IIJ for a more meaningful display setting, then


~mll~~~
~mm.
:&filili: 63. 55 g/mol.

This means that the chemist can safely assume that the best
mass to use for any random sample of copper would be 63.55
g/mol-the weighted average of the masses of the two isotopes.

334 An Easy Course In Using The HP-42S


Deviating From The Average

Of course, any average can tell you only a certain amount about your
data. To say that you "sold a monthly average of$19,550 worth of books
in 1989" makes it sound as if you could count on that level of sales every
month, steady and predictable.

Sure, it might have happened that way. Or you might have sold the
entire year's total ($234,600) during the Christmas season rush- and
sold nothing the rest of the year.

The point is, you can't tell merely by looking at the average, because
no matter how uneven and irregular your sales actually were, as long
as they add up to $234,600 for the year, your monthly average will
always calculate out to be the same number. An average just doesn't
tell you anything about the distribution of your values.

Well, after a quick glance at your actual monthly income history for the
year, you know what your sales distribution was: It wasn't smooth-
and-regular, nor was it "all-in-one-rush." In the summer months, sales
were slow (everybody was at the beach), while in the fall and winter,
your book sales were brisk - accelerating as Christmas approached.

So exactly how even or uneven was it? How can you measure this from
a set of values?
)
That's one of the uses of the standard deviation statistic- to measure
how widely dispersed or varied from the average your actual data
values are.

SOLVING PROBLEMS: Using Your Power Tools 335

j
To get the idea,

Try This: Key a set of identical values into the STATistical regis-
ters, say, four 4's: •cLEARl~H ~

What's the averageofthissetofvalues? It's4. ,of course


(verify it with lllm, if you wish).

And what's the standard deviation - the measure ofhow


far a "typical value" tends to vary from this average?

To find out, press m:D. Result: 0,


(
Since every value is an average value, there's no vari-
ation from that average; the standard deviation is zero.
(

Now This: Key in these values to the STAT registers: 11, 0, 1, 4


(press .CLEARl'i!lfl~@JE~GJB).

Find the average: lllm. Result: 4. - same as before.

But now find the standard deviation of this set of data:


Eil1). Result: 5,

Compared to the average itself, this is a large deviation


- telling you that the actual values vary quite widely
from that average.

336 An Easy Counte In Using The HP-428


This is the way to measure how "even" or "uneven" your book sales
revenues were over the year 1989: Take the standard deviation of your
monthly sales levels for that year....

Like So: (Unfortunately, because you've since entered other sta-


tistical data, you'll now need to re-key in the twelve
values again; see page 332 if you want to review the list.)

.CLEARlliQ~@:@@)~~
~~~~
~~~
~~-

Just to refresh your memory, find the average monthly


sales again (press !mlm). ~: 19, 550. 00.

Now, to test out the "evenness" of the sales, press Em.


Result: 10, 247. 35

That's quite a large deviation in comparison to the average itself - so


it was quite an up-and-down year for your store, sales-wise.

And if you were to compare this to similar calculations for other years,
you could tell immediately in which years you had smoother, more
uniform sales - the years with smaller standard deviations!

)
)

SOLVING PROBLEMS: Using Your Power Tools 337


Now, to be more exact, there are two kinds of standard deviations- and
they mean different things, because they use different formulas.

The formula programmed into your HP-428 assumes that your data is
really a sample of a much larger population - as if you were catching
fish to get an idea of the typical weight of any such fish in the ocean.
This is useful, obviously, when you can't actually catch and weigh every
fish in the ocean.

But for other situations (as with your monthly sales figures for 1989),
you can actually analyze all the possible data - an entire population.
And the standard deviation formula for an entire population is slightly
different than for a sample* (and the population formula is not pro-
grammed into your HP-428). But you can get your HP-428 to calculate (
the population standard deviation - by adjusting your data a tad. (

Like This: To get the population (true) standard deviation for your
1989 monthly income, you add one extra entry to your
STAT accumulation - the average for the actual data. So )
you'd first calculate this average (press !ilm), then enter )
it as a "13th value:" (g). Now you can use the built-in
)
formula, m:D, to find cr .... Result: 9, 811.

This is somewhat less than the sample standard devia-


tion, which is usually the case.

*Statisticians use different symbols for sample and population standard deviations. Sample
standard deviation is abbreviated as s. Population standard deviation is abbreviated as cr.

338 An Easy Coune In Using The HP-428


)

Two-Variable Statistics

) Up to now, the information you've gathered from your bookstore data


) has involved only one variable - the book sales figures themselves. You
now know the yearly and monthly averages of recent sales, and you
know that your monthly sales vary considerably from their average.

But do you have any idea why it varied like that?

"Sure - because more customers come into bookstores in the fall and
winter than in the spring and summer."

OK, but why? Does the average person suddenly become more
interested in books in September?

Is that when everyone can afford the time or the money to shop for
books? Would it have anything to do with the weather - the amount of
rainfall or the temperature outside?

Well, any of these ideas are possible explanations. But how would you
)
go about testing whether or not a particular explanation is a good one?

SOLVING PROBLEMS: Using Your Power Tools 339


Getting Trendy: Regression and Estimation

Here's where you really start to use two-variable statistics to help you
answer questions and test possibilities. And one very useful toolset is
already built into your HP-428: regression and estimation.

Regression is a general term in statistics for finding a mathematical


relationship (a dependence) between two (or more) variables. If you
think of the two variables as x and y, then regression is the process of
finding the equation that is transforming each x datum into a y datum.
()
Take, for example, the equation, y = 5x + 2. This formula transforms
each x into a y by first multiplying the x by 5 and then adding 2 to it.
(
But that's when you know the equation already. Regression analysis
doesn't begin with an equation. It begins with two sets of data, the x-
values and the y-values, and attempts to find the one equation that
comes the closest to turning each of the x-values into their correspond-
ingy-values. In the simple example above, regression would begin with
a set of data such as:

x y
3 17
4 22
7 37
-1 -3

and would then figure out (mathematically, somehow) that if each x


were multiplied by 5 and then incremented by 2, the result would be the
corresponding y-value.

340 An Easy Course In Using The HP-428


J

To solve such a tricky problem, what your calculator does, essentially,


is plot the x- and y- values on an imaginary graph, like the one below:

20
) 10

5 10 15 20 x

It then "draws" the best-fitting curve - the curve that gets as close as
possible to as many of the data points as it can. Then the equation it
wants will be the equation of that curve.

In the simple example graphed above this "curve" is actually a


straight-line (indeed, when regression is restricted to finding the best-
fitting line for a set of data, it is called linear regression). But whether
or not the curve is linear, you can often find that curve, with the help
of a very "smart" item in the~ Menu: mil, or Curve FITting:

Do This: Enterthe data from the example on the previous page


into the STAT registers, then press mll.

Here'sHow: ~l!B~~~G@
0IJENTERJCfIEffi +/-}ENTER)CiI±Bf£] mil.

Remember that you must enter they-value first, then


key in the x-value.

)
SOLVING PROBLEMS: Using Your Power Tools 341
The display should now look like this:

This new sub-Menu can be used to find the "equation" that is the
solution to a regression problem.

Try It: Use your HP-428 to find the regression "equation," assum-
ing that the best-fitting curve is a line.

Like So: First, you must tell the calculator your assumption about
the shape of the best-fitting curve. To do this, choose GI!]B. (
This selects one of the four MODeL assumptions that your
calculator can work with. You'll probably see LI Near Func-
tion selected (m:JjJ) already; if not, select it now (the other
three MODels are LOGarithmic Function, EXPonential
Function, and PoWeR Function, which you'll see shortly).

Now, remember that the general equation for a line is

y = mx+ b

where mis the slope of the line and bis they-intercept. Your
calculator will use this notation convention, also.

So, [EXIT) back to the lml sub-Menu and choose~­


Result: 5, Then choose fillII. Result: 2.

342 An Easy Course In Using The HP-428


Thus the best-fitting equation of this linear regression is: y = Sx + 2

Which is exactly what you knew it should be. Remember that the
number, m, is called the slope of the line, because it determines its
"steepness" as it appears on the graph. For every 1 unit you change the
x-value, you change the y-value by "m" units. So the higher the m-
value, the steeper the slope of the line. And if m is negative, the line
slopes "downhill" to the right; if mis positive, the line slopes "uphill"
to the right (as it does in the last example).

As for b, what y-value do you get when xis zero?... y = b , right?

Butx is zero only along the y-axis, so that point on the line would also
be on the y-axis, and thus the line would cross the y-axis at that point.
Sob is called they-intercept value - because this is the value (the
"height") at which the line "intercepts" the y-axis.

The "slope" and "y-intercept" are also key values in MODels other than
LINear, although their interpretation isn't quite so simple as in the
LI Near case. The equations for the other three options are:

• Logarithmic: y = b + m(ln x)

• Exponential: y = benu or lny=lnb+mx

• Power: y=b.x"' or In y =In b + m(ln x)

Using the STAT registers (including the registers containing logarith-


mic data), your HP-42S can find a best-fitting equation using any of
these models-youjust select the MODeL most likely to "fit" your data.

SOLVING PROBLEMS: Using Your Power Tools 343


OK, you've been through an ideal example with that trivial little linear
equation. What about the real world - your sales data, for example?

You need to decide on a second variable for your data. Didn't you say
you might have some ideas as to why your sales figures vary from year
to year - some other factor-some variable condition upon which your
sales seems to depend?

What's your best guess? Christmas? Well, it probably has an effect,


but it isn't exactly a variable - it comes around every year.

Weather? ... It's possible: People read more (it's an indoor sport) as the
weather gets bad. But what measurable aspect of weather do you think
matters most? Temperature? ... Rainfall? ... Hmm ... a rainy spell in the (
summertime sends people indoors to read, even when the temperature (
remains relatively high. Rainfall might be a good variable to test.

First, you'd better state your theory (the one you're about to test )

statistically) in so many words, just so the folks at home know what it


is you're trying to prove: )

)
~amount ofannualoooK:_safes over tfie past ten years (1980· 1989) aeperufea

upon tM amount of rainfalI in tfie vicinity of my oook§tore. 'Ifie rainer it was )


auring any particular year, tfie more 6ooK:_safes I fuu{ tfiat year.•

OK, now when you say "depended upon," you're saying that the rain
and nothing else was by-and-large responsible for your varying book
sales. You're saying that other factors (bus strikes, the competition's
summer sale, heat waves, MTV, tax audits, cash crises, the school
schedule, etc.) didn't really cause these variations.

344 An Easy Course In Using The HP-428


Sure, those other factors may have caused small fluctuations in your
sales, but you're claiming here that they were insignificant compared
to the governing condition -the independent variable - rainy weather.

Fine. And now what do you mean by the phrase, "the rainier it was, the
more sales I had?" Do you mean that if the rainfall doubled, your sales
doubled? Tripled? If the rainfall is an inch more in any given year, do
you generate $10,000 more in sales? What?

Well, that's a tough one. You've only just now suggested that there is
any kind of numeric connection - a correlation - between rain and
sales, and now you're already trying to decide what the correlating
relationships might be.

Remember regression? Why not let your HP-428 decide that for you?
Why not try a simple, LI Near model, and see how well it correlates - or
fits - your data?

Ready to test your theory? All right: To put it a little more mathemati-
cally, what you're really proposing on the previous page is this:

':for tfie fast ten years, tfie annual 6ooK_sales of my 600/qtore fuis 6een airect{y
propo~.onal {on a {inear moae{} to tfie amount of rainfalL '!Frat is:
Yoole• = 111Xrainfall +b
wfiere m anab are constants.•

SOLVING PROBLEMS: Using Your Power Tools 345


Test It: Here are your rainfall and sales data for the last ten years:

Year Rainfall (inche~} Sal~~($}


1980 17.0 215,000
1981 25.2 236,000
1982 19.2 154,500
1983 18.5 209,000
1984 21.5 223,000
1985 25.0 240,000
1986 28.3 245,000
1987 12.5 180,000
1988 25.9 270,000
1989 22.0 234,600

(
Is there a linear correlation between annual rainfall and
annual book sales?
( )
Analyze: Press •CLEARl'l!f!I ~IJHl@TI), then enter all the data
(y-data first in each set):

)
CililllTiillJ(ENTER)GTI)~
Cilllilliilll(ENTER) CffiEill~
CilliilllillJ(ENTER)QliEIB[g)
~(ENTffi)Cilll'.TI)[g)
)
CillITffiillJ(ENTffi) CillEIT)[g)
~(ENTffi)@lil~
CilllillTIIQJ(ENTER)@nEIT)~
crrm::@Iill)(ENTER)o:ITEffi~
Cilllfiliill)@I®CillEITJ[B
~(ENTffi@rr)[g)

346 An Easy Course In Using The HP-428


(Now check theli!ID - there should be 215.10 in the X-
register and 2, 207, 100. 00 in the Y-register. If not, then
you've made an entry error and need to start over.)

Next, press mII mlm to find m. Result: 5, 269. 78


Then find the y-intercept, IE[I. Result: 107, 356. 95

So your equation is: Ysaies =5,269.78.x,aintaii + 107,356.95

So, are you right? Is the rain driving your book sales? That
is, how well does this line fit your data? Unlike an ideal
example, not all the data points are exactly on this line of
regression. You know that the line is the best-fitting line for
the given data, but that doesn't really tell you everything.

You need to use a measure of"fitness" to tell you how closely


the line fits your data points. This measure is called the
correlation coefficient, r, a number between -1 and 1: If r is
close to 1 (for a positive m) or -1 (for a negative m), the fit is
good, and your theory seems valid. Ifr is nearer to 0, then
the fit is not good, and your theory sucks.

So, test the fitness of the regression line of your rainfall


theory: E!Ilill. &filili: 0. 76

Hmm ... not bad. 0.76 indicates a fairly good linear correlation, though
it could be stronger (suggesting possibly that although rainfall is a sig-
nificant factor in your book sales, it doesn't explain all fluctuations).

SOLVING PROBLEMS: Using Your Power Tools 347


How about trying other MODels? Maybe rainfall affects sales in a
pattern more nearly logarithmic or exponential than linear. You can
find out - and without re-entering any data!

Explore: Find the correlation coefficients for your rainfall/book


sales theory for logarithmic, exponential, and power
curves.

Discover: Select ~. then press l!E], (EXIT) back to the previous


sub-Menu, and select mfilt to find the correlation coeffi-
cient for the logarithmic model: 0. 74 .

Repeat this procedure (m:rn!fmi(EXIT) l!!Ifill) to find the (


correlation coefficient in the exponential model: 0. 73 .
(
(
Similarly, the power model yields a coefficient of0. 71 .
(
It looks like the linear model did the best job after all!

Question: How can you make sure you always use the best model?

)
Answer: Select lllilon the GElll sub-Menu. The calculator will
check all four models for you and select the one with the )
highest correlation coefficient for that particular set of
data. Try it now .... It picks the linear model, as it should!

348 An Easy Course In Using The HP-428

(
All right, assuming that your linear correlation is more or less correct,
if your cousin (the Old Farmer's Almanac expert) were to whisper con-
spiratorily that next year you'd have 30.4 inches of rain, what would
you project for your bookstore sales next year?

Soothsay: Use your HP-42S to forecast your future sales based on


this "tip" about the rainfall.

Like So: You need to use the ForeCaST X and the ForeCaST Y
functions on your l!iII sub-Menu. If you enter an x-
value, and press !ME, you'll find out what they-value
would be, based on the regression equation.

So, key in your cousin's rainfall prediction and choose


!ME. Ikfilili: 267, 558. 38. Not bad!

Butwhatyoureallywanttoknowishowmuchrainyou'd
need to get to that magic sales plateau of $300,000.

Simple: ~lmiB: Result: 36, 56

"Hmm ...... maybe a branch store in Seattle .... "

Well, at least now you know how to use some of the built-in statistical
functions and tests on your HP-42S. As you can see, your calculator
does the hard part - accumulating the data - for you, so that you can
concentrate on choosing the correct test!

SOLVING PROBLEMS: Using Your Power Tools 349


SOLVER and Integrate:
Power Tools That Use Programs

Yes, you heard right. These final two power tools are really powerful,
because they allow-nay, require-you to customize them with (simple)
programs of your own.

To use~' for example, your program must calculate the function


that you want to integrate. To use~, your program must create
an equation. In both cases, these programs are actually very straight-
forward - far simpler than that MUSIC mess, for instance.

However, there are a few minimum requirements for these programs:


(

• Each must begin with a global label.


( I

• Each must make use of variable menus (recall pages 199-203 and
MVAR and VARMENU statements).

• Each should be as short and simple as possible - without ALPHA


messages, PROMPTs, or other instructions that stop or use the
display. These programs may be run many times over (like a loop)
as your HP-428 calculates with them; don't slow it down needlessly.

)
These rules aren't too tough, are they? All of the programming you
need here should seem quite easy to you (but if you do need to review
programming a bit, reread pages 173-209 now).

350 An EWIY Course In Using The HP-428

(
The llli!!)Menu

The~ Menu is used to calculate the definite integral of a function.

As you may (or may not) recall, the definite integral of a function is,
graphically speaking, an area or region, I, whose four "sides" are
defined by four things:

• The function, f(x), usually defines the "top side" of the region.
This "side" is usually not a straight line, but a curve of some sort.

• The x-axis (the horizontal axis on a graph) usually defines the


"bottom side" of the region.

• The Lower LIMit (LLIM) is a vertical line defining the left side.

• The Upper LIMit (ULIM) is a vertical line defining the right side.

So the graph of a typical definite integral might look like this:

LUM ULIM r

SOLVING PROBLEMS: Using Your Power TooZ. 351


Mathematically, the region of the definite integral is defined like this:

I= fuL1Mf(x) dx
LLIM

where the values of the two limits (LLIM and ULIM) appear on the
integral (f) sign, the function,f(x), follows that sign, and the variable of
integration, x in this case, is indicated by what follows the d.

All of this means that to calculate a definite integral on your HP-428,


you'll have to define for it:

• Afunction
• The limits of integration (LLIM and ULIM) (
• The variable of integration

Example: Use your calculator to solve this definite integral:

where a= 5 and n = 3.

Solution: First, you write a short program, using menu variables


and calculating the function,f(x) under the integral sign:

352 An Eaay Coune In Using The HP-428


To do this, of course, you must llfilQEB, then go into
Program Mode, •PRGM), to key in this new program:

01 LBL DISC11 11 The global label

02 Ml/AR "X" The three variables in the


03 Ml/AR "A" function are defined as menu
04 Ml/AR "N" variables.

05 RCL "X" This section actually calcu-


06 Xt2 lates the function. At the end
07 RCL "Au of line 14, the current value
08 Xt2 of the function will be sitting
09 - in the X-register.
10 SQRT
11 RCL 11N11
12 YtX
13 RCL "X"
14 x

That's it-you've written the program, so (EXJT)Program


Mode and select~ You'll see this message:

"Se 1ect .ff ( x) Pro gr ar•l''

You must now select which program ("function") you


want to integrate (since you might have had several
different functions stored in memory). Of course, you
have only the one, so choose UHi....

SOLVING PROBLEMS: U11ing Your Power Tool.II 353


Now you're told to "Set Vars; Select !var" and
you're shown a variable menu for the function DISC,
complete with variables, 11111. . . . and IEll.

Enter values for those variables you know: You know


that a= 5 and n =3, so key in (IJ . . @J IEll. Then you
press the menu key of your variable of integration - in
this case, x: 11111. As soon as you select your variable of
integration, you'll see this menu:

Next, you enter your limits. For this problem, your LLI M
is 7 and your ULIM is 12: GJmID Cil1)l!I!III.

Now, there's only one more item to deal with before you
can press . . to calculate the integral: You must use
llD to tell the machine how "accurate" you want the
result of your integral calculation.
)
"Don't I want it calculated as accurately as possible?"

Not necessarily.

The more accurate you want your result, the more time )
it will take your calculator. Besides, the limits you key )
in may already be approximations; you can't really ex-
pect an integral more accurate than the approximations
you're using to calculate it, right?

354 An Easy Course In Using The HP-428


Think of the Accuracy Factor as a tolerance for error:
Could you live with a 1% error in your answer or does it
need to be more like 0.01 %? In the first case, you'd use
0.01 as your Accuracy Factor; in the second, you'd use
0.0001.

Choose O.Ql for now, and key it in (press [TilD lia).


Then (finally!) press . . to calculate the integral.. ..

Result: 80, 820. 15

The . . function puts something in the Y-register, too:


This the uncertainty ofcomputation. Check it out: press
[x~y] and see that the uncertainty of computation for this
integration is 801. 57.

This means the final result could (and probably should)


be expressed as: 30,320.15 ± 301.57

So the actual ("exact") answer is somewhere between


30,018.58 and 30,621.72.

Try narrowing down the margin of error by keying in


0.0001 as the Accuracy Factor and then recalculating the
integral: ~ID . . .

Result: 80, 881. 29 ±([x~y)) 8. 08. Sure enough-your


error has been cut by a factor of a hundred- but it takes
a lot longer, doesn't it?

SOLVING PROBLEMS: Using Your Power Tools 355


Spikes, Asymptotes, And Other Beasties:
Know Your Limits!

The integration routine that you've just learned works very well for all
"well-behaved" smooth functions - and as long as you pay attention to
some of the basic rules for definite integrals.

Try This: Solve the same integral as the previous example, except
this time use different limits: LUM= 4 and ULIM = 7.

Solution: Just key in the new limits: G]mID[I)l!I!IIland press ....


to recalculate!. ..

... Aaargh! What beastie is this? "lnval id Type" ? )


What happened?
()
Well, when you changed the limits, you created a situ-
)
ation where your calculator was trying to take the
)
square root of a negative number: When x = 4, the
function is a complex number - a no-no within definite )
integrals. )

You need to stick to real numbers!


)

356 An Easy Course In Using The HP-428


And complex numbers aren't the only problems to watch out for....

Question: Why can't the HP-428 help you with this integral?

I= !.,.,, ~d.x
,.7
x-8

Answer: Within those limits, (x = 7 and x =12), there's a value


(x =8) where the function is undefined.

All definite integrals must use continuous functions


within the limits specified (in this case, the graph
clearly shows an asymptote at x = 8:). Since the
function is not continuous over this interval the HP-
428 will give you a wrong result.

·:;"- - - • · 8
~m
:t\~
: !~
:;
See? the area is unbounded at an asymptote, so a defi-
nite integral is undefined for this range-even though
the calculator will give you an answer. You must use
your mathematical insight to know it's "bogus!"

) SOLVING PROBLEMS: Using Your Power Tools 357

)
The other "bogies" to watch out for are the "spikes." Certain functions
that are real, continuous, and usually well-behaved still "go ballistic"
once in awhile,* varying enormously over very small intervals.

For Example: The graph of the function,fix) =x(2-'), has a sharp


spike between x = 0 and x = 2:

I )
x
...
10 100,000

(
Ifyou choose limits too far apart- such as x = 0 and
x = 100,000- the calculator will give you a mislead-
ing answer, because, in doing the integration, it se-
lects a number of sample points from within the (
limits you set. With too large a range, its sample (
points may "miss" the region with the spike-thus
grossly underestimating the area under the curve!

The only way to avoid this is simply to be sure you


know if your function has any steep spikes. And if /
you need to calculate and integral with a spike,
you might want to reduce your interval of integra-
tion and/or your Accuracy Factor (to allow for more
sample points within the interval).

*doesn't everybody?

358 An Easy Course In Using The HP-428


The •SOLVER] Tool

The •SOLVER) Menu works similarly to the ~Menu, except that


•SOLVER] uses your program as an equation rather than a function .

What's the difference? Well, with any algebraic expression-any com-


bination of variables, constants and operators-afunction is a process
that assigns values to the variables and then computes a single, unique
numeric result-called the "value ofthe function." For example, in your
function, DISC, its algebraic expression is x(./x2- a2) ~ The function
is the process that assigns a value to x, "plugs this into" the expression
and blindly computes the result- "the value of the function DISC at a
given x."

An equation, on the other hand, is a process that assigns this resulting


value of the function ahead of time, then "backtracks" to compute the
value of the variables necessary to produce that result. So to use the
above function as an equation, the machine would assign it a value,
then "backtrack" through the expression to compute whatx must have
been to produce that value!

So you see, the only difference between the assumptions of~ and
•SOLVER) is that •SOLVER) assigns a resulting value to the specified
function. And that assigned value is always zero.

"Hmm .. .But what if my function is already in the form of an equation


- and it's not equal to zero?"

No problem - you simply rearrange it: If you have 3.x2 + 4x = 35, for
instance, you could instead write this as 3.x2 + 4x - 35 =0 , ... right?
)
SOLVING PROBLEMS: Using Your Power Tools 359
Any equation can be rearranged so that it is set equal to zero. And
that's the strategy you must use when programming for the~-

Try This: Write a program for~ to solve for any variable in


the Ideal Gas Law: PV = nRT
where P = pressure of the gas
V = volume of the gas
n = number of moles of the gas
R = ideal gas constant
T =the temperature of the gas (in Kelvins)

Solution: First, rearrange the equation so that it is equal to zero:


PV - nRT = 0 Now write the program, complete with
a global label, menu variables, and the straightforward
"calculation-description" itself:
)
01 LBL 11 GAS 11 09 x
02 MVAR npn 10 RCL uNu
03 MVAR uvn 11 RCL "Ru
04 MVAR "N" 12 RCL "T"
05 MVAR "R" 13 x
06 MVAR "Tu 14 x
07 RCL 11 P11 15 -
08 RCL 11 V11

Once you've created a program for the equation you want to solve, you
can use •SOLVER] to solve for any one of its variables -after you key in
known values for the other variables.

360 An Easy Course In Using The HP-428


Try It: Use asoLVER] to find out what pressure a gas is under if
10.0 moles (n) of it are contained in a 8.2 Liters (V) jar at
a temperature (T) of273 Kelvins (O"C or 32°F). The Ideal
Gas Constant, R, is 0.0821 L-atm/mol-°K

Solution: [EXIT] Program Mode, then press asoLVER] to see the


menu of global labels and "Select Solve PrograM"
(choose l!rlHI, of course).

Next, you'll see a variable menu with all the variables of


the Ideal Gas equation. Just key in the known values:
(ill] IEllITT:m . .®fill . .c:rillllliJ . . . .
then press . . to solve for the unknown pressure.
~: 27.33 (atm.)

Not bad, eh? And there's no end to the "what-if' calculations you can
do once you have an equation programmed for asoLVER]!*

For Example: What pressure results if you raise the temperature to


300K? What temperature results if you maintain
pressure at 27.33 atmbut expand the gas to 12 liters?

Solutions:
CillEIIITJ. . (iliJ.....
0BQJ . . . . . Result: 30.04 (atm).
Ikfilill: 399 46 I (K)

*And remember (from page 203) that you can always press• and hold down a menu-key to see
what value is currently stored. This keeps you from getting lost when doing lots of"what-iffing.""

SOLVING PROBLEMS: Using Your Power Tools 361


What .SOLVER] Is Really Doing

As handy as •soLVER) sounds so far, you should also know that it gives
back a whole lot more information than just the answer. In fact, it fills
up the stack with information ....

As with~' ~works with a "mental" graph of a function,


such as the one shown below:
Reversals

Solutions

To the Solver, a "solution" occurs anytime the curve crosses the x-axis.
(After all, that's when the value of the function becomes zero-just as
your machine requires, right?)

The function illustrated above has two solutions - one somewhere


between -5 and 0, the other somewhere between 5and10.. ..hmmm ... so,
which solution will it give you when you use ~?

362 An Easy CouT7le In Using The HP·42S


Guessing The Answer:
Telling .SOLVER] Where To Look

Whenever you're working with an equation that has more than one
solution (or otherwise behaves strangely like this example graph), you
should enter two "guesses" as to the answer. Your machine will then
begin looking for an answer between those two guesses.

For Example: The equation x2 + x - 6 = 0 has two solutions. Use


your calculator to find them. (Hint: one solution
is positive, and the other is negative.)

Solution: First, enter the program for this equation:

01 LBL "TWO" 05 Xt2


02 MVAR 11 X 11 06 +
03 RCL X 11 11 07 6
04 ENTER 08 -

Now, (EXIT)Program Mode and press •sOLVER)lim


for the variable menu (. .is the only variable).

Key in two guesses, to suggest a "search area" for


a solution:@J. .0 . .. Now press . . (yep -
same key again) to find it: 2. 00.

Now, guess a range for the negative solution:


0]+1-) . .@+1-) . . and press . .again... .
Result: -3. 00

SOLVING PROBLEMS: Using Your Power Tools 363


Don't Be Misled By False Solutions

As you can tell from this previous example, just as with ~. you
have to know something about your functions to get reliable solutions.
It may take some exploration, and fortunately, the~ is particu-
larly handy for this exploration.

But you can still misinterpret the results if you aren't careful! There
are several types of situations that can lead the Solver to produce an
answer in the X-register that isn't exactly a solution!

If you refer back to the graph on page 362, you see the two most
common types illustrated there - Reversals and Extrema.

Your~ seeks solutions by repeatedly trying new values for the


variable it's solving for. It tries to make the result of each successive
trial closer and closer to zero. It figures that it has gone too far when
the result of one trial was a positive value but the result of the very next
trial was negative (or vice versa). It assumes that it just "crossed" the
x-axis between those two trial points and that the solution (also known )
in algebra class as a "root" or a "zero") is there somewhere in between.
It then narrows its search and quickly pinpoints the point that yields
up a zero value - and reports this as a solution.

The problem comes when the program encounters a Reversal point.


Reversals are typically caused by vertical asymptotes where one side
is increasingly positive and the other side is increasingly negative as
x approaches the asymptote. So your calculator can be fooled into re-
porting the asymptote value as a solution - even though the graph did
not actually cross the x-axis! Reversals are false solutions!

364 An Easy Course In Using The HP-428


A second type of false solution can occur when the calculator discovers
that the function is no longer looking like it will ever cross the x-axis.
This happens on the graph whenever the function "bends" in such a
way that values that had been getting more and more positive sud-
denly start getting more and more negative (or vice versa).

Each of these "bends" in the graph of a function occurs at anExtremum


Sometimes these Extrema are useful things to know - but they aren't
solutions to the equation, because the curve is not crossing the x-axis.

The Good News

You don't need to worry too much about these false solutions. Indeed,
you can use them to help you find out more about your equation.

This is because your HP-428 keeps you informed about what it's doing.

It tells you when it has encounted a "Si 9n Reversal " or an "Ext re-
MUM ". It also tells you when one or more of your guesses happen to be
impossible solutions (i.e. they tell the calculator to divide by zero or
some other impossible thing). In such cases, your machine will display
"Bad Guess<es) ".

Ifby any chance your equation yields the same value no matter what
trial value is used, your calculator will wonder, "Const ant?," suggest-
ing to you that your function is a constant (i.e. a number).

SOLVING PROBLEMS: Using Your Power Tools 365

I
Sometimes the answer in the X-register is actually less interesting
than what's in the other Stack registers. Every time you use •SOLVER],
all four Stack registers receive some part of the "answer:"

In the X-register is the "solution," of course - false or otherwise;

In the Y-register is the previous trial value - the "next best "solution.
Comparing this with the X-register gives you some idea about what the
"neighborhood" of the solution looks like.

In the Z-register is the value of the function when the "solution" is used
as a trial. Of course, if the solution is an exact solution, then the value
in Z should be zero (or very, very close to zero, in the case of irrational
number solutions).

In the T-register is a number - a integer between 0 and 4:


)

• 0 means: "There's a real solution in the x-register."

• 1 means: "The 'solution' in the x-register is more likely just the )


approximate location of a sign reversal (an asymptote, maybe)." )

• 2 means "The 'solution' in the x-register is more likely just the


approximate location of an extremum." (Remember that the )
value of the function at this extremum is stored in the Z-register). )

• 3 means: "One or more of the guesses caused an error during the


calculation; you should try some new ones."

• 4 means: "The function seems constant in this search interval."

366 An Easy Court1e In Using The HP-428


Test your understanding of.SOLVERf s behavior and of the information
it provides you:

Quizzette: Assume that your function has a graph like the one
below. For each of the following sets of guesses, what
type ofresponse will .SOLVER] give-solution, reversal,
extremum, bad guess, or constant?

1. -1 and 5
2. 10 and 19
3. 19 and 21
4. 5 and 35
5. 5 and 9
6. -8 and -10
7. 21and29
8. 5 and 19

. ....
n
..
....
..
SOL YING PROBLEMS: Using Your Power Tools 367
Solutiette: 1. Extremum. In this range, the calculator will dis-
cover the bump.

2. Bad Guess. 10 is an asymptote. The function is


undefined at x = 10.

3. Reversal. The asymptote atx= 20 is crossed here.

4. Bad Guess. The function is undefined at x = 35; the


asymptote at x = 30 limits the function
from getting out that far.

5. Solution. Finally! Make well-chosen guesses and


you'll arrive at a solution.

6. Extremum. This is called an asymptotic extremum


because the function gets closer and
closer to the x-axis without ever get-
ting there.

7. Extremum. This is a straight-forward example of


an extremum.

8. Solution? Assuming that it begins its search at


the first guess, 5, it'll arrive at a solu-
tion before any of the other beasties.

Moral Of The Story: Use your own knowledge of the function to


narrow down your search for solutions before using •SOLVER).

368 An Easy Course In Using The HP-428


Finally, did you know that you can solve an equation (using •SOLVER])
that includes an integration in it?

Hmm: Junior Beaver arrived home from Hydro Tech one spring, and
found his father all in a dither about ducks "ruinin' my dam
again! That's the third year in a row them ducks've landed on
th' pond so thick that the water level rose above my dam!"

Junior knew that something had happened the last few years
to flood the dam, but he had his doubts about this theory. "Pop,
how much does the water have to rise to cause a problem?"

"I always leave 'bout half a meter of "just-in-case" at the top.


It's hard to find enough building material to do more 'n that."

"Then I don't think the ducks could possibly be at fault. Let


me run some calculations to see," Junior suggested. He then
set out with his trusty HP-42S to test the validity of his
father's theory, taking these measurements:

• The surface of the pond - roughly rectangular - measured


70 meters by 13 meters.
• The pond was 3.5 meters deep (at its deepest) and trough-
shaped-like a tall tin can, halved lengthwise and laid flat.
• The average volume of a duck's bottom (d.b.) in water was
2.25 Liters and its area on the surface averaged (450 cm2 ). *

*For these sensitive and personal measurements, Junior Beaver wishes to thank several duck
acquaintances who prefer to remain anonymous. They know who they are.

SOLVING PROBLEMS: Using Your Power Tools 369


Then he derived the formula equating the total volume of n
ducks' bottoms, nvd.b. 'to the rise in the pond level:*

1ooof •·D·~ ((xi+ 4Dif) Acos( - _MQ_)- i{x2+ 4D2-8hD L J Jxi+ 4Di-4hD) dh
64D2 1 x 2 +4D 2 2\ 8D JV"\ D
A•D

L = length of the pond, x =the beginning width of the pond, h


= the actual maximum depth of the pond, D = the beginning
maximum depth of the pond (before ducks), and I = the
increase in pond level due to then ducks' bottoms.

But Junior had trouble using this formula with~ to


find h. Your job is to help him do this.

Hmm: You'll need two programs. The first one is for the function
under the integral (call it 11 POND 11 ):

01 LBL 11 POND 11 17 33 RCL "Hu


02 MVAR "D" 18 STO "R" 34 -
03 MVAR "X" 19 Xt2 35 x
04 MVAR "H" 20 RCL "L" 36 RCL "Ru
05 MVAR "L" 21 x 37 2
06 RAD 22 1 38 x
07 RCL "X" 23 RCL 11H11 39 RCL "Hu
08 Xt2 24 RCL "Ru 40 -
09 RCL "D" 25 41 RCL "Hu
10 Xt2 26 - 42 x )
11 4 27 ACOS 43 4
12 x 28 x 44 x )
13 + 29 RCL 11L11 45 SQRT
14 RCL "D" 30 2 46 x
15 8 31 47 -
16 x 32 RCL 11R11

•You probably want to take Junior's word for this - unless you, too, are an Eager Beaver!

370 An Easy Course In Using The HP-428


Then, to get an equation using this integral within a •SOLVER}
function, you need to rearrange it like this:

Thus, the asoLVERJ program for this would be:

01 LBL 11 8EAV 11
02 MVAR 11 W 09 PGMlNT 11 PON0 11 16 1000
03 MVAR 11 1/ 11 10 RCL 11 011 17 x
04 MVAR 11 011 11 STO 11 LLIM" 18 RCL 11 N11
05 MVAR 11 111 12 RCL 11 111 19 RCL 11 1/ 11
06 MVAR 11 X11 13 + 20 x
07 MVAR 11 L11 14 STO 11 ULIM" 21 X<>Y
08 MVAR 11 ACC 11 15 lNTEG 11 H11 22 -

This asoLVER] program is just like others you've seen except


for the instructions on lines 09 and 15. You'll find these when
you're in ~ Mode and you choose ~· You'll see a
menu with mrn:ll and two new options: rn:II and IIZm!I.

You use rn:II (at line 09) to tell your~ program which
other program you want to integrate. Then you use IIDIBJ to tell
your asoLVERJ program to actually begin the integration
using the specified variable as the variable of integration.

) The program lines 10-14 store the limits of integration, LLIM


and ULIM, and the ACCuracy factor. Remember that when a
program is used to do the integration, you need to have the
program store the limits of integration because you won't be
keying them in from the keyboard.

) SOLVING PROBLEMS: Using Your Power Tools 371


Junior wants to use his programs now to test his theory. First
he must figure out how many ducks can fit on the lake: The
total surface area of the lake is 9,100,000 cm 2 (70 m x 13 m).
Each duck occupies an average of 450 cm2 , so about 20,222
ducks - packed in like sardines - could fit onto the pond's
surface area.

Now, he presses .SOLVER] and chooses om. Then, he enters


the following values for his variables:

N = 20,222 ducks X = 13 meters


V d.b. = 2.25 Liters L =70 meters
D = 3.5 meters ACC =0.01

When he's finished with the entry of data, he solves for I - the
amount the water will rise due to the ducks- by pressing . .:

Result: 0. 01 (meters).

Junior grins triumphantly. Even ifthe pond were packed solid


with ducks, the water level would rise only about 1 centimeter,
not nearly enough to swamp his dad's extra 50 centimeters of
dam (in fact, even if all 20,222 ducks were to dive for food at the
same moment, this still wouldn't be enough to do it)!*

*It turned out, however, that the ducks weren't entirely blameless: After some further exploration,
Junior and his Dad discovered that the real problem was that his Dad was building his dam each
year on a deeper and deeper layer of duck droppings accumulating on the bottom of the pond. The
droppings were not as firm a base as the actual pond bottom, so the dam was settling and slipping
a little more each year. By pure coincidence, the resulting swamping happened around the same
time as the annual arrival of the ducks.

372 An Easy Course In Using The HP-428


Powerful Problems

1. Using the~ Menu, find the HEXadecimal solution to the


following:
16D316-7143s _ 61 :?
100100i 10 · 16

2. Can you use the m:mlfunction in the ~Menu to solve a


system of 6 equations in 5 variables? How would you go about it?

3. Your calculator has built-in statistical analysis functions only for


two-variable regressions. How could you make it do "multivari-
ate linear regression" to analyze data with more than two vari-
ables (say, 4 independent variables and one dependent variable)?

4. The volume of the intersection of a sphere with a radius of 6 cm


and a cone with an aperture angle of1t/3 can be found by solving
the following: Mp

v = f,.If P-

p•O
6
p 2 sinlf> dp dlf> de

,.o
9·0

Find the volume of this intersection using the power of~-

5. Find all six real roots of this polynomial:

x!'-45x5 -447x4 + 4293x3 + 1782.x2- 29952x-27040 =0

SOLVING PROBLEMS: Using Your Power Tools 373


Powerful Solutions

1. The sequence of keystrokes: ~IIOOWGTI]m.ill!m@J[EXIT)


OOII lIOlillB lm!llffilliIDill)EJ lllmCiliB lllJlllJ.
Result: FFFFFFFFF

2. Yes, but you want to ignore one of the equations. Remember from
page 319 that mm calculates a solution matrix with matrix di-
vision, which involves an inversion of a matrix, and - as you
learned back on page 152, only square matrices can be inverted.
This means that you can use mm only for systems that have
matching numbers of equations and variables.
(

3. As you remember (page 345 ), the linear regression model for one
(
independent variable and one dependent variable is y =a+ bx. If
there were four independent variables, the regression equation
becomesf=a+ bx+cy+dz+ew wherefis the dependent variable, (
x, y, z, and w are the independent variables, and a, b, c, d, and e
are the coefficients of regression.

So how do you solve one equation in five variables?

Obviously, you can't. But by combining the powers of your~


and •MATRIX] power tools you can transform this one equation
into a system of five equations in five variables.

The idea is to create a single matrix equation of the type AX= B.

374 An Easy Course In Using The HP-428


You need to accumulate, using the STATistical registers, various
values and then store them in MATA and MATS so that the matrix
equation looks like this:
n Ix LY Iz LW It
Ix I(x2) LXJ Ixz LXW Itx
LY
Iz
Iw
LXJ
Ixz
LXW
L (yZ)
LYZ
LJW
LYZ
I (z•l
Izw
LJW
I zw
I(w2)
rn IIY
= It
Itw
1

The coefficient of determination, which tells you how good a fit


your regression equation is, can be calculated with this formula:

R 2 = aIJ +bL,fx +cL,Jy +dL,fz +eL,fw -!z{L,!)2


L. v2l -MI 1)2
All of this can be done by combining the power of the STATistical
registers and the matrix math.

Of course, the best way to do this is to write a program. You could


then use it to: enter data, accumulate it into statistical registers
(and others, too), create the matrices, use mml to solve for the
"solution matrix," and calculate R2 automatically. And since it's
a program, it would allow you to use prompts and menus to keep
everything straight.

This is just one example of how programming can vastly extend


the power of your power tools. Indeed, there are few problems
) that are totally beyond the abilities of your calculator - as long
as there is enough memory available for the problem.

SOLVING PROBLEMS: Using Your Power Tools 375


4. The triple integral can be solved with a series of small programs.
First, rearrange the integral for a clearer order of calculation:

Your program needs to calculate the innermost integral first, use


this result as a constant in the next integral, calculate the second
integral, and use that result a constant in the final integral. Of
course, you need to make sure that the correct limits are stored
before each integration. Note: In order to calculate a multiple
integral, you must not use~- If you try to use~, you'll
get the message "Int eg (Int eg)" which is your calculator's way
of telling you that it doesn't do windows.

The program, TRIPI, calculates this triple integral by calling up


integration subroutines three separate times.*

Integration Subroutines:

01 LBL 11 RH0 11 01 LBL 11 PHI 11 01 LBL 11 THETA 11


02 MVAR P 11 11 02 MVAR Q 11 11 02 MVAR H 11 11

03 RCL P 11 11 03 RCL P 11 11 03 RCL Q 11 11

04 Xt2 04 RCL Q 11 11

05 SIN
06 x

*This basic format could be used to find any triple integral - all that you'd need to change would
be the specific integration subroutines (RHO, PHI, and THETA) and the limits of integration in the
mrun program so that they match the new problem.

376 An Easy Course In Using The HP-428


Main Program:

01 LBL "TRIPI" 15 STO "P"


02 MVAR "RADIUS" 16 PGMINT PHI"
08 MVAR "ANGLE" 17 RCL "ANGLE 11

04 VARMENU "TRIPI" 18 STO "ULIW


05 STOP 19 INTEG "Q"
06 RAD 20 STO "Q"
07 PGMINT "RHO" 21 PGMINT THETA"
11

08 0 22 PI
09 STO "LUM" 28 2
10 RCL R"
11 24 x
11 STO "ULIW 25 STO "ULIM"
12 0.01 26 INTEG "H"
18 STO "ACC" 27 STO "VOLUME"
14 INTEG "P" 28 VIEW "VOLUME 11

First, you input the radius of the sphere and the aperture angle
of the cone (and line 06 puts into RADian mode). Then you call
11 RHO 11 and store the limits of the first integration and the AC Cu-

racy factor (0.01) to be used throughout the problem.

After the first integration, the result is stored in "P", to be used


in the next integration. Then a new upper-limit is stored (the
lower limit and accuracy factor remain the same), and the result
of the second integration is stored in "Q". Again, the upper-limit
for the next integration is changed (to 27t), and 11 THETA" is inte-
grated. Finally, the answer is stored and viewed as 11 VOLUME 11 •

Now press [XEO] mm(!) li!mII!I ti@E l'lifill] [RIS), to calculate the
triple integral:

Answer: VOLUME=226. 22 (cm3 ).

SOL YING PROBLEMS: Using Your Power Tools 377


5. The trick in this problem is to be systematic in your search for
multiple solutions, using whatever shortcuts you can remember
from your algebra class. First, of course, you need to write the
program for this polynomial equation:

01 LBL 11 POLY 11 13 4 24 RCL 11 X11


02 MVAR 11 X11 14 YtX 25 Xt2
03 RCL 11 X11 15 447 26 1782
04 6 16 x 27 x
05 YtX 17 - 28 +
06 RCL 11x11 18 RCL 11x11 29 RCL 11 X11
07 5 19 3 30 29952
08 YtX 20 YtX 31 x
09 45 21 4293 32 -
10 x 22 x 33 27040
11 - 23 + 34 -
12 RCL 11x11

Now, before actually trying to find the solutions, you should see
what information you can glean from the equation to help you
narrow your search somewhat:

• According to Descartes' Rule of Signs you can expect either 1


or 3 positive and either 1 or 3 negative real solutions.

• Values for x lower than the lowest solution yield will positive
y-values. And values for x higher than the highest solution
will also yield positive y-values. This is a property of polyno-
mials of even degree (in this case, the degree is 6), whose
highest-degree coefficient is positive in sign (the .x6term has a
positive coefficient).

378 An Eaay Course In Using The HP-428


Now begin your search: •sOLVER)UJ!igets you to the variable
menu. Enter your two guesses, then press . . to begin the
search for solutions (when entering guesses with no good idea
where to begin or what the graph looks like, it's a good idea to use
the same number for both guesses. Here is one suggested search-
ing sequence. Of course, you can use any method you want):

Guesses Interpretation

0,0 - 1.00 Press @lfil®J to see a 0. 00 in the T-


register, so this is a true solution.

1, 1 - 2. 00 Again, confirm that this is a root. Now,


from Descartes Rule of Signs, you know
there must be a third negative root.

2,2 4. 00 A positive root!

8, 8 5. 00 A second positive root! There's a third


positive root, too! Notice that when
x=8, the sign in the display is negative,
so the next root is greater than 8.

64,64 52. 00 That's it! Now find the negative one.

-4, -4 - 2. 00 Nope -you have that one already!

-16, -16 -13. 00 Ahhh! There it is - the sixth root.

In sum, the roots are: -13, -2, -1, 4, 5, and 52.

SOLVING PROBLEMS: Using Your Power Tools 379


Foundation Completed
'The Book Stops Here"

That's about it- the end of the Easy Course, the tools put away - for
now. But you have only just begun. You've just finished your
apprenticeship and become a fully-trained HP-428 tinkerer.

But of course, it doesn't mean you've seen it all. As we said at the start,
this book doesn't cover all of the many uses of your machine. For
example, here are a couple of topics you can now explore on your own:

• Display graphics;

• Printer operations;

Of course, most of the topics you did cover in this Easy Course have
plenty more exciting functions and variations to try. Explore them -
enjoy them - and get the most out of your HP-428!

How Did You Like This Book?

Do you find yourself wishing we had covered other things? More of the
same things? Did any mistakes, typos, or other little mysteries leap
out and grab you by the lapels? Please let us hear from you. Your
comments are our only way ofknowingwhether these books help or not
- and we always read our mail!

Grapevine Publications, Inc.


P.O. Box 118
Corvallis, Oregon 97339-0118 U.S.A.
Here are other great books
HP-28S Software Power Tools HP-28S Software Power Tools
Utilities Electrical Circuits
Whether or not you're experienced with the Here's the solutions books you've been wait-
HP-28S, you'll find this book to be a great ing for! First, you build a friendly and easy-to-
collection of advice, good habits and sound edit description ofyour circuit, which may have
programming principles. any of the following elements in series or in
parallel:
• Directory Manipulation
• Display Formtting • Resistors • Capacitors
• Graphics/Plotting • Inductors • Impedences
• General Object Manipulation • Independent voltage sources
• Printer Manipulation • Independent current sources
• Program Development
• Sorting/Searching You can do either mesh or nodal analysis,
construct general networks or ladders, and use
Learn clear, clean and convenient methods a host of small utility routines to do side calcu-
for arranging and namingthe objects and clirec- lations as you wish. And naturally, you can
tories in your HP-28S's memory, so that as you vary the frequency of your sources and plot
gather tools and routines, "there's a place for results, either on the display or the infrared
everything-and everything in its place." printer. Every routine is explained, and every
piece of the program is documented!
(
(
An Easy Course In Using The HP-28S Here's a list of all our other books:
(
If you're looking for a clear, straightforward • An Easy Course In Using The HP-22S
explanation of the powerful HP-28S, then this • An Easy Course In Using The HP-27S (
is your book! Authors Loux and Coffin sort • An Easy Course In Using The HP-19B
through the myriad features of this machine,
giving you the pictures and the practice you
• HP-19B Pocket Guide: Just In Case (
• An Easy Course In Using The HP-17B
need to make the HP-28S your favorite calcu- • HP-17B Pocket Guide: Just In Case
lating tool.
• An Easy Course In Using The HP-12C
• HP-12C Pocket Guide: Just In Case
You'll learn about this and more:
• An Easy Course In Programming The HP-41
• An Easy Course In Programming
• The Display • Menu keys
• Posting Memos • Keyboards The HP-llC and HP-15C
• Real Numbers • Flags • The HP Business Consultant Training Guide
• Strings • Lists • Using Your HP-41Advantage
• Complex Numbers • Matrices Statics For Students
• Algebraic Objects • Vectors • An Easy Course In Using The HP-16C
• Programs
• User Defined Functions

Grapevine Publications, Inc.


P.O. Box 118
Corvallis, OR 97339-0118
To Order:
Call our Toll-Free Line for the location of the GPI dealer nearest you, OR
Charge the books to VISA or Mastercard, OR
Send this Order Form to: Grapevine Publications, P.O. Box 118, Corvallis, OR 97339
copies of An Easy Course In Using The HP-42S ............ @ $22.00 ea.= $ _ __
copies of An Easy Course In Using The HP-32&........,..,.., @ $22.00 ea.= $ _ __
copies of An Easy Course In Using The HP-22S ............ @$22.00 ea.= $ _ __
copies of An Easy Course In Using The HP-19B ............ @$22.00 ea.= $ _ __
copies of The HP-19B Pocket Guide: Just In Case ..... @$ 5.00 ea.= $ _ __
copies of An Easy Course In Using The HP-17B ............ @$22.00 ea.= $ _ __
copies of The HP-17B Pocket Guide: Just In Case ..... @ $ 5.00 ea.= $ _ __
copies of The HP Business Consultant Training Guide (18C) @$22.00 ea.= $ _ __
opies of An Easy Course In Using The HP-12C ............ @$22.00 ea.= $ _ __
copies of The HP-12C Pocket Guide: Just In Case ..... @$ 5.00 ea.= $ _ __
copies of An Easy Course In Using The HP-28S ............ @$22.00 ea.= $ _ __
copies of HP-288 Software Power Tools: Utilities"""'"''-,._.., @$18.00 ea.= $ _ __
copies of HP-288 Software Power Tools: Electrical Circuits.. @$18.00 ea.= $ _ __
copies of An Easy Course In Using The HP-27S ............ @$22.00 ea.= $ _ __
copies of An Easy Course In Programming The HP-41.. @$22.00 ea.= $ _ __
copies of Computer Science on Your HP-4lcu•nrAdY~tq.J ....... @$15.00 ea.= $ _ __
copies of Using Your HP-41 Advantage: Statics·---···· @$12.00 ea.= $ _ __
copies of An Easy Course In Programming The HP-11C&l5C @$22.00 ea.= $ _ __
copies of An Easy Course In Using The HP-16C ............ @$22.00 ea.= $ _ __

(Prices valid through February 5, 1990) Subtotal = $ _ _ _ __


SHIPPING INFORMATION:
For orders less than $10.00 ADD $ 1.00 $ _ _
or
For all other orders - Choose one:Post Office shipping and handling .... ADD $ 2.50 $ _ _
(allow 2-3 weeks for delivery) or
UPS shipping and handling............... ADD$ 3.75 $ _ _
(allow 7-10 days for delivery) or
International Mail Surface Post $4..50 .....- ......---·-----··.... ADD $ 4..50 $ _ _
(allow 6-8 weeks for delivery)
Air Parcel (P1eaae contact u.e forCOTTect amount or add $10 per book t.o Canada and :\iexico. Add $2 5 per book
to all other countriee. We ....;11 refund any caah exceu, ar cha~ exact 1hipp1ng C'Olt to credit cards. Allow 2 -3 week.I delivery)

TOTAL AMOUNT: -------------------------> $_ _ __


PAYMENT:
Your personal check is welcome. Please make it out to Grapevine Publications, Inc. OR
(/numational CMck or MonJry Ord.r must be in U.S funds and drown on a U. S bank)

Your VISA or MasterCard#:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Exp. date:_ _ __


Your signature:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Phone: ( )
Name _ _ __ __ _ _ _ _ _ _ _ _ _ __ _ _ _ _ __ _ _ _ _ _ _ __
Shipping Address - - - - - - - - - -- -- - - - - -- - - - - - - -
<Note: UPS wtll not deiiYtt to • P.O. Bold Plaue ('!Te• llreet addni• ror UPS deliTel'JJ

City _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ State _ _ _ __ Zip_ _ _ _ __

For Orders Only


call: 1-800-338-4331
(In Oregon 754-0583)
l .,
Reader Comments
We here at Grapevine love to hear feedback about our publications. It helps us
write books tailored to our readers' needs. If you have any specific co=ents or
advice for our authors after reading this book, we'd appreciate hearing them!

Which of our books do you have?

Comments, Advice and Suggestions:

May we use your comments as testimonials?


Your Name: Profession:
City, State where you live:
How long have you had your HP calculator?

Please send Grapevine Catalogs to the following people:

City _ _ _ _ _ _ _ _ _ _ _ _ _ __ State Zip

and
Name _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ~

(J
Address _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ~
u
City _ _ _ _ _ _ _ _ _ _ _ _ _ __ State Zip

J
)
)
..

0 . ~. __ .

('
('
('
c

c
('
c
(
c
(

c
c
c
c
(

c
(
c
.
Coffin (
Coffin
Bloch
An Easy Course In Using The HP-428
(

This cover flap is handy for several If you have an HP-42S, you can do a lot, right? "Right!" c
different things: (
-Tuck it just inside the front Calculate a hairy triple integral? "[can do that!" (
cover when you store this book ~ Solve a system of 6 linear complex equations? "I can do that!"
on a shelf. That way, you can (
see the title on the spine. Customize your HP-42S menus, just for you? "[can do that!"
l
- Fold it inside the back cover -
out of you way- when you're .. .How am I going to do that? (
using the book. (
- Use it as a bookmark when you Take this Easy Course on the HP-42S. It'll show you how!
take a break from your reading!
First, you'll read about math and functions, the Stack, the
CUSTOM menu and each of the variable types (real/ALPHA,
Complex and Matrix). Then you'll learn to program the HP-
42S and use its built-in application tools to solve tough
problems with ease and understanding.

All this -with diagrams and examples, quizzes and solutions


-in Grapevine's inimitable style and clarity. It's amazing how
the right explanation can turn a complex machine into a
powerful and friendly tool!
ISBN 0-931011-26-4
(
(

~lifE~~ (
.... (~lltViwE 1'.$ucJ\noMS, INC,
P.O. Box 118 • Corvallis, Oregon 97339-0118 • U.SA • (503) 764-0683

HP Part# 92206M

GRAPEVINE

You might also like