Chapter Programming 19-1 19-2 19-3 19-4 19-5 19-6 19-7 19-8 19-9 19-10 19-11 19-12 19-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 19
19-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.
19-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 cm 3 10 cm cm2 cm 3 15 cm cm2 cm 3 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.
19 - 2 Programming Examples • The cursor changes form to indicate alpha character input. • The following are the characters you can use in a file name: A through Z, r, θ, spaces, [, ], {, }, ’, ”, ~, 0 through 9, ., +, –, ×, ÷ • Note, however, that v and . cannot be input for the name of a program that contains binary, octal, decimal, or hexadecimal calculations. P.5 • Use 1 (RUN) to input a program for general calculations (a program to be executed in the COMP Mode).
Programming Examples 19 - 2 u To change modes in a program • Pressing 4 (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 “To select an icon”, as well as the sections of this manual that describe what you can do in each mode.
19 - 2 Programming Examples The following function key menu appears if you press !Z while inputting a program that contains binary, octal, decimal, or hexadecimal calculation. !Z 1 2 3 4 5 6 Actual program contents are identical to manual calculations. The following shows how the calculation of the surface area and volume of a regular octahedron would be calculated using a manual calculation. Surface Area S .. c*!9d* xw Volume V ...........
Programming Examples 19 - 2 u To 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 2 169.7409791 cm 161.6917506 cm3 10 cm 346.4101615 cm2 471.4045208 cm3 15 cm 779.4228634 cm2 1590.
19 - 2 Programming Examples w • Pressing w while the program’s final result is on the display re-executes the program. P.334 • 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.
19-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.
19-4 Calculating the Number of Bytes Used by a Program This unit comes with 26 kbytes of memory. A byte is a unit of memory that can be used for storage of data. There are two types of commands: 1-byte commands and 2-byte commands. • 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.
19-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 1 2 3 4 5 6 2.
19 - 5 Secret Function u To recall a program Example To recall the file named AREA which is protected by the password CASIO 1. In the program list, use f and c to move the highlighting to the name of the program you want to recall. 2. Press 2 (EDIT). 2(EDIT) 3. Input the password and press w to recall the program. • The message “Mismatch” appears if you input the wrong password.
19-6 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.
19 - 6 Searching for a File 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 6 (g) 1 (SRC) and input the initial characters of the file you want to find. 6(g)1(SRC) OCT 2. Press w to search. w • All files whose file names start with the characters you input are recalled.
19-7 Searching for Data Inside a Program Example To search for the letter “A” inside the program named OCTA 1. Recall the program, press 3 (SRC), and input the data you want to search for. 1 2 3 4 5 6 3(SRC) aA • You cannot specify the newline symbol (_) or display command (^) for the search data. 2. Press w to begin the search. The contents of the program appears on the screen with the cursor located at the first instance of the data you specified. w Indicates search operation is in progress 3.
19-8 Editing File Names and Program Contents u To 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). 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.
Editing File Names and Program Contents Example 2 19 - 8 To use the OCTA program to create a program that calculates the surface area and volume of regular tetrahedrons when the length of one side is known Use TETRA as the file name. A Length of One Side (A) Surface Area (S) Volume (V) 7 cm 2 cm 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.
19 - 8 Editing File Names and Program Contents w 1 2 3 4 5 6 2. Edit the program contents. 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 84.87048957 cm2 40.42293766 cm3 10 cm 173.2050808 cm2 117.8511302 cm3 15 cm 389.7114317 cm2 397.
Editing File Names and Program Contents 19 - 8 w baw w 331
19-9 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 4 (DEL). 4(DEL) 1 2 3 4 5 6 3. Press 1 (YES) to delete the selected program or 6 (NO) to abort the operation without deleting anything. u To delete all programs 1.
19-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. !W 1 2 3 4 5 6 1 (COM) ...... Program command menu 2 (CTL) ........ Control command menu 3 (JUMP) ..... Jump command menu 4 (?) ............ Input command 5 (^) ........... Output command 6 (g) ...........
19 - 10 Useful Program Commands 6(g) 1 2 3 4 5 6 1 (For) ......... For command 2 (To) ........... To command 3 (Step) ....... Step command 4 (Next) ....... Next command 6 (g) ........... Next menu 6(g) 1 2 3 4 5 6 1 (Whle) ...... While command 2 (WEnd) ..... WhileEnd command 3 (Do) .......... Do command 4 (Lp•W) ...... LpWhile command 6 (g) ........... Previous menu Control Command Menu (CTL) While the program menu is on the display, press 2 (CTL) to display the control command menu.
Useful Program Commands 19 - 10 Clear Command Menu (CLR) While the program menu is on the display, press 6 (g) 1 (CLR) to display the clear command menu. 6(g)1(CLR) 1 2 3 4 5 6 1 (Text) ........ ClrText command 2 (Grph) ...... ClrGraph command 3 (List) ......... ClrList command Display Command Menu (DISP) While the program menu is on the display, press 6 (g) 2 (DISP) to display the display command menu. 6(g)2(DISP) 1 2 3 4 5 6 1 (Stat) ........ DrawStat command 2 (Grph) ...... DrawGraph command 3 (Dyna) .
19 - 10 Useful Program Commands Pressing 5 (R•Tbl) while the display command menu is on the display causes the recursion calculation and recursion formula graph command menu to appear. 5(R•Tbl) 1 2 3 4 5 6 1 (Tabl) ........ DispR-Tbl command 2 (Web) ....... DrawWeb command 3 (an•Cn) ..... DrawR-Con command 4 (Σa•Cn) .... DrawRΣ-Con command 5 (an•Pl) ...... DrawR-Plt command 6 (Σa•Pl) ......
19-11 Command Reference k Command Index Break ..................................................................................... 343 ClrGraph ................................................................................ 347 ClrList .................................................................................... 347 ClrText ................................................................................... 347 DispF-Tbl, DispR-Tbl .............................................................
19 - 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 19 - 11 3. You can also use a carriage return indicated by _ in place of the multi-statement command. _ (Carriage Return) Function: Connects two statements for sequential execution without stopping. Description: 1. Operation of the carriage return is identical to that of the multi-statement command. 2. Using a carriage return in place of the multi-statement command makes the displayed program easier to read.
19 - 11 Command Reference Description: This command is almost identical to If~Then. The only difference is that the IfEndstatement is always executed, regardless of whether the If-condition is true (nonzero) or false (0). Example: If A = 0 _ Then ”A = 0” _ IfEnd _ ”END” 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).
Command Reference 19 - 11 Example: Lbl 1:? → A _ If A > 0 And A < 10 _ Then ”GOOD”_ Else Goto 1_ IfEnd The above program displays the message “GOOD” whenever a value that is greater than zero and less than 10 is input. Any other value prompts for input again. For~To~Next Function: This command repeats everything between the For-statement and the Next-statement.
19 - 11 Command Reference Syntax: For → To Step _ : ^ Next 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.) step value: numeric value (omitting this value sets the step to 1) Description: 1. This command is basically identical to For~To~Next.
Command Reference Syntax: While _ : ^ 19 - 11 ~ WhileEnd Parameters: expression 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.
19 - 11 Command Reference 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.
Command Reference 19 - 11 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.
19 - 11 Command Reference 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.
Command Reference 19 - 11 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 (_).
19 - 11 Command Reference 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. Syntax: DrawDyna_ Description: This command performs a Dynamic Graph draw operation during program execution in accordance with the drawing conditions defined within the program.
Command Reference 19 - 11 2. DrawR-Con produces a connect type graph, while DrawR-Plt produces a plot type graph. 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.
19 - 11 Command Reference 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. 79 69 59 49 78 68 58 48 39 29 28 38 27 77 67 57 47 76 66 56 46 36 26 75 65 55 45 35 25 37 74 64 54 44 73 63 53 43 33 72 62 52 42 32 71 61 51 41 31 2.
Command Reference 19 - 11 Description: 1. This command displays values (including variable contents) or text at a specific location on the text screen. 2. The row is designated by a value from 1 to 7, which the column is designed by a value from 1 to 21. (1, 1) → ← (21, 1) (1, 7) → ← (21, 7) Example: Cls_ Locate 7, 1, ”CASIO FX” This program displays the text “CASIO FX” in the center of the screen. • In some cases, the ClrText command should be executed before running the above program.
19 - 11 Command Reference k Conditional Jump Relational Operators (REL) =, G, >, <, ≥, ≤ Function: These relational operators are used in combination with the conditional jump command. Syntax: ⇒ _ : ^ Parameters: left side/right side: variable (A to Z, r, θ), numeric constant, variable expression (such as: A × 2) relational operator: =, G , >, <, ≥, ≤ Description: 1.
19-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 (^) between the text and calculation. • Inputting more than 21 characters causes the text to move down to the next line.
19-13 Using Calculator Functions in Programs k Using Matrix Row Operations in a Program P.92 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. u To 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.
Using Calculator Functions in Programs 19 - 13 u To calculate a scalar product and add the results to another row ` Row+) (` Example 3 To calculate the scalar product of Row 2 of the matrix in Example 1, multiplying by 4, and 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.
19 - 13 Using Calculator Functions in Programs 5 G SelOn 1_ 5 4411J 6 DrawGraph 6 !W622 Executing this program produces the result shown here. k Using Dynamic Graph Functions in a Program P.208 Using Dynamic Graph functions in a program makes it possible to perform repeat Dynamic Graph operations. The following shows how to specify the Dynamic Graph range inside a program.
Using Calculator Functions in Programs 19 - 13 k Using Table & Graph Functions in a Program P.236 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.
19 - 13 Using Calculator Functions in Programs k Using Recursion Table & Graph Functions in a Program P.250 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.
Using Calculator Functions in Programs 19 - 13 Executing this program produces the results shown here. Numeric Table w Recursion graph w k Using List Sort Functions in a Program P.265 These functions let you sort the data in lists into ascending or descending order.
19 - 13 Using Calculator Functions in Programs • The following is a typical graph condition specification for a scatter diagram or x, y line graph. S-Gph1 DrawOn, Scatter, List1, List2, 1, Square_ In the case of an x, y line graph, replace “Scatter” in the above specification with “ xyLine”. • The following is a typical graph condition specification for a single-variable graph.
Using Calculator Functions in Programs 19 - 13 k Performing Statistical Calculations • Single-variable statistical calculation 1 1-Variable List1, List2 Frequency data (Frequency) x-axis data (XList) 1 4161 • Paired-variable statistical calculation 2-Variable List1, List2, List3 Frequency data (Frequency) y-axis data (YList) x-axis data (XList) • Regression statistical calculation 1 LinearReg List1, List2, List3 Calculation type* Frequency data (Frequency) y-axis data (YList) x-axis data (XList)