Example: Enter a program SPH that calculates the volume of a spherical cap of height h within a sphere of radius R using values stored in variables H and R.

V =

1

πh

2

( 3r h)

--

 

 

3

 

 

 

In this and following chapters on programming, “stack diagrams” show what arguments must be on the stack before a program is executed and what results the program leaves on the stack. Here’s the stack diagram for SPH.

Level 1

Level 1

 

 

 

 

volume

 

 

 

The diagram indicates that SPH takes no arguments from the stack and returns the volume of the spherical cap to level 1. (SPH assumes that you’ve stored the numerical value for the radius in variable R and the numerical value for the height in variable H. These are global variables — they exist outside the program.)

Program listings are shown with program steps in the left column and associated comments in the right column. Remember, you can either press the command keys or type in the command names to key in the program. In this first listing, the keystrokes are also shown.

Program:

Keys:

Comments:

 

 

 

«

@%

Begins the program.

 

 

 

'1/3

O1 /3

Begins the algebraic expression

 

 

to calculate the volume.

 

 

 

*π*H^2

*!Ì

Multiplies by ̟h2.

 

*H Q2

 

 

 

 

*(3*R-H)'

*!Ü

Multiplies by 3r - h, completing

 

3 *R -

the calculation and ending the

 

H ™™

expression.

 

 

 

→NUM

Converts the expression with π

 

 

to a number.

 

 

 

»

 

Ends the program.

 

`

Puts the program on the stack.

 

OSPH K

Stores the program in variable

 

 

SPH.

 

 

 

RPL Programming 1-5