Chapter Programming 20-1 20-2 20-3 20-4 20-5 20-6 20-7 20-8 20-9 20-10 20-11 20-12 20-13 Before Programming Programming Examples Debugging a Program Calculating the Number of Bytes Used by a Program Secret Function Searching for a File Searching for Data Inside a Program Editing File Names and Program Contents Deleting a Program Useful Program Commands Command Reference Text Display Using Calculator Functions in Programs 20
0-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 File Name Program Program Select the PRGM icon in the Main Menu and enter the PRGM Mode. When you do, a program list appears on the display.
20-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.
20 - 2 Programming Examples • Use 1 (RUN) to input a program for general calculations (a program to be executed in the COMP Mode). For programs that involve number system specifications, use 2 (BASE). Note that programs input after pressing 2 (BASE) are indicated by B to the right of the file name. • Pressing 6 (SYBL) displays a menu of symbols ( ’, ”, ~ ) that can be input. • 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.
Programming Examples 20- 2 • Pressing 6 (SYBL) displays a menu of symbols ( ’, ”, ~, *, /, # ) that can be input into a program. • Pressing ! Z displays a menu of commands that can be used to change set up screen settings inside a program. • {ANGL}/{COOR}/{GRID}/{AXES}/{LABL}/{DISP}/{P/L }/{DRAW}/{DERV}/ {BACK}/{FUNC}/{SIML}/{S-WIN}/{LIST}/{LOCS }/{T-VAR}/{ΣDSP}/{RESID} P.5 For details on each of these commands, see “Set Up Screen Function Key Menus”.
20- 2 Programming Examples The following shows examples of how to actually use the ? and ^ commands. !W4(?)aaA6(g)5(:) c*!9d*aAx 6(g)5(^) !9c/d*aAMd !Q or JJ uTo run a program 1. While the program list is on the display, use f and c to highlight the name of the program you want to run. 2. Press 1 (EXE) or w to run the program. Let’s try running the program we input above. Length of One Side (A) Surface Area (S) Volume (V) 7 cm 169.7409791 cm2 161.6917506 cm3 10 cm 346.4101615 cm2 471.
Programming Examples 20- 2 w ·· ·· ··· ··· · · • Pressing w while the program’s final result is on the display re-executes the program. P.378 • You can also run a program while in the RUN Mode by inputting: Prog ”” w. • An error occurs if the program specified by Prog ”” cannot be found.
20-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.
20-4 Calculating the Number of Bytes Used by a Program There are two types of commands: 1-byte* commands and 2-byte* commands. * A byte is a unit of memory that can be used for storage of data. • Examples of 1-byte commands: sin, cos, tan, log, (, ), A, B, C, 1, 2, etc. • Examples of 2-byte commands: Lbl 1, Goto 2, etc. While the cursor is located inside of a program, each press of d or e causes the cursor to move one byte. P.
20-5 Secret Function When inputting a program, you can protect it with a password that limits access to the program contents to those who know the password. Password protected programs can be executed by anyone without inputting the password. uTo register a password Example To create a program file under the name AREA and protect it with the password CASIO 1. While the program list is on the display, press 3 (NEW) and input the file name of the new program file. 3(NEW) AREA 2.
Secret Function 20- 5 2. Press 2 (EDIT). 3. Input the password and press w to recall the program. • The message “Mismatch” appears if you input the wrong password.
20-6 Searching for a File There are three different methods for searching for a specific file name. uTo find a file using scroll search Example To use scroll search to recall the program named OCTA 1. While the program list is on the display, use f and c to scroll through the list of program names until you find the one you want. 1 2 3 4 5 6 2. When the highlighting is located at the name of the file you want, press 2 (EDIT) to recall it.
Searching for a File 20- 6 2. Press w to search. • All files whose file names start with the characters you input are recalled. • If there is no program whose file name starts with the characters you input, the message “Not Found” appears on the display. If this happens, press J to clear the error message. 3. Use f and c to highlight the file name of the program you want to recall and then press 2 (EDIT) to recall it.
20-7 Searching for Data Inside a Program Example To search for the letter “A” inside the program named OCTA 1. Recall the program. 2. Press 3 (SRC) and input the data you want to search for. 3(SRC) aA • You cannot specify the newline symbol (_) or display command (^) for the search data. 3. Press w to begin the search. The contents of the program appear on the screen with the cursor located at the first instance of the data you specified. Indicates search operation is in progress 4.
20-8 Editing File Names and Program Contents uTo edit a file name Example To change the name of a file from TRIANGLE to ANGLE 1. While the program list is on the display, use f and c to move the highlighting to the file whose name you want to edit and then press 6 (g) 2 (REN). 2. Make any changes you want. DDD 3. Press w to register the new name and return to the program list.
20 - 8 Editing File Names and Program Contents Use TETRA as the file name. Length of One Side (A) Surface Area (S) Volume (V) A 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 tetrahedron for which the length of one side is known. 2 S = 3 A2, V = –––– A3 12 Use the following key operations when inputting the program. Length of One Side A .. !W4(?)aaA6(g)5(:) Surface Area S ............
Editing File Names and Program Contents 20- 8 cd![bc D !Q Let’s try running the program. Length of One Side (A) Surface Area (S) Volume (V) 7 cm 84.87048957 cm2 40.42293766 cm3 10 cm 173.2050808 cm2 117.8511302 cm3 15 cm 389.7114317 cm2 397.
20-9 Deleting a Program There are two methods for deletion of a file name and its program. uTo 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 4 (DEL). 3. Press 1 (YES) to delete the selected program or 6 (NO) to abort the operation without deleting anything. uTo delete all programs 1. While the program list is on the display, press 5 (DEL·A). 2.
20-10 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. Program Menu Press ! W to display the program menu. • {COM}/{CTL}/{JUMP}/{CLR}/{DISP}/{REL}/{I/O} • {?} ... {input command} • {^} ... {output command} • { : } ...
- 10 Useful Program Commands k DISP (display command menu) Selecting {DISP} from the program menu displays the following function menu items. u {Stat}/{Grph}/{Dyna} ... {statistical graph}/{graph}/{Dynamic Graph} draw u {F-Tbl} ... {Table & Graph command menu} The following are the items that appear in the above menu. • {Tabl}/{G-Con}/{G-Plt} ... {DispF-Tbl}/{DrawFTG-Con}/{DrawFTG-Plt} command u {R-Tbl} ...
20-11 Command Reference k Command Index Break ..................................................................................... 378 ClrGraph ................................................................................ 382 ClrList .................................................................................... 382 ClrText ................................................................................... 382 DispF-Tbl, DispR-Tbl .............................................................
20- 11 Command Reference The following are conventions that are used in this section when describing the various commands. Boldface Text ............. Actual commands and other items that always must be input are shown in boldface. {Curly Brackets} ......... Curly brackets are used to enclose a number of items, one of which must be selected when using a command. Do not input the curly brackets when inputting a command. [Square Brackets] ...... Square brackets are used to enclose items that are optional.
Command Reference 20- 11 : (Multi-statement Command) Function: Connects two statements for sequential execution without stopping. Description: 1. Unlike the output command (^), statements connected with the multistatement command are executed non-stop. 2. The multi-statement command can be used to link two calculation expressions or two commands. 3. You can also use a carriage return indicated by _ in place of the multistatement command.
20- 11 Command Reference If~Then~IfEnd Function: The Then-statement is executed only when the If-condition is true (nonzero). The IfEnd-statement is always executed: after the Then-statement is executed or directly after the If-condition when the If-condition is false (0). Syntax: If numeric expression _ : ^ Then _ : ^ _ : ^ IfEnd Parameters: condition, numeric expression Description: This command is almost identical to If~Then.
20- 11 Command Reference If~Then~Else~IfEnd Function: The Then-statement is executed only when the If-condition is true (non-zero). The Else-statement is executed when the If-condition is false (0). The IfEnd-statement is always executed following either the Then-statement or Else-statement.
20- 11 Command Reference Parameters: • control variable name: A to Z • starting value: value or expression that produces a value (i.e. sin x, A, etc.) • ending value: value or expression that produces a value (i.e. sin x, A, etc.) Description: 1. When the starting value of the control variable is greater than the ending value, execution continues from the statement following Next, without executing the statements between For and Next. 2.
Command Reference 20- 11 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. Making the starting value greater than the ending value and specifying a negative step value causes the control variable to be decremented with each execution. Example: For 1 → A To 10 Step 0.1_ A×3→B_ B^ Next Do~LpWhile Function: This command repeats specific commands as long as its condition is true (non-zero).
20- 11 Command Reference 2. Since the condition comes after the While-statement, the condition is tested (checked) before the commands inside the loop are executed. Example: 10 → A_ While A > 0_ A – 1 → A_ ”GOOD”_ WhileEnd k Program Control Commands (CTL) Break Function: This command breaks execution of a loop and continues from the next command following the loop. Syntax: Break _ Description: 1. This command breaks execution of a loop and continues from the next command following the loop. 2.
Command Reference Main Routine A 20- 11 Subroutines D Prog ”D” Prog ”C” C E Prog ”E” Prog ”I” Prog ”J” Level 2 Level 3 Level 1 I J 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. A Goto~Lbl command inside of a subroutine is valid inside of that subroutine only.
20- 11 Command Reference 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.
Command Reference 20- 11 2. This command can be used to loop back to the beginning of a program or to jump to any location within the program. 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 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.
20- 11 Command Reference Parameters: left side/right side: variable (A to Z, r, θ), numeric constant, variable expression (such as: A × 2) P.387 relational operator: =, G, >, <, ≥, ≤ 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.
Command Reference 20- 11 k Display Commands (DISP) DispF-Tbl, DispR-Tbl Function: These commands display numeric tables. Syntax: DispF-Tbl_ DispR-Tbl_ Description: 1. These commands generate numeric tables during program execution in accordance with conditions defined within the program. 2. DispF-Tbl generates a function table, while DispR-Tbl generates a recursion table. DrawDyna Function: This command executes a Dynamic Graph draw operation.
20- 11 Command Reference DrawR-Con, DrawR-Plt Function: These commands graph recursion expressions, with an(bn) as the vertical axis and n as the horizontal axis. Syntax: DrawR-Con_ DrawR-Plt_ Description: 1. These commands graph recursion expressions, with an(bn) as the vertical axis and n as the horizontal axis, in accordance with conditions defined within the program. 2. DrawR-Con produces a connect type graph, while DrawR-Plt produces a plot type graph.
Command Reference 20- 11 Description: 1. This command graphs convergence/divergence of a recursion expression (WEB graph). 2. Omitting the number of lines specification automatically specifies the default value 30. k Input/Output Commands (I/O) Getkey Function: This command returns the code that corresponds to the last key pressed. Syntax: Getkey_ Description: 1. This command returns the code that corresponds to the last key pressed.
20- 11 Command Reference Syntax: Locate , , Locate , , Locate , , ”” [Example] Locate 1, 1, ”AB”_ Parameters: • • • • • line number: number from 1 to 7 column number: number from 1 to 21 value: numeric value variable name: A to Z string: character string Description: 1. This command displays values (including variable contents) or text at a specific location on the text screen. 2.
Command Reference 20- 11 Send ( Function: This command sends data to an external device. Syntax: Send () Description: 1. This command sends data to an external device. 2. The following types of data can be sent by this command.
20-12 Text Display You can include text in a program by simply enclosing it between double quotation marks. Such text appears on the display during program execution, which means you can add labels to input prompts and results. Program Display ?→X ? ”X =” ? → X X=? • If the text is followed by a calculation formula, be sure to insert a display command (^), a carridge return (_) or multi-statement command (:) between the text and calculation.
20-13 Using Calculator Functions in Programs k Using Matrix Row Operations in a Program P.80 These commands let you manipulate the rows of a matrix in a program. • For this type of program, be sure to use the MAT Mode to input the matrix, and then switch to the PRGM Mode to input the program. uTo swap the contents of two rows (Swap) Example 1 To swap the values of Row 2 and Row 3 in the following matrix: Matrix A = 1 2 3 4 5 6 The following is the syntax to use for this program.
20- 13 Using Calculator Functions in Programs uTo calculate a scalar multiplication and add the results to another `Row+) row (` Example 3 To calculate the product of Row 2 of the matrix in Example 1 and the scalar 4, then add the result to row 3 The following is the syntax to use for this program. `Row+ 4, A, 2, 3 Matrix name Multiplier Executing this program produces the following result.
Using Calculator Functions in Programs 20- 13 Y = Type_ 3 4431 ”X ^ 4– X ^ 3– 24X2 + 4X + 80” → Y1_ 4 J41JJ G SelOn 1_ 5 4411J 6 Orange G1_ 6 42 7 DrawGraph 7 !W622 3 4 5 CFX Executing this program produces the result shown here. k Using Dynamic Graph Functions in a Program P.182 Using Dynamic Graph functions in a program makes it possible to perform repeated Dynamic Graph operations. The following shows how to specify the Dynamic Graph range inside a program.
20- 13 Using Calculator Functions in Programs k Using Table & Graph Functions in a Program P.206 Table & Graph functions in a program can generate numeric tables and perform graphing operations. The following shows various types of syntax you need to use when programming with Table & Graph functions.
Using Calculator Functions in Programs 20- 13 k Using Recursion Table & Graph Functions in a Program P.218 Incorporating Recursion Table & Graph functions in a program lets you generate numeric tables and perform graphing operations. The following shows various types of syntax you need to use when programming with Recursion Table & Graph functions. • Recursion formula input an+1 Type_ .... Specifies recursion type.
20- 13 Using Calculator Functions in Programs Executing this program produces the results shown here. Numeric Table Recursion graph k Using List Sort Functions in a Program P.234 These functions let you sort data in lists into ascending or descending order.
Using Calculator Functions in Programs 20- 13 k Using Statistical Calculations and Graphs in a Program P.250 Including statistical calculations and graphing operations into program lets you calculate and graph statistical data.
20- 13 Using Calculator Functions in Programs • The following is a typical graph condition specification for a regression graph. S-Gph1 DrawOn, Linear, List1, List2, List3, Blue _ The same format can be used for the following types of graphs, by simply replacing “Linear” in the above specification with the applicable graph type. P.254 Linear Regression: ......... Linear Med-Med: ....................... Med-Med Quadratic Regression: ... Quad Cubic Regression: .......... Cubic Quartic Regression: .......
Using Calculator Functions in Programs 20- 13 k Performing Statistical Calculations • Single-variable statistical calculation 1 1-Variable List 1, List 2 Frequency data (Frequency) x-axis data (XList) 1 4161 • 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* Frequency data (Frequency) y-axis data (YList) x-axis data (
20- 13 Using Calculator Functions in Programs • Sine regression statistical calculation SinReg List 1, List 2 y-axis data (YList) x-axis data (XList) • Logistic regression statistical calculation LogisticReg List 1, List 2 y-axis data (YList) x-axis data (XList) 398