Global and local variables and subprograms, Global and local variables and subprograms ,21-2 – HP 50g Graphing Calculator User Manual

Page 649

Advertising
background image

Page 21-2

„´

@LIST @ADD@

ADD

Calculate (1+x

2

),

/

/

then divide

[']

~„x™

'x'

„°

@)@MEM@@ @)@DIR@@ @PURGE

PURGE

Purge variable x

`

Program in level 1

_______________________

__________

_____________________

To save the program use: [']~„gK

Press J to recover your variable menu, and evaluate g(3.5) by entering the
value of the argument in level 1 (3.5`) and then pressing

@@@g@@@.

The result is 1.2485…, i.e., g(3.5) = 1.2485. Try also obtaining g({1 2 3}), by
entering the list in level 1 of the display: „ä1#2#3`
and pressing

@@@g@@@. The result now is {SINH(1)/2 SINH(2)/5 SINH(3)/10}, if

your CAS is set to

EXACT

mode. If your CAS is set to APPROXIMATE mode, the

result will be {0.5876.. 0.7253… 1.0017…}.

Global and local variables and subprograms

The program

@@@g@@@, defined above, can be displayed as

«

'x' STO x SINH 1 x SQ ADD / 'x' PURGE

»

by using ‚

@@@g@@@.

Notice that the program uses the variable name x to store the value placed in
level 1 of stack through the programming steps

'x' STO

. The variable x, while

the program is executing, is stored in your variable menu as any other variable
you had previously stored. After calculating the function, the program purges
(erases) the variable x so it will not show in your variable menu after finishing
evaluating the program. If we were not to purge the variable x within the
program its value would be available to us after program execution. For that
reason, the variable x, as used in this program, is referred to as a global
variable
. One implication of the use of x as a global variable is that, if we had
a previously defined a variable with the name x, its value would be replaced by
the value that the program uses and then completely removed from your
variable menu after program execution.
From the point of view of programming, therefore, a global variable is a
variable that is accessible to the user after program execution. It is possible to

Advertising