Páginas: 45 (11235 palabras) Publicado: 10 de octubre de 2010
Chapter 21 Programming in User RPL language
User RPL language is the programming language most commonly used to program the calculator. The program components can be put together in the line editor by including them between program containers in the appropriate order. Because there is more experience among calculator users in programming in the RPN mode, most of the examples in this Chapter willbe presented in the RPN mode. Also, to facilitate entering programming commands, we suggest you set system flag 117 to SOFT menus. The programs work equally well in ALG mode once they have been debugged and tested in RPN mode. If you prefer to work in the ALG mode, simply learn how to do the programming in RPN and then reset the operating mode to ALG to run the programs. For a simple example ofUser RPL programming in ALG mode, refer to the last page in this chapter.

An example of programming
Throughout the previous Chapters in this guide we have presented a number of programs that can be used for a variety of applications (e.g., programs CRMC and CRMT, used to create a matrix out of a number of lists, were presented in Chapter 10). In this section we present a simple program tointroduce concepts related to programming the calculator. The program we will write will be used to define the function f(x) = sinh(x)/(1+x2), which accepts lists as argument (i.e., x can be a list of numbers, as described in Chapter 8). In Chapter 8 we indicated that the plus sign, , acts as a concatenation operator for lists and not to produce a term-by-term sum. Instead, you need to use the ADDoperator to achieve a term-by-term summation of lists. Thus, to define the function shown above we will use the following program: To key in the program follow these instructions:

[']

«

x„~ K™x„å‚ ~

Keystroke sequence:

Produces:
'x' STO x

Interpreted as: Start an RPL program Store level 1 into variable x Place x in level 1

»

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

»«

«Page 21-1

_______________________

To save the program use: [']
J

Press to recover your variable menu, and evaluate g(3.5) by entering the value of the argument in level 1 ( ) and then pressing . 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: and pressing . The result now is {SINH(1)/2 SINH(2)/5 SINH(3)/10}, ifyour 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
@@@g@@@

The program

, defined above, can be displayed as

by using . 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, whilethe 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
@@@g@@@

»

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

Page 21-2

@@@g@@@

@@@g@@@

`5.3

Kg„~

`3#2#1ä„

™x„°„ ~ ´„ º„ x„~´„ #
[']
EGRUP@ @@RID@)@ @@MEM@)@ @DDA@ TSIL@ @HTM@)@HNIS@ PYH)@

SINH 1 x SQ ADD / 'x' PURGE

Calculate sinh of level 1 Enter 1 and calculate x2 Calculate (1+x2), then divide Purge variable x Program in level 1 _____________________

«

1 / `

__________

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,...

Regístrate para leer el documento completo.