Chapter Programming 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.
Programming Chapter 8 1. Before Programming The programming function helps to make complex, often-repeated calculations quick and easy. Commands and calculations are executed sequentially, just like the manual calculation multistatements. Multiple programs can be stored under file names for easy recall and editing. File Name File Name Program Program File Name Program Select the PRGM icon in the Main Menu and enter the PRGM Mode. When you do, a program list appears on the display.
Programming Chapter 8 2. Programming Examples Example 1 To calculate the surface area and volume of three regular octahedrons of the dimensions shown in the table below Store the calculation formula under the file name OCTA. Length of One Side (A) A Surface Area (S) Volume (V) 7 cm cm2 cm3 10 cm cm2 cm3 15 cm cm2 cm3 The following are the formulas used for calculating surface area S and volume V of a regular octahedron for which the length of one side is known.
Programming Chapter 8 • Pressing 4 (SYBL) displays a menu of symbols that can be input. 4(SYBL) 1 2 3 4 • You can delete a character while inputting a file name by moving the cursor to the character you want to delete and pressing D. 3. Press w to register the file name and change to the program input screen. File name w • Registering a file name uses 17 bytes of memory. • The file name input screen remains on the display if you press w without inputting a file name.
Programming Chapter 8 u To change modes in a program P.2 • Pressing 3 (MENU) while the program input screen is on the display causes a mode change menu to appear. You can use this menu to input mode changes into your programs. For details on each of these modes, see “Using the Main Menu”, as well as the sections of this manual that describe what you can do in each mode. 3(MENU) 1 P.6 2 3 4 • Pressing ! Z displays a menu of commands that can be used to change set up screen settings inside a program.
Programming Chapter 8 Surface Area S .. c*!9d*aAxw Volume V ........... !9c/d*aAMdw If you simply input the manual calculations shown above however, the calculator would execute them from beginning to end, without stopping. The following commands make it possible to interrupt a calculation for input of values and display of intermediate results. ? : This command pauses program execution and displays a question mark as a prompt for input of a value to assign to a variable.
Programming 1 Chapter 8 2 3 4 1 (EXE) or w hw (Value of A) Intermediate result produced by ^ w w baw w • Pressing w while the program’s final result is on the display re-executes the program. P.140 • You can also run a program while in the RUN Mode by inputting: Prog ”” w. • An error (Go ERROR) occurs if the program specified by Prog ”” cannot be found.
Programming Chapter 8 3. Debugging a Program A problem in a program that keeps the program from running correctly is called a “bug,” and the process of eliminating such problems is called “debugging.” Either of the following symptoms indicates that your program contains bugs and that debugging is required.
Programming Chapter 8 5. Searching for a File You can search for a specific file name using any of the three following methods. • Scroll Search — scroll through the file names in the program list. • File Name Search — input the name of the file. • Initial Character Search — input the first few letters of the name of the file. u To find a file using scroll search Example To use scroll search to recall the program named OCTA 1.
Programming Chapter 8 u To find a file using initial character search Example To use initial character search to recall the program named OCTA 1. While the program list is on the display, press [ 3 (SRC) and input the initial characters of the file you want to find. [3(SRC) OCT 2. Press w to search. w • All files whose file names start with the characters you input are recalled.
Programming Chapter 8 • The following function keys are also useful when editing program contents. 1 (TOP) ....... Moves the cursor to the top of the program 2 (BTM) .......
Programming Chapter 8 Let’s edit the program. 2(EDIT) eeeeDD cd![bc D Q Let’s try running the program. Length of One Side (A) Surface Area (S) Volume (V) 7 cm 2 84.87048957 cm 40.42293766 cm3 10 cm 173.2050808 cm2 117.8511302 cm3 15 cm 389.7114317 cm2 397.
Programming Chapter 8 w baw w 7. Deleting a Program There are two different ways to delete a file name and its program. • Specific program delete • All program delete u To delete a specific program 1. While the program list is on the display, use f and c to move the highlighting to the name of the program you want to delete. 2. Press [ 1 (DEL). [1(DEL) 1 2 3 4 3. Press 1 (YES) to delete the selected program or 4 (NO) to abort the operation without deleting anything. u To delete all programs 1.
Programming Chapter 8 [2(DEL•A) 1 2 3 4 2. Press 1 (YES) to delete all the programs in the list or 4 (NO) to abort the operation without deleting anything. P.37 • You can also delete all programs using the MEM Mode. See “Clearing Memory Contents” for details. 8. Useful Program Commands In addition to calculation commands, this calculator also includes a variety of relational and jump commands that can be used to create programs that make repeat calculations quick and easy.
Programming Chapter 8 Program Command Menu (COM) While the program menu is on the display, press 1 (COM) to display the program command menu. 1(COM) 1 (If) ............ If command 1 2 3 4 [ 1 2 3 4 [ 1 2 3 4 [ 2 (Then) ...... Then command 3 (Else) ....... Else command 4 (I•End) ...... IfEnd command [ 1 (For) ......... For command 2 (To) ........... To command 3 (Step) ....... Step command 4 (Next) ....... Next command [ 1 (Whle) ...... While command 2 (WEnd) ..... WhileEnd command 3 (Do) .
Programming Chapter 8 Jump Command Menu (JUMP) While the program menu is on the display, press 3 (JUMP) to display the jump command menu. 3(JUMP) 1 (Lbl) .......... Lbl command 1 2 3 4 [ 1 2 3 4 [ 2 (Goto) ....... Goto command 3 (⇒) ........... ⇒ (jump) command [ 1 (Isz) .......... Isz command 2 (Dsz) ........ Dsz command Press [ to return to the previous menu. Clear Command Menu (CLR) While the program menu is on the display, press [ 3 (CLR) to display the clear command menu.
Programming Chapter 8 3(TABL) 1 (Tabl) ........ DispTable command 1 2 3 4 2 (G•Con) .... DrawTG-Con command 3 (G•Plt) ...... DrawTG-Plt command Conditional Jump Relational Operator Menu (REL) While the program menu is on the display, press [ [ 1 (REL) to display the conditional jump relational operator menu. [[1(REL) 1 (=) ............ Relational operator = 1 2 3 4 [ 1 2 3 4 2 (G) ............ Relational operator G 3 (>) ............ Relational operator > 4 (<) ............
Programming Chapter 8 9. Command Reference k Command Index Break ..................................................................................... 140 ClrGraph ................................................................................ 144 ClrList .................................................................................... 144 ClrText ................................................................................... 144 DispTable ..........................................................
Programming Chapter 8 Numeric Expressions . Numeric expressions (such as 10, 10 + 20, A) indicate constants, calculations, numeric constants, etc. Alpha Characters ....... Alpha characters indicate literal strings (such as AB). k Basic Operation Commands ? (Input Command) Function: Prompts for input of values for assignment to variables during program execution. Syntax: ? → Example: ? → A _ Description: 1.
Programming Chapter 8 2. Using a carriage return in place of the multi-statement command makes the displayed program easier to read. k Program Commands (COM) If~Then Function: The Then-statement is executed only when the If-condition is true (nonzero). Syntax: If numeric expression _ : ^ Then _ : ^ Parameters: condition, numeric expression Description: 1. The Then-statement is executed only when the If-condition is true (non-zero). 2.
Programming Chapter 8 If~Then~Else Function: The Then-statement is executed only when the If-condition is true (nonzero). The Else-statement is executed when the If-condition is false (0). Syntax: If numeric expression _ : ^ _ : ^ Then Else _ : ^ _ : ^ Parameters: condition, numeric expression Description: 1. The Then-statement is executed when the If-conditions is true (non-zero). 2.
Programming Chapter 8 For~To~Next Function: This command repeats everything between the For-statement and the Next-statement. The starting value is assigned to the control variable with the first execution, and the value of the control variable is incremented by one with each execution. Execution continues until the value of the control variable exceeds the ending value.
Programming Chapter 8 Description: 1. This command is basically identical to For~To~Next. The only difference is that you can specify the step. 2. Omitting the step value automatically sets the step to 1. 3. Making the starting value less than the ending value and specifying a positive step value causes the control variable to be incremented with each execution.
Programming Chapter 8 Description: 1. This command repeats the commands contained in the loop as long as its condition is true (non-zero). When the condition becomes false (0), execution proceeds from the statement following the WhileEnd-statement. 2. Since the condition comes after the While-statement, the condition is tested (checked) before the commands inside the loop are executed.
Programming Chapter 8 3. A subroutine can be used in multiple locations in the same main routine, or it can be called up by any number of main routines. Main Routine A Subroutines D Prog ”D” Prog ”C” C E Prog ”E” Prog ”I” I J Prog ”J” Level 1 Level 2 Level 3 Level 4 4. Calling up a subroutine causes it to be executed from the beginning. After execution of the subroutine is complete, execution returns to the main routine, continuing from the statement following the Prog command. 5.
Programming Chapter 8 Example: For 2 → I To 10_ If I = 5_ Then ”STOP” : Stop_ IfEnd_ Next This program counts from 2 to 10. When the count reaches 5, however, it terminates execution and displays the message ”STOP.” k Jump Commands (JUMP) Dsz Function: This command is a count jump that decrements the value of a control variable by 1, and then jumps if the current value of the variable is zero.
Programming Chapter 8 3. This command can be used in combination with conditional jumps and count jumps. 4. If there is no Lbl-statement whose value matches that specified by the Gotostatement, an error (Go ERROR) occurs. Example: ? → A : ? → B : Lbl 1 : ? →X:A ×X+B^ Goto 1 This program calculates y = AX + B for as many values for each variable that you want to input. To quit execution of this program, press A.
Programming Chapter 8 Description: 1. The conditional jump compares the contents of two variables or the results of two expressions, and a decision is made whether or not to execute the jump based on the results of the comparison. 2. If the comparison returns a true result, execution continues with the statement following the ⇒ command. If the comparison returns a false result, execution jumps to the statements following the multi-statement command (:), display command (^), or carriage return (_).
Programming Chapter 8 Description: This command draws a statistical graph in accordance with conditions defined within the program. DrawGraph Function: This command draws a graph. Syntax: DrawGraph_ Description: This command draws a graph in accordance with the drawing conditions defined within the program. DispTable Function: These commands display numeric tables.
Programming Chapter 8 Parameters: left side/right side: variable (A to Z), numeric constant, variable expression (such as: A × 2) relational operator: =, G , >, <, ≥, ≤ Description: 1.
Programming Chapter 8 • Graph function input Y = Type_ ..... Specifies graph type. ”X2 – 3” → Y1_ • Graph draw operation DrawGraph_ Example Program 1 ClrGraph_ 1 !W[32 2 View Window –10, 10, 2, –120, 150, 50_ 2 !31Q 3 Y = Type_ 3 3321Q ”X ^ 4 – X ^ 3– 24X2 + 4X + 80” → Y1_ 4 J[21Q 5 3311 6 !W[42 5 G SelOn 1_ 6 DrawGraph 4 Executing this program produces the result shown here. k Using Table & Graph Functions in a Program P.
Programming 1 T SelOn 1_ 1 341Q 0→ 2 J[31 6 → 3 F End_ 3 2 1→ 4 3Q 2 4 F Start_ F pitch_ Chapter 8 5 DispTable^ 5 !W[431Q 6 DrawTG-Con 6 !W[432Q Executing this program produces the results shown here. Numeric Table Graph w k Using List Sort Functions in a Program P.80 These functions let you sort the data in lists into ascending or descending order.
Programming Chapter 8 The graph conditions that are required depends on the graph type. See “Changing Graph Parameters”. • The following is a typical graph condition specification for a scatter diagram or xy line graph. S-Gph1 DrawOn, Scatter, List1, List2, 1, Square_ In the case of an xy line graph, replace “Scatter” in the above specification with “xyLine”. • The following is a typical graph condition specification for a single-variable graph.
Programming Chapter 8 k Performing Statistical Calculations • Single-variable statistical calculation 1 1-Variable List 1, List 2 Frequency data (Frequency) x-axis data (XList) 1 31[11Q • Paired-variable statistical calculation 2-Variable List 1, List 2, List 3 Frequency data (Frequency) y-axis data (YList) x-axis data (XList) • Regression statistical calculation 1 LinearReg List 1, List 2, List 3 Calculation type* 1 Frequency data (Frequency) y-axis data (YList) x-axis data (XList) 31[1[1Q *