Monday, October 24, 2011

RPL Programming Tutorial - Part 17 - HP 49g+/50g: System Flags

Flags

Welcome to Part 17 of the RPL Tutorial for the Hewlett Packard 49g+ and 50g calculators. Today we will work with flags.

There are two types of flags: system and user flags.

User flags do not have any pre-defined meaning except for what the programmer gives them. User flags are flags 1 through 127.

System flags are the flags that set the various modes of the calculator, and they are -1 to -127. Depending on how these flags are clear (turned off) or set (turned on) dictate how the calculator operates.

The Flag Menu

Keystroke sequence: [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F3] (FLAG)

[F1] (SF) - Set Flag. Turns the flag on. The flag number is on level 1 of the stack.
[F2] (CF) - Clear Flag. Turns the flag off. The flag number is on level 1 of the stack.
[F3] (FS?) - Set Flag Test. Tests if a flag is set. Returns 1 if the flag is set, 0 if it isn't.
[F4] (FC?) - Clear Flag Test. Tests if a flag is cleared. Returns 1 if the flag is cleared, 0 if it isn't.
[F5] (FS?C) - Tests if a flag is set - then clears the flag regardless of the result.
[F6] (FC?C) - Tests if a flag is clear - then clears the flag regardless of the result.

Some Common System Flags

Flag -13
Set: Built-in Time Value of Money calculations - assumes all payments are paid at the beginning of each period. (BGN mode on financial calculators)
Clear: Built-in Time Value of Money calculations - assumes all payments are paid at the end of each period. (END mode on financial calculators)

Flag -27
Set: Displays complex numbers as 'x + y*i'
Clear: Displays complex numbers as (x,y)

Flag -28
Set: Multiple equations are plotted simultaneously
Clear: Multiple equations are plotted sequentially

Flag -40
Set: The clock is displayed
Clear: The clock is not displayed

Flag -41
Set: 24 Hour Clock
Clear: 12 Hour Clock

Flag -42
Set: Day/Month/Year date format
Clear: Month/Day/Year date format

Flag -51
Set: The fraction mark is a comma ( , )
Clear: The fraction mark is a decimal point ( . )

Flag -60
Set: Pressing [ALPHA] once sets alpha-lock
Clear: Pressing [ALPHA] twice sets alpha-lock (default)

Flag -65
Set: Only level 1 on the stack displays multiple lines
Clear: All the levels on the stack displays multiple lines

Flag -79
Set: Single-line expressions
Clear: Textbook expressions

Flag -95
Set: Algebraic Mode (factory default)
Clear: RPN Mode

Flag -103
Set: Complex Number Mode (C indicator)
Clear: Real Number Mode (R indicator)

Keyboard Toggle: Hold [LS] while pressing [TOOL] (i)

Flag -105
Set: Approximate Mode (~ indicator)
Clear: Exact Mode (= indicator)

Keyboard Toggle: Hold [RS] while pressing [ENTER] (→NUM)

Flag -114
Set: Polynomials are shown in increase power order
(a0 + a1 * x + a2 * x^2 + ... + an * x^n)
Clear: Polynomials are shown in decrease power order
(an * x^n + ... + a2 * x^2 + a1 * x + a0)

Angle setting using flags:
Degree: Clear flags -17 and -18
Radians: Set flag -17, clear flag -18
Gradians: Set flag -18, clear flag -17

By commands:
Hold [LS] while pressing [MODE], [F2] (ANGLE)
F1: DEG, F2: RAD, F3: GRAD

PUSH and POP

A very handy pair of programming commands is PUSH and POP. Both commands are found in the catalog. These commands allow the user to save the calculator's mode settings with PUSH, change them during program execution, and recall them with POP.

PUSH: saves the current status of the flags

POP: restores the last saved status of the flags

The Program ROOTZ

This program will allow the user to calculate the xth root of any number. The user can request through a temporary soft menu:

[F1] (PRN): The principal root. This is the root that most, if not all, calculators return if the xth root (x√y) command is used. For square roots, this is the positive square root.

[F2] (REAL): All real roots to be returned. Real mode is set during execution.

[F3] (ALL): All roots, real and complex, to be returned. Complex mode is set during execution.

ROOTZ also purges the variable X and sets the calculator to Approximate mode.

Caution: ROOTZ works with real radicands (y). Complex radicands will return errors or undesired results.

Keystrokes:
[RS] [ + ] ( << >> )
105 [+/-] [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F3] (FLAG) [F1] (SF)

* Set the calculator to approximate mode
[LS] [ + ] ( { } )
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [SYMB] (P) [ √ ] (R) [EVAL] (N) [ALPHA] [ → ]
[RS] [ + ] ( << >> ) [RS] [ √ ] (x√y) [RS] [ENTER] (→NUM)

* Enters the commands for the PRN option (F1)
[ → ] [ → ] [ → ] [ → ]
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [ √ ] (R) [F5] (E) [F1] (A) [NXT] (L) [ALPHA] [ → ]
[RS] [ + ] ( << >> ) 103 [+/-] hold [LS] press [MODE] [F3] (FLAG) [F2] (CF)
[ ' ] [big X] [ → ] [LS] [EVAL] (PRG) [F2] (MEM) [F1] (PURGE)
[big X] [LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
[y^x] [L2] (SWAP) [ - ] [big X] [SYMB] [F5] (SOLVE) [F6] (ZEROS)

* Enters the commands for the REAL option (F2)
[ → ] [ → ] [ → ] [ → ]
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [F1] (A) [NXT] (L) [NXT] (L) [ALPHA] [ → ]
[RS] [ + ] ( << >> ) 103 [+/-] hold [LS] press [MODE] [F3] (FLAG) [F1] (SF)
[ ' ] [big X] [ → ] [LS] [EVAL] (PRG) [F2] (MEM) [F1] (PURGE)
[big X] [LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
[y^x] [L2] (SWAP) [ - ] [big X] [SYMB] [F5] (SOLVE) [F6] (ZEROS)

* Enter the commands for the ALL option (F3)
[ → ] [ → ] [ → ] [ → ] [ → ]
hold [LS] press [MODE] [F5] (MENU) [F3] (TMENU)

* Enters the TMENU command
[ENTER]
* Terminate program entry.


[ ' ] [ALPHA] [ALPHA] [ √ ] (R) [ ' ] (O) [ ' ] (O) [COS] (T) [ ÷ ] (Z) [ENTER] [STO>]

The completed program:

<< -105 SF
{ { "PRN" << XROOT →NUM >> }
{ "REAL" << -103 CF 'X' PURGE X SWAP ^ SWAP - X ZEROS >> }
{ "ALL" << -103 SF 'X' PURGE X SWAP ^ SWAP - X ZEROS >> } }
TMENU >>


Instructions:

1. Enter y (the radicand - goes underneath the radical √ )
2. Enter x

Complex numbers are displayed as coordinate pairs (real part,imaginary part).

Example:

1. The 4th roots of 8:

Principal: 1.618179283051

Real Roots: {1.618179283051, -1.618179283051}

All Roots: {1.618179283051, -1.618179283051, (0, -1.618179283051),
(0, 1.618179283051)}

2. The 3rd roots of -7:

Principal: -1.91293118277

Real Roots: -1.91293118277

All Roots: {(.956465591386, -1.65664699997), (.956465591386, 1.65664699997),
(-1.91293118277, 0)}

This concludes Part 17 of our RPL tutorial. Until next time, happy programming, Eddie.



This tutorial is property of Edward Shore. Mass reproduction and distribution requires express permission from the author.

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...