HP 50g Graphing manual Calculations in a Program, Examples of Program Actions, Program Results

Models: 50g Graphing 48gII Graphing

1 693
Download 693 pages 23.18 Kb
Page 26
Image 26

Examples of Program Actions

Program

 

Results

 

« 1 2 »

 

2:

1

 

 

1:

2

« "Hello" { A B } »

2:

"Hello"

 

 

1:

{ A B }

« '1+2'

»

1:

'1+2'

« '1+2'

→NUM »

1:

3

« « 1 2 + » »

1: « 1 2 + »

« « 1 2

+ » EVAL »

1:

3

 

 

 

 

Programs can also contain structures. A structure is a program segment with a defined organization. Two basic kinds of structure are available:

Local variable structure. The command defines local variable names and a corresponding algebraic or program object that’s evaluated using those variables.

Branching structures. Structure words (like DO…UNTIL…END) define conditional or loop structures to control the order of execution within a program.

A local variable structure has one of the following organizations inside a program:

«name1 namen 'algebraic ' »

«name1 namen « program » »

The → command removes n objects from the stack and stores them in the named local variables. The algebraic or program object in the structure is automatically evaluated because it’s an element of the structure — even though algebraic and program objects are put on the stack in other situations. Each time a local variable name appears in the algebraic or program object, the variable’s contents are substituted.

So the following program takes two numbers from the stack and returns a numeric result:

« → a b 'ABS(ab)' »

Calculations in a Program

Many calculations in programs take data from the stack. Two typical ways to manipulate stack data are:

Stack commands. Operate directly on the objects on the stack.

Local variable structures. Store the stack objects in temporary local variables, then use the variable names to represent the data in the following algebraic or program object.

Numeric calculations provide convenient examples of these methods. The following programs use two numbers from the stack to calculate the hypotenuse of a right triangle using the formula x2 + y2 .

« SQ SWAP SQ + ƒ »

« → x y « x SQ y SQ + ƒ » » « → x y 'ƒ(x^2+y^2)' »

The first program uses stack commands to manipulate the numbers on the stack — the calculation uses stack syntax. The second program uses a local variable structure to store and retrieve the numbers — the calculation uses stack syntax. The third program also uses a local variable structure — the calculation uses algebraic syntax. Note that the underlying formula is most apparent in the third program. This third method is often the easiest to write, read, and debug.

12 RPL Programming

Page 26
Image 26
HP 50g Graphing, 48gII Graphing manual Calculations in a Program, Examples of Program Actions, Program Results