Professional Documents
Culture Documents
Mathematical Applications
Step-by-Step Solutions
for Your HP-28S Calculator
r/iiiW HEWLETT
~~ PACKARD
The programs that control your calculator are copyrighted and all rights
are reserved. Reproduction, adaptation, or translation of those programs
without prior written permission of Hewlett-Packard Company is also
prohibited.
Corvallis Division
1000 N.E. Circle Blvd.
Corvallis, OR 97330, U.S.A.
Printing History
... to the HP-28S Solutions Books. These books are designed to help you
get the most from your HP-28S calculator.
Before you try the examples in this book, you should be familiar with cer-
tain basic concepts from the owner's documentation:
• The basics of your calculator: how to move from menu to menu, how
to use the graphics capabilities, how to edit expressions and equa-
tions, and how to use the menu to assign values to, and solve for, user
variables.
• Entering numbers, programs, and algebraic expressions into the
calculator.
Please review the section, "How To Use This Book." It contains impor-
tant information on the examples in this book.
Welcome... 3
Contents
11 How To Use This Book
14 How This Book Is Organized
14 Program Entry and Listings
14 PSUB (Polynomial Subtract) Main Program
16 Entering Programs
18 Using SYSEVAL
2 26 Polynomial Arithmetic
27 Instructions
27 Conversion to List Form
28 Conversion to Polynomial Value
29 Entering Coefficients
30 Examples
Contents 5
31 Programs
31 PADD (Polynomial Add) Main Program
32 PSUB (Polynomial Subtract) Main Program
33 PMULT (Polynomial Multiply) Main Program
34 POIV (Polynomial Divide) Main Program
6 Contents
5 60 Numerical Solutions to First-Order
Differential Equations
60 Algorithms
61 Instructions
62 Example
63 Programs
63 DEI (First-Order Differential Equation) Program
64 Yll (First-Order Y Increment) Subroutine
7 70 Coordinate Transformations
71 Algorithms
71 Instructions
73 Examples
76 Programs
76 SETX (Set up Transform) Main Program
77 --NEW (Compute New Coordinates) Main Program
77 ->OLD (Compute Old Coordinates) Main Program
78 XFMS (Transformation) Subroutine
8 79 Curve Fitting
79 Algorithms
80 Instructions
82 Examples
Contents 7
84 Programs
84 CFU1 (Curve Fit 1) Utility
85 CFU2 (Curve Fit 2) Utility
85 LINC (Linear Curve Fit) Subroutine
86 EXPC (Exponential Curve Fit) Subroutine
86 PWRC (Power Curve Fit) Subroutine
87 LOGC (Logarithmic Curve Fit) Subroutine
87 PLOT (Curve Plot) Subroutine
88 POINT (Accumulate Point) Subroutine
88 DEL (Delete Point) Subroutine
89 BEST (Best Fit) Subroutine
9 90 Triangle Solutions
91 Algorithms
91 SSS (3 Sides)
91 ASA (2 Angles and Included Side)
91 SAA (Side, Adjacent Angle, Opposite Angle)
92 SAS (2 Sides and Included Angle)
92 SSA (2 Sides and Adjacent Angle)
92 Area
92 Instructions
94 Examples
97 Programs
97 TU1 (Triangle 1) Utility
98 TU2 (Triangle 2) Utility
98 TU3 (Triangle 3) Utility
99 Computation Subroutines
99 ---->SSS (Compute SSS) Subroutine
100 ---->ASA (Compute ASA) Subroutine
100 ---->SAA (Compute SAA) Subroutine
101 ---->SAS (Compute SAS) Subroutine
101 ---->SSA1 (Compute SSA) Subroutine 1
102 ---->SSA2 (Compute SSA) Subroutine 2
102 Main Programs
102 SSS (Side-Side-Side) Main Program
103 ASA (Angle-Side-Angle) Main Program
103 SAA (Side-Angle-Angle) Main Program
8 Contents
104 SAS (Side-AngIe-Side) Main Program
104 SSAI (Side-Side-Angle) Main Program 1
105 SSA2 (Side-AngIe-Side) Main Program 2
105 AREA (Triangle Area)
Contents 9
How To Use This Book
Please take a moment to familiarize yourself with the formats used in this
book.
!ENTERl
ll~~i
~T6 1
i ARRAyi
ifbOrl
~~~-:-EL~ j
Key: Description:
Menus typically include more menu labels than can be displayed above
the six, redefinable menu keys. Press INEXT Iand IPREY Ito roll through the
menu options. For simplicity, INEXT Iand IPREY Iare not shown in the
examples.
To solve for a user variable within ~ SOLVR ~, press the shift key, followed
by the appropriate user-defined menu key.
Some keys cause the display to show different characters than are on the
key.
Key: Display:
~ *
[±] /
[lli] INV
[2] SQ
Idjdx l a
~ ,;
Interactive Plots and the Graphics Cursor. Coordinate values
you obtain from plots using the [INS] and IDEL Idigitizing keys may differ
from those shown, due to small differences in the positions of the graphics
cursor. The values you obtain should be satisfactory for the Solver root-
finding that follows.
-5
-12345.678
[[-1, -2, -3 [-4, -5, -6 [
51cHSI
12345.678 [cHs l
[ [ 1 [CHS I , 2 ICHS I ,
The examples in this book typically display a format for the number of
decimal places. If your display is set such that numeric displays do not
match exactly, you can modify your display format with the [MODE Imenu
and the ~ FIX ~ key within that m e nu. For example, to set the calculator to
display two decimal places, set it to FIX2 mode by pressing [MODE 12
~ FIX ~.
The HP-28S automatically inserts spaces around each operator as you key
it in. Therefore, using the ~ , B,
and [gJ keys to enter the R-+C com-
mand will result in the expression R -+ C and, ultimately, in an error
in your program. As you key in programs on the HP-28S, take particular
care to avoid spaces inside commands, especially in commands that
include an -+.
User Menus. If you do not purge all the programs and variables after
working each example, or if your [USER I menu contains your own user-
defined variables or programs, the I USER I menu on your calculator may
differ from the displays shown in this book. Do not be concerned if the
variables and programs appear in a slightly different order on your [iJ"SEBJ
menu; this will not affect the calculator's performance.
Arguments Results
2: { coefficients 1 } 2:
1: { coefficients 2 } 1: { difference }
Program: Comments:
«
LIST-. -. n n = number of terms.
« 1 n
START NEG n ROLL Negate each term.
NEXT
n -.LIST PADD
»
»
I ENTER I
'PSUB' @ O] Store program.
The program type is given after the program name and description
and will be one of the following:
Entering Programs
The programs for each of the applications are listed at the end of each
chapter. You may enter all of the programs into the HOME directory.
However, we recommend that you take advantage of the HP-28S directory
system to organize USER memory to provide easy access to the groups of
programs. For example, in the HOME directory, create a directory
named MATH to hold all of the programs listed in this book. Then,
switch to the MATH directory, and create individual subdirectories for
each application. Suggested names: TRI (triangle solutions), POLY
(polynomial operations), DEQ (differential equations), XFM (coordinate
transformations), and FIT (eurve fitting). Enter all of the triangle pro-
grams into the TRI directory, the polynomial programs into the POLY
directory, and so forth.
Most of the main programs are independent, so you can save memory by
only entering the main programs you need for a specific purpose. For
example, in the Curve Fitting application, you may only wish to use
exponential curves, so you don't need to enter the programs for linear,
power, and logarithmic curves.
Instructions
{an an - 1 ... a 1 a0 }
"
Names in the original object algebraic (except for the poly-
nomial variable name) are evaluated during execution of
Note PCOEF. To prevent substitution of current values for those
names, you should purge the corresponding variables.
Entering Coefficients
Enter the coefficients of the polynomial as a list containing from two to
five real or complex numbers. The number of elements in the list deter-
mines the order of the polynomial:
linear { al ao}
quadratic { a2 al ao}
cubic { a3 a2 al ao}
quartic { a4 a3 a2 a 1 ao}
• If you wish to save the polynomial coefficients for later use, store the
list in a variable, for example, = DUP = 'COEF' l§iQJ.
• Press ~_,=--ROOT :::0:. PROOT returns one, two, three, or four real or
complex roots to the stack, depending on the order of the polynomial.
• To evaluate the polynomial at a particular value of the independent
variable, enter the coefficient list then the variable value (list in level
2, variable value in level!), then press :::0: PVAL ~ or ~U:>§ERS :::0:. PVAL
and PSERS will accept symbolic coefficients and variable values, as
well as real and complex numbers.
{A B C 0 -10}
'ENTER 1
11:
.::..
.-.·
{ ABC (1 -1';:1 )!
I
'-
~~~ImIlIIfimI"B1!II1
i~ _1!l!liIJ~~1mIlI1fim1l!la
___ _ _____ __,___ -----.11
Arguments Results
3: 'expression' 3:
2: 'variable name' 2:
1: n 1: {an'" a o}
Program: Comments:
lsi NARY I
~-----.-
~-rHEX·~
- --~-- ---
«
3 DUPN TYPE SWAP
TYPE ROT
TYPE 3 -LIST {O 6 9} Check argument types.
IF ==
THEN DUP 1 + - n Saven+l as n.
« #C53Bh SYSEVAL
SWAP
#33017h SYSEVAL
#59B5h SYSEVAL
#38104h SYSEVAL
DROP #5973h SYSEVAL Put coefficients on stack.
1 n
FOR m m ROLL COLCT
NEXT Collect terms and reverse
coefficients.
n -LIST Make coefficient list.
»
END
»
[g~TERJ
I PCOEF I [§iQ:1 Store the program.
Program: Comments:
«
----> st x Save list and value as temporary
variables.
« st 1 GET 2 st SIZE Set up iterations.
FOR n x * st n GET + Multiply each term by x and add ai.
NEXT
» »
~~rfER I
'PVAL' i _~i5J Store the program.
Program: Comments:
«
----> X Save value as a temporary variable.
« LIST----> 0 SWAP 1
FOR n n 1 + ROLL Get the nth coefficient.
x n 1 - A * anx
+ Add to the expression.
-1 STEP Iterate.
» »
~ NTERj
'PSERS' ilii9l Store the program.
26 2: Polynomial Arithmetic
Instructions
{an an -l ... a 1 a 0 }
w
Note
Names in the original object algebraic (except for the poly-
nomial variable name) are evaluated during execution of
PCOEF. To prevent substitution of current values for those
names, you should purge the corresponding variables.
2: Polynomial Arithmetic 27
Conversion to Polynomial Value
After an operation is complete, you can convert the list representation of
the result into an algebraic expression or a numerical value.
1. Place the coefficient list in level 2 and the variable name or value in
level 1:
2: { an ... ao }
1: X
2. Execute PVAL or PSERS. (Refer to chapter 1.) PV AL returns the
value of the polynomial
28 2: Polynomial Arithmetic
Entering Coefficients
Enter the coefficients of the polynomial as a list containing from two to
five real or complex numbers. The number of elements in the list deter-
mines the order of the polynomial:
linear { a 1 aO}
quadratic { a2 al aO}
cubic { a3 a2 al aO}
quartic { a4 a3 a2 al aO}
• If you wish to save the polynomial coefficients for later use, store the
list in a variable, for example, ~ DUP-~ , COEF' [-STQj.
• Press ~ PROOT ~ . PROOT returns one, two, three, or four real or
complex roots to the stack, depending on the order of the polynomial.
• To evaluate the polynomial at a particular value of the independent
variable, enter the coefficient list then the variable value (list in level
2, variable value in levell), then press == PVAL == or '= PSERS =. PVAL
and PSERS will accept symbolic coefficients and variable values, as
well as real and complex numbers.
2: Polynomial Arithmetic 29
Examples
Example 1. Add the polynomials x 2 - 1 and 2x 3 + 4x + 3.
{I 0 -1 1 £~~EBJ 1:2:
! 1:
{ 1 0 -1
{ 2 0 4 3
}I
}i
{2 0 4 3 [~!iTERl It:m3jDHllm:J.!I!lfi!lImBI_1
l' _ _ ___ __ __ _ __ _ .. ___ ! ~ ~
2:
11: { 2 1 4 2 }I
I ~DHllm:J.!I!lfi!lImBI~i
The result is 2x 3 + x 2 + 4x + 2.
1.-.·
It;
I
}i
t:m3jDHllm:J.!I!lfi!lImBI_
{ -1 1 4 1
I
The result is - x 3 + X + 4x + ].
30 2: Polynomial Arithmetic
Multiply the polynomials.
[USER] = PMUL =
~f~: {2 0 2 2 -4 -2
l~
!lm)1m'I1m!I)1Ii!II1IilD~
The result is 2x 5 + 2x 3 + 3x 2 - 4x - 2.
[ 2:1:
ICLEAR I ~
- :IB-~- ~-~--~
----
{1 1 1 [ENTER I { 1 1 1 }
{ 1 -1 }
{1 -1 ~ NT@] !lm)1m'I1m!I)1Ii!II1IilD_
1: {1-1}]
!lm)1m'I1m!I)1Ii!II1IilD_
!L_ _ _ _ __
~ _ __
~ _ _ _ _ _ __
Programs
Arguments Results
2: { coefficients 1 } 2:
1: { coefficients 2 } 1: { sum-coefficients}
2: Polynomial Arithmetic 31
Program: Comments:
«
DUP2 SIZE SWAP SIZE
IF > THEN SWAP END Put longer list in level 2.
LIST~ DUP 2 + ROLL
LIST~ DUP 2 + ROLL Dump lists on stack.
~ g s Save lengths of lists as g (long) and s
(short).
« 1 g
FOR n n s
IF ::;
THEN g 1 + ROLL + Add each pair of terms until short
list is exhausted.
COLCT
END
g ROLLD
NEXT
g ~LIST
»
»
iENTER:
, PADD'STOi Store the program.
Arguments Results
2: { coefficients 1 } 2:
1: { coefficients 2 } 1: { difference}
Required Program:
• PADD
32 2: Polynomial Arithmetic
Program: Comments:
«
LIST-> -> n n = number of terms.
« 1 n
START NEG n ROLL Negate each term.
NEXT
n ->LIST PADD
»
»
[gfJTER i
, PSUB ' I STO I Store the program.
k =n +m
k
Ck = L,aibk - i'
i=O
Arguments Results
2: { multiplicand} 2:
1: { multiplier} 1: { product}
Required Program:
• PADD
Program: Comments:
«
DUP SIZE ROT DUP
SIZE DUP 4 PICK
IF >
2: Polynomial Arithmetic 33
THEN 4 ROLL 4 ROLL
END Order as 4: long list; 3: long size; 2:
short list; 1: short size.
-+ g g5 5h 5
« { } 1 5 Start empty result list.
FOR 55 g LIST-+ 1
SWAP
START 5h 55 GET * gs
ROLL
NEXT Multiply each clement of L by the ss
element of S.
1 5 S5 - DUP2
IF ~ Justify the list.
THEN START 0
NEXT
ELSE DROP2
END
g5 5 5S - + -+LIST Add the list to the result list.
PADD
NEXT
»
»
[ENTER]
, PMULT' ISTO I Store the program.
The first term Cn -m is an Ibm . After this term is computed, a new divi-
dend C' is computed, where C' =A -cn -mB . The next quotient term
Cn -m -1 is then computed in the same manner from C', and the process is
repeated for each of the II terms of A. The remainder is the dividend that
results at the end of the process.
34 2: Polynomial Arithmetic
Arguments Results
3: 3: { quotient}
2: { dividend} 2: { remainder}
1: { divisor} 1: { divisor}
Program: Comments:
«
DUP 1 GET OVER SIZE
-+ d t n Save divisor, top-order term of divi-
sor, and number of divisor terms.
« SWAP DUP SIZE
{ }
n - 1 +
1 SWAP
START From 1 to n -m + 1 (m = number of
dividend terms) ...
DUP 1 GET t / COLCT Divide leading term by t.
ROT OVER 1 -LIST + Append result to quotient list.
3 ROLLD 1 n
FOR m Subtract the result * divisor from the
dividend ...
OVER m GET d m GET
3 PICK * - ROT
m ROT PUT SWAP
NEXT
DROP 2 100 SUB Throwaway the leading term.
NEXT d Repeat.
»
»
[ENTER]
I ' ~ - ---'
flx 3x3~2><+1
L\\v8, {3
". l'
0 2.
l' l'
q 2: Polynomial Arithmetic 35
xl )C:t. x C
3
Polynomial Root Finding
This set of programs provides root finding for polynomial expressions.
For speed of operation, polynomials are represented by lists of the form
Algorithms
In the following discussions, the polynomials are assumed to have 1 as the
coefficient of the highest order term. Any polynomial can be reduced to
this form by dividing it by the highest order coefficient without changing
the value of the roots.
Quadratic Polynomials
The form for a quadratic polynomial is Z2+ a1z +ao. Quadratic polyno-
mials can be solved for two roots by application of the quadratic
formula:
'/2 i
- .~'.• <:t <
1.
, '-{f -
< ,
'T ><'co .t
a1
a1 2 ] [
z±= -T± (2) -ao ='
2. <}
Cubic Polynomials
The form for cubic polynomials is z 3 + a 2 z 2 + a 1Z +a o. The algorithm used
for cubic polynomials is as follows:
1. Rewrite the polynomial as w 3+aw +b, where
a2
w =z-3
a =al - - -
al
3
b =(2a23-9a2al +27ao)
27
2. Define
1
A = [_ ~ _ (b4 2
_ ;~ )1/2] 3
B=-~
3A
a2
ZI = --+A +B
3
a2 B
Z2= -3+ fA +[
a2 A
Z3 = -3+[+f B
°
For the case a = 0, the above solutions are valid with A = and B = (-b) 3 .
Fourth-Order Polynomials
The form for a fourth-order polynomial isz4+a3z3+a2z2+alz +ao. A
fourth-order polynomial can be factored into
2A =a3
2B +Az-Cz=az
2AB -2CD =al
BZ-Dz=ao
A=~
2
B=L
2
al
AB--
C= 2 (* )
D
D =(BZ-aO)'/2
bZ= - az
bl=a3al-4ao
b o=ao(4az - an - a'f
C can also be expressed as (A 2 - az+y )'/2, but this introduces a sign ambi-
guity. The sign of the square root must be chosen so that C satisfies the
equation (*) above. However, care must be taken when using (*), since D
can be zero, or close to zero in some cases. In the programs below, the
three roots yare inspected to determine which gives the largest absolute
value for D; that value of y is chosen for the remainder of the calculation.
This leaves the pathological case where all three roots are the same and
all yield D = O. In this case, the sign choice for C is unimportant, so the
alternate definition of C (described at the beginning of this paragraph) is
used. (Note that these programs do not detect cases where D should be
zero but is not because of round-off error in the numerical computations.
{an an - 1 ... a 1 a0 }
"
Names in the original object algebraic (except for the poly-
nomial variable name) are evaluated during execution of
Note PCOEF. To prevent substitution of current values for those
names, you should purge the corresponding variables.
quadratic { az a 1 ao}
cubic { a3 az al ao}
quartic { a4 a3 az a 1 ao}
• If you wish to save the polynomial coefficients for later use, store the
list in a variable, for example, == OUP == ' COEF' [§'TQJ.
• Press ~ PROOT ~. PROOT returns one, two, three, or four real or
complex roots to the stack, depending on the order of the polynomial.
• To evaluate the polynom.ial at a particular value of the independent
variable, enter the coefficient list then the variable value (list in level
2, variable value in level 1), then press ~ pVAI~ or ·;: PSERS ~•. PVAL
and PSERS will accept symbolic coefficients and variable values, as
well as real and complex numbers.
Examples
Example 1. Find the roots of 4X4 - 8X 3 - 13x2 - lOx + 22 = O. Also,
evaluate the polynomial at x = 2.
I MOf)E] 4 ~ FIX ~
1 1I(I]~·CIl1IJil~WJ!(lf~fI!iliH1Im1
Real roots are in stack positions 4 and 2. Complex roots are in stack posi-
tions 3 and 1.
Example 2. Find the three cube roots of (0,8). The cube roots are the
roots of the equation x 3 - (0,8) = 0.
Arguments Results
4: 4: Z4
3: 3: Z3
2: 2: Z2
1: { an ... ao} 1: Z1
Required Programs:
• QU D
• CUBIC
• QUAR
Program: Comments:
«
LIST---> --->ARRY Put coefficients in a vector.
DUP 1 GET / Normalize coefficients .
ARRY---> LIST---> DROP 1 Polynomial order.
- DUP 2 + ROLL DROP Discard leading coefficient.
{NEG QUO CUBIC QUAR} Choices fo r various orders.
SWAP GET EVAL Execute the appropriate choice.
»
[fNTER I
, PROOT' I STO I Store the program.
Arguments ResuHs
Program: Comments:
«
SWAP 2 / NEG - al/2
OUP SQ ROT - V [(ad2i - ao]1/2
OUP2 + 3 ROLLO -
»
lQlTERI
, QUO' [gCS] Store the program.
Program: Comments:
«
3 PICK -3 / -a~3
3 PICK 5 PICK SQ 3 / a
5 ROLL OUP 3 2 * A
SWAP 9 * 6 ROLL * -
27 / 4 ROLL + NEG b
OVER ABS a
IF == If a = 0 ...
THEN 3 INV A ... then B = (- b )1/3
SWAP DROP a SWAP andA = O.
ELSE 2 / OUP SQ 3
PICK 3 /\ 27 / +
V - 3 INV A A
SWAP OVER / 3 / NEG B
END
-1 3 V R----;C 2 / f
4 ROLLO 3 OUPN 3 Z1
OUPN + +
8 ROLLO 7 PICK *
SWAP 7 Zz
PICK / + +
5 ROLLO 4 PICK /
SWAP 4 ROLL * + + Z3
»
' ENTER]
'CUBIC' L§iQ] Store the program.
Arguments Results
4 : a3 4: Z1
3 : a2 3 : Z2
2 : a1 2 : Z3
1: ao 1: Z4
Required Programs:
• QUO
• CUBIC
Program: Comments:
«
3 PICK NEG DUP 6
ROLLD
5 PICK 4 PICK * 3
PICK 4 * -
5 ROLL 4 * 6 PICK
SQ - 4 PICK
* 5 PICK SQ - bo
CUBIC 3 -+LIST Combine three roots in a list.
1 3 Find the root Yo that maximizes
I (V/ 2 )2 _ ao l ·
FOR n
DUP n GET 2 / SQ n
2 + PICK - ABS SWAP
NEXT 4 ROLLD DUP2
IF <
THEN SWAP DROP 3
ELSE DROP 2
END 3 ROLLD
IF >
THEN DROP 1
END GET Yo
4 ROLL 2 / A
SWAP 2 / B
I ENTER I
'QUAR' I STO I Store th e program.
Algorithms
To obtain a general solution to a second-order differential equation of the
form listed above, use the following facts:
1. The left side of the equation can be represented as
(D +r 1)(D +r2»)'
where D is the differential operator d/dx, and r 1 and r2 are the
negatives of the roots of the quadratic equation
r2+ar +b =0
2. The general solution of the equation
(D +r ) y =1 (x)
is given by
x
"
Before running the next examples, make sure flag 34 is
clear. Otherwise, you will not get the solutions as shown.
Note
This equation is suitable for symbolic solution by SDEQ. The right side is
a polynomial f o=x 2 plus a second term f 1 that is a polynomial x multi-
plied by the exponential e -X.
im:HlmHlmM---
'DA2+3*D+2' ·1
{ 'XA2' 2 121 }
{ X .1 -1
IENTEBJ
} I:. ."" - - ,
Enter the triplet for the second term on the right.
~1mHI~l:~-
D'2+3*0+.2 '1
?_J
Combine the lists.
~
+ 3'
2: 'D A2+3*D. +2'
1: { 'XA2' 2_
m:HlmHlmM 121 X_1 -_1 }
You can check this result by constructing the differential operator and
applying it to the result. The differential operator corresponding to
, D" 2 + 3 * D+ 2' can be created as the program D IFO P:
'DIFOP' ISTOI
Although you could apply this to the entire expression above, it is easier
and faster to check each piece separately.
~ = DIFOP = 2:
1:
'CO*EXP(X>+C1*EXP(-",
0
IALGBRA I == COLCT == tnmll!l1J1llft'HlEmOO!D[l]H!]]
The sum matches the original right side of the differential equation,
demonstrating the validity of the solution.
To cast this equation into a form suitable for SDEQ, you must rewrite it
in terms of exponentials:
y" -y = -i e 2ix +i e - 2ix.
Programs
Arguments Results
2 : 'quadratic' 2:
1: { list} 1: 'expression'
Required Programs:
• HOMOG
• PARTl
• PART2
• COLX
Program: Comments:
« list
--> Save the arguments.
« D X CO Cl sl }
{ Initialize the variables.
PURGE
'D' QUAD Solve the quadratic.
DUP 1 'sl' STO EVAL Tl
NEG
SWAP 'sl' SNEG EVAL T2
NEG
--> rl r2 Save the roots.
« rl r2 HOMOG Compute the homogeneous solution.
1 list SIZE
FOR I Repeat for each triplet.
list I I 2 + SUB
[ENTER i
I SDEQ I 181'01 Store the program.
-1 I A * * +
NEXT
END
» »
IENTER I
'PART1' I STO I Store the program.
Program: Comments:
« -> n k rl r2 Save the parameters.
« n rl k + PARTI "Integrate" once.
n 1 + r2 k + PARTI Again.
n COLX Simplify.
'EXP(k * X)' EVAL * Multiply by e k x .
» »
IENTER]
'PART2' ISTO I Store the program.
Arguments Results
2: r1 2:
1: r2 1: {solution}
Program: Comments:
« rl r2
-> Save the roots.
« IF rl r2 SAME
THEN '( CO * X + C1 ) Case for identical roots.
* EXP(-rl * X)'
ELSE 'CO * EXP (-rl * Different roots.
X) + Cl * EXP(-r2 *
X) ,
END EVAL
» »
iENTERl
'HOMOG' [§fQ] Store the program.
Algorithms
For a differential equation of the form y , = f (x ,y ), the value of y at a
nearby point x +h can be approximated from the value of y at x:
where
C1 =hf (x ,Y)
h C1
c2=hf (x + -,y +-)
2 2
h C2
c3= hf (¥ + 2'Y + 2)
«-> X Y 'f(x,y)' »,
'F' [8TOI
and so on.
Programs
Program: Comments:
«
{STO X Y H} MENU Display the input menu.
HALT Set up INCR key for first order.
'YII' 'INCR' STO Do the first step.
YII Activate the USER menu.
23 MENU
»
I ENTE~1
'DEI' jSTO ! Store the program.
Argument I Result
Program: Comments:
«
« DUP 2 / Y + H
2 / X + SWAP F H *
»
H X Y F * This sequence will be executed twice.
OVER EVAL C1
ROT EVAL C2
DUP Y + X H + SWAP F C3
H * C4
OVER + + OVER + + +
6 /
'Y' STO+ H 'X' STO+ t..y
X Y R->C The R->C may be omitted if you
» prefer to have x and y returned as
separate real numbors.
!ENTERI
'YIl' [STO I Store the program.
Algorithms
The approach for a second-order differential equation, of the form
y " = f (x,y ,v '), is sim ilar to that for first -order equations. Here both y
and y' are approximated incrementally:
y'(x +h )=/(t)+(k1+2k2+2k3+k4)j6
where
k 1 = hf (t ,y "v')
k 2 =1 h h, h k
If (x+-,v+-v ,k1 )
2' 2~
+-
8
1, V + -
. 2
k If ( h h, hk ,k2)
3= I X + 2'y + 2 Y +"8 2, y +2
k4 =hf (x +h,y +hy' + ~ k3'Y' +k3)
« -+ X Y Dy I f ( X , y , Dy) I »,
« Y Dy 'x*(Dy-l)/
- X
(SQ(x)-l)' » i
T; « "*
/(SQ(x)-l)' »
x y Dy 'X*(D,:o/-n l
I
~NTEF1J i lllBl~mm~IlIIlm~1
'F' [§ICl~
l-!J'!~~
~ INCR ~
Programs
Program: Comments:
«
{STO X Y DY H} MENU Display the input menu.
HALT Set up INCR key for second order.
'YI2' 'INCR' STO Do the first step.
YI2 Activate the USER menu.
23 MENU
»
~IiTERl
'YI2' L§JOl Store the program.
x p
--;------;.
y ...... :~"
•• .. " X , I
." .
. '..
y: .. '
...
.y
• x'
70 7: Coordinate Transformations
Algorithms
The programs implement the following expressions:
If a flag>. is defined that has the value 1 (nonzero) for the forward
transformation and the value 0 for the reverse, then these can be com-
bined into a single equation
where P (1) ') represents the vector in the original (transformed) system
or the transformed (9riginal) system, according to whether>' has the value
1 or 0, respectively. >. means NOT >..
Instructions
Three main programs are provided:
• SETX (Set Up Transform) prompts you for the values of T, N, and O.
• -----NEW converts a vector from the old (unprimed) system to the new
(primed) system.
• -----OLD converts a vector from the new system to the old.
7: Coordina1e Transformations 71
To transform vectors:
72 7: Coordinate Transformations
Examples
Example 1. The coordinate systems (x,y) and (x ~ ,y~) are shown helow:
y
y' • P3(6,-8)
.PI (-9,7)
x'
.P2 (-5,-4)
.Pi(2. 7 ,-3.6)
Convert PI to P l~ .
[-9 7 --.NEW
..
.-::: :
'1; [-'3. 2t,22 17. OE4'3 ] ,
"im1JEIIGlIDIlI!l!ImrnJl
7: Coordinate Transformations 73
Convert P 2 to P 2' .
[ - 5 - 4 [-=;NE~W~
I~1:;-[[-10.6921
-9.2622 17.0649 ] 1·
5.4479 ]
~rnImEllEmHllmImrml
1
Convert P 3 to P 3' .
[6 8 ~ .;NEW ~ 1;2:
3:
,- ~ . - - · · - ·· - -···· -~- -I
[-9.2622 17.0649 ]
[-10.6921 5.4479 ]1
11. : [.4.5
. 56. .9 11. 146.1 ]..
L"iiil*ClInI.m:D!IllmImrml
"rnImEllEmHIlmI~1
~f..;
i3:-~-- --- - -- 1
[ 3 . 9 2. 1 7 ~ ~NEW ~
~ -- -
.....
[
.--- .---------
3.586 0.261
rnImEllEmHllmImrm
0.58~" . 1
- - ----- ---_ ._ - -
74 7: Coordinate Transformations
In the translated, rotated system above, a point has the coordinates
(1,1,1). What are the corresponding coordinates in the original system?
l~ii:f,.ti~~~~1
Purge the menu entries created by these exam pies.
7: Coordinate Transformations 75
Programs
[]t\ITER J
'SETX' iSTO j Store the program.
76 7: Coordinate Transformations
---+NEW (Compute New Coordinates) Main Program
Argument Result
1: [xy z] 1: [xyz']
Required Program:
• XFMS
Program: Comments:
« 1 SF XFMS » Set flag 1 for forward transform.
tENTER I
'-=-"NEW' l§tQ] Store the program.
Argument Result
11 : [x y z'] 1: [x y z]
Required Program:
• XFMS
Program: Comments:
« 1 CF XFMS » Set flag 1 for forward transform.
[[f',JIERI
, -->OLD' I STO i Store the program.
7: Coordinate Transformations 77
XFMS (Transformation) Subroutine
I Argument Result
1: [xy z 1 [)( y z']
Program: Comments:
«
1 FC?
SWAP DUP SIZE 3 ~
[EN~
, XFMS' ISTQj Store the program.
78 7: Coordinate Transformations
8
Curve Fitting
These programs collect statistical data points ~t: ,Y ) and fit any or all of
four curves to the data. The programs can also choose the curve of "best
fit," defined as that curve fit with the highest coefficient of determination
for the data.
Exponential y = a e bx
Logarithmic y = a + b (In x)
The program requires all data points be in the domain x > 0. To fit a
linear curve with points with x ::; 0, use LR.
Algorithms
The regression coefficients a and b are found by solving the following
linear equations:
8: Curve Fitting 79
n n
An +bEY; = EY;
i=l ;=1
n n n
A E Xi +b EX? = EX; Y;
where n is the number of points, and A, X, and Yare defined by
Regression A ~ Yi
Linear a Xi y.
~ ,
Exponential In a Xi In y.,~
Logarithmic a In Xi y
.' ,
Power In a In Xi InYi
Instructions
1. Accumulate the data. Enter each data point as one of the following:
• two real numbers (x in level 2 and y in levell).
• a vector of the form [x y].
• a complex number of the form (x y).
Then press ~ POIf'.rr~. POINT accumulates the vectors [ x y In(x)
In(y) ] in the statistics matrix ~DAT.
,
2. To remove the most recent data point, press ~..Q~'= ~ which returns
a vector [x Y ] representing the most recent entry, while removing it
from the statistics matrix.
80 8: Curve Fitting
3. Fit a particular curve using either of the following methods:
8. Press
• ~ LlNC =
for a linear curve fit,
• ~ PWRC~
- - -." - ,-" .
8: Curve Fitting 81
Examples
Example 1. Fit a straight line to the following set of data and compute
predicted values ofy for x =37 andx =35.
x y
40.5 104.5
38.6 102
37.9 100
36.2 97.5
35.1 95.5
34.6 94
82 8: Curve Fitting
Example 2. Find the curve that best fits the following set of data. Then
com pute predicted values of y for x = 1.5 and x = 2.
x y
0.72 2.16
1.31 1.61
1.95 1.16
2.58 0.85
3.14 0.50
~ BEST ~
8: Curve Fitting 83
Purge the menu entries created by this example.
Programs
Arguments Results
3: m 3: a
2: n 2: b
1: 'name' 1 : r2
Program: Comments:
«
'X-+Y' STO OVER COU.::: b, A
LR m
SWAP ROT
IF 4
THEN EXP a
END SWAP CORR SQ r2
[~Nlf[!
'CFU1' : ~T-9J Store the program.
84 8: Curve Fitting
CFU2 (Curve Fit 2) Utility
Program: Comments:
«
DUP EVAL DUP 6 PICK Compare output from two
IF > curve fits and discards
THEN 4 ---->LIST 5 ROLLD the one with the smaller ,2.
4 DROPN LIST----> DROP
ELSE 4 DROPN
END
»
~NTER I
, CFU2' L0Q] Store the program.
Arguments Results
3: 3: a
2: 2: b
1: 1: r2
Required Program:
• CFUI
Program: Comments:
« 2 1 « PREDV » CFU1
»
I ENTER!
, LINC' i STO I Store the program.
8: Curve Fitting 85
EXPC (Exponential Curve Fit) Subroutine
Arguments Results
3: 3: a
2: 2: b
1: 1 : r2
Required Program:
• CFU]
Program: Comments:
« 4 1 « B * EXP A *
» CFU1 »
Arguments Results
3: 3: a
2: 2: b
1: 1: r2
Required Program:
• CFUl
Program: Comments:
«
4 3 « B A A * » CFU1
»
[l::NTERJ
'PWRC' iSTO j Store the program.
86 8: Curve Fitting
LOGC (Logarithmic Curve Fit) Subroutine
Arguments Results
3: 3: a
2: 2: b
1: 1: r2
Required Program:
• CFUl
Program: Comments:
«
2 3 « LN PREDV »
CFU1
»
~t'JJ~~i
'LOGC '8TO ' '-=--'--~
Store the program.
[tNTER i
, PLOT' [§JO ! Store the program.
8: Curve Fitting 87
POINT (Accumulate Point) Subroutine
Arguments Results
1: y
Program: Comments:
«
DUP TYPE Determine entry type.
IF DUP 3
THEN DROP ARRY-+ DROP Unpack a vector.
ELSE
IF 1 --
THEN C-+R Unpack a complex number.
END
END
DUP2 LN SWAP LN SWAP
{ 4 } -+ARRY ~+ Accumulate data point.
»
[ffi~RJ
, POINT' [~Q i Store the program.
Argument Result
11 : 11 : [xy]
Program: Comments:
«
~- { 2 RDM Return x andy.
»
[ENTER]
, DEL' lBgJ Store the program.
88 8: Curve Fitting
BEST (Best Fit) Subroutine
Arguments Results
3: 3: a
2: 2: b
1: 1: r2
Required Programs:
• LOGC
• PWRC
• LINC
• EXPC
Program: Comments:
«
'LOGC' DUP EVAL Logarithmic fit.
'PWRC' CFU2 Power fit.
'LINC' CFU2 Linear fit.
'Expe' CFU2 Exponential fit.
3 DROPN DUP EVAL Repeat the best fit.
#25AFCh SYSEVAL Display the stack. *
4 ROLL 4 DISP Display the best curve name.
»
rItITER-l
'BEST' [§T61 Store the program.
This program shows the use of the SYSEVAL function to programmatically display an
updated stack.
8: Curve Fitting 89
9
Triangle Solutions
These programs can be used to find the area, the lengths of all of the
sides, and all of the angles of a triangle. The triangle is specified in terms
of one of the following:
• Three sides (SSS).
• Two sides and the included angle (SAS).
• Two sides and an adjacent angle (SSA).
• Two angles and the included side (ASA).
A3L-------------------------~
SI
The algorithms and programs work equally well when the sides and angles
are numbered clockwise or counterclockwise around the triangle.
The triangle programs will work with numeric or symbolic values for the
sides and angles.
90 9: Triangle Solutions
Algorithms
SSS (3 Sides)
S 1, S 2, and S 3 are known:
P =(S 1 +S2+S3)/2
PCP -SI) ]1/2
Al = 2cos-l [- - - -
S~3
1 2
_[P(P-S 2 )J /
A2=2cos l ----
S IS3
A3= cos-l ( - COS(A2+A 1»
S 3 = S 1 cosA 2 + S 2 cosA 1
A 2 =coS-1 ( -COS(A3 +A l»
9: Triangle Solutions 91
SAS (2 Sides and Included Angle)
The problem is now reduced to the ASA configuration. But note that
there are two possible solutions if S 2 > S 1 and A 3 ;F90°, corresponding to
A 3 determined by the above equation and A 3' = 180° - A 3' In the program
listing, the first .<,olution corresponds to the program SSA1 and the second
to SSA2.
Area
Instructions
1. Select radians mode or degrees mode as appropriate. In degrees
mode, angles are entered and returned in degrees; in radians mod
angles are entered and returned in radians.
92 9: Triangle Solutions
2. Choose the program corresponding to the known elements of the
program:
Press [WEAl
--- ----
, then one of the following: ~ SSS ~ , ~AS'" ~ , ~ SAA ~ ,
~ SAS ~ , ~ SSA 1 ~ ,
or ~ SSA2 ~ .
3. The HP-28S will halt and display an input menu showing menu keys
for each of the three known sides or angles or both. For each vari-
able, enter the desired value and press the corresponding menu key.
You may enter the values in any order.
• If you leave this menu, you can return at any time by pressing
ICUSTOM I ·
• You do not have to enter a value for any of the prompted quan-
tities if you want to preserve the current value.
• To recall the current value of any of the variables, press [J , fol-
lowed by the appropriate menu key, then ~vAL:J .
One or more of the values that you enter may be symbolic, for
which the programs will return symbolic results. However, if
you do enter symbolic values, don 't use the names SI, S2, S3,
AI, A2, or A3, or any of the triangle program names for any of
the sides or angles. This will cause circular references, which
can result in endless program execution (from which you can
recover by pressing I ON I to produce a system halt).
4. Press ICONT I to continue the program. When the triangle com puta-
tion is complete, you will see a CUSTOM menu appear with a
menu key for each of the six sides and angles of the triangle. Press
any of the six keys to return the value of the corresponding variable
to the stack. The triangle variables may also be used from the
USER menu.
5. Press I NEXT I (repeatedly, if necessary), to find the menu key
~ AREA ~ . Press ~ AREA ~ to return the area of the triangle.
9: Triangle Solutions 93
Examples
Example 1. Find the angles (in degrees) and the area for the following
triangle:
lU}ER I ~_$S~~ 1 2: !
111 ~l 1GL][li]C][=1I::;:;J1
~A2 ~
:0= A3 :O=
94 9: Triangle Solutions
Example 2. A surveyor is to find the area and dimensions of a triangu-
lar land parcel. From point A , the distances to Band C are measured
with an electronic distance meter. The angle betweenAB andAC is also
measured. Find the area and the other dimensions of the triangle.
Sf , c
This is an SAS problem:
Enter the angle and two sides, then solve for side S 3 (in meters).
p.-; -~ -~----I
171.63 ~ S1 ~
297. 35 ~ S2 ~
98. 12 lfB\~1
== HMS-t ==
ll• .m __ m.~
I CUSTOM I ~ A3 ~
I CON~I
~ S3 ~
'3- :-----~--~--------l
~ A1 ~
2: 363.9118
1: 27.8270
iWJ.~IIHIIIiDI _ _ 1IDI
9: Triangle Solutions 95
Solve for angle A 2'
~A2~ 8:- - -- -- - -- 36:3.91181
2: 27.8270'
~
1
...
__IHIIm.':'=1
-- ~ -- - .-. - --. -_ .. _- --- -- - -- -
.2: 5:::.97:30
11 : 25256. 20'341
t'lRIm9mHRHlIlilDIIiJg,
GS
W....- - - - - - - - f - - - - - - - - . E
S
By subtracting the wind direction from 180° (yielding an angle of 103°),
the problem reduces to an SSA triangle solution:
96 9: Triangle Solutions
Enter two sides and the adjacent angle and solve for HDG (A2).
140 ~rS1 ~ t : : : :- --------1
25 =S2= 2: I
~ - --== - 1 •• 1 c, '''1 2 r.> ?'I
...,,-,.1::: ~_
Solve for GS (S 3) .
=:' S3 ~ 8:----"---------1
12:
11:
10.0202
132.2407
1. . IIiIIIKmEIII. . . .!
Programs
Arguments Results
2: x 2:
1: y 1: cos- 1 [ -cos(x+y)]
Program: Comments:
« + COS NEG ACOS » cos-1( - cos(z 1 + z 2))
[ENTERl
'TU1' []Iol Store the program.
9: Triangle Solutions 97
TU2 (Triangle 2) Utility
I Arguments
2: {list}
Results
1: 'name'
Program: Comments:
«
{ Sl Al S2 A2
S3 A3 AREA } MENU
»
IENTER I
'TU2' []TOl Store the program.
Argument Result
1:
Required Programs:
• TUI
• ASA
Program: Comments:
« Program common to --SSAI and
DUP 'A2' STO Al TU1 --SSA2.
'A3' STO
S2 Al
->ASA 'AI' STO 'S2'
STO
»
IENTER I
'TU3' []Io I Store the program.
98 9: Triangle Solutions
computation Subroutines
The following subroutines perform the actual triangle computations and
can be called by other routines. The name of each routine is "~" followed
by three letters indicating which case (for example, SSS, SAS, and so on)
the routine evaluates.
Program: Comments:
« 51 52 53
+ + 2 / p
DUP DUP2 52 - * 51 / StoreA 2 •
53
/ V AC05 2 * 'A2' Store A l'
5TO StoreA 3 ·
51 - * 52 / 53 / V
AC05 2 * DUP 'A1'
5TO
A2 TU1 'A3' 5TO
»
IENTER I , ISTO j
'~555 Store the program.
9: Triangle Solutions 99
-ASA (Compute ASA) Subroutine
Required Program:
• TVl
Program: Comments:
« Sl A3 A2
TUl DUP 'Al' STO StoreA 1 ·
SIN / A2 SIN * 'S2' Store 52'
STO 53
Sl A2 COS * Al COS
S2 * +
'S3' STO
»
[ENT~~J
, -.ASA' '8JO 1 Store the program.
Program: Comments:
« Al A3 OVER
TUl 'A2' STO SaveA 2·
-.ASA 5 2 ,5 3
'Al' STO Restore original A l'
»
~NTERJ
, -.SAA' [§:fo: Store the program.
Program: Comments:
« SI S2 A3 3 DUPN
COS * * -2 *
ROT SQ + ROT SQ +
V 'S3' STO Store 5 3.
---+SSS A 1 ,A 2
'A3' STO Restore originalA 3 .
»
Program: Comments:
«
Al SIN S2 * SI / A2
ASIN
TU3
»
I ENTER ]
'---+SSAl' I STO] Store the program.
Program: Comments:
«
Al SIN S2 * SI / A'2
ASIN A'2
-1 ACOS SWAP -
TU3 »
[ENTER I
' ~SSA2' [sTO I Store the program.
Main Programs
The following programs are intended to be used directly from the USER
menu. The name of each program describes which of the various triangle
solutions is perform ed by the program.
Program: Comments:
« { STO SI S2 S3 }
MENU HALT ~ SSS TU2 »
ENTERj
'ASP..' i STO I Store the program.
LsNTERI
, SAA' I-STO 1 Store the program.
(ENTER]
, SAS' ISTOI Store the program.
Program: Comments:
« { STO SI S2 Al }
MENU HALT -+SSAI TU2
»
[Er;JIEBI
, SSAl' i§iQ1 Store the program.
Program: Comments:
« { 8TO 81 82 Al }
MENU HALT ---.88A2 TU2
»
ENTERl
'88A2' I STO I Store the program.
IENTE~!
, AREA' ! STO 1 Store the program.
Practical routines show you how to use the built-in menus to solve prob-
lems more effectively, while easy-to-follow instructions help you create
personalized menus.
Calculus (00028-90102)
• Perform function operations: definition, composition, analysis, angles
between lines, and angles between a line and a function.
• Solve problems of differential calculus: function minimization, com-
puting tangent lines and implicit differentiation.
• Obtain symbolic and numerical solutions for integral calculus prob-
lems: polynomial integration, area between curves, arc length of a
function, surface area, and volume of a solid of revolution.