Chapter Programming 8-1 8-2 8-3 8-4 8-5 8-6 8-7 8-8 Basic Programming Steps Program Mode Function Keys Editing Program Contents File Management Command Reference Using Calculator Functions in Programs Program Mode Command List Program Library This unit comes with approximately 144 kbytes of memory. • You can check how much memory has been used and how much remains by entering the SYSTEM Mode from the Main Menu, and then pressing 1(Mem). See “9-2 Memory Operations” for details.
8-1-1 Basic Programming Steps 8-1 Basic Programming Steps Description Commands and calculations are executed sequentially, just like manual calculation multistatements. Set Up 1. From the Main Menu, enter the PRGM Mode. When you do, a program list appears on the display. Selected program area (use f and c to move) Files are listed in the alphabetic sequence of their names. Execution 2. Register a file name. 3. Input the program. 4. Run the program.
8-1-2 Basic Programming Steps ○ ○ ○ ○ ○ Example 1 To calculate the surface area (cm2) and volume (cm3) of three regular octahedrons when the length of one side is 7, 10, and 15 cm, respectively. Store the calculation formula under the file name OCTA. 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 A is known.
8-2-1 Program Mode Function Keys 8-2 Program Mode Function Keys • {NEW} ... {new program} u When you are registering a file name • {RUN}/{BASE} ... {general calculation}/{number base} program input • {Q Q} ... {password registration} • {SYBL} ... {symbol menu} u When you are inputting a program —— 1(RUN) … default • {JUMP} ... {top}/{bottom} of program • {SRC} ... {search} • {MAT}/ {STAT}/{LIST}/{GRPH}/{DYNA}/{RECR} ...
8-2-2 Program Mode Function Keys u When you are inputting a program —— 2(BASE)*1 • {JUMP}/{SRC} • {d~o} ... {decimal}/{hexadecimal}/{binary}/{octal} value input • {LOG} ... {logical operators} • {DISP} ... conversion of displayed value to {decimal}/{hexadecimal}/{binary}/{octal} • {SYBL} ... {symbol menu} • Pressing !J(PRGM) displays the following PRGM (PROGRAM) menu. • {Prog}/{JUMP}/{?}/{^ ^} • {= ≠ <} ... {logical operator menu} • {:} .........
8-3-1 Editing Program Contents 8-3 Editing Program Contents k 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 that require debugging.
8-3-2 Editing Program Contents k Using an Existing Program to Create a New Program Sometimes you can input a new program by using a program already in memory as a base. Simply recall the existing program, make the changes you need, and then execute it. ○ ○ ○ ○ ○ Example 2 To use the OCTA program (page 8-1-2) to create a program that calculates the surface area (cm 2) and volume (cm3) of regular tetrahedrons when the length of one side is 7, 10, and 15 cm Use TETRA as the file name.
-3-3 Editing Program Contents Now edit OCTA to produce the TETRA program. 1. Edit the program name. 6(g)2(REN)ATETRAw 2. Edit the program contents. 2(EDIT) eeeeDD cdDbc i 3. Try running the program.
8-3-4 Editing Program Contents k Searching for Data Inside a Program ○ ○ ○ ○ ○ Example To search for the letter “A” inside the program named OCTA 1. Recall the program. 2. Press 2(SRC) or w and input the data you want to find. 2(SRC) av(A) 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.*1 4. Each press of w or 1(SRC) causes the cursor to jump to the next instance of the data you specified.
8-4-1 File Management 8-4 File Management k 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. • The name that starts with the characters you input highlights.
8-4-2 File Management k Editing 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. The program list is resorted according to the changes you made in the file name. k Deleting a Program u To delete a specific program 1.
8-4-3 File Management u To delete all programs 1. While the program list is on the display, press 5(DEL·A). 2. Press w(Yes) to delete all the programs in the list or i(No) to abort the operation without deleting anything. • You also can delete all programs by entering the SYSTEM Mode from the Main Menu, and then pressing 1(Mem) to display the memory management screen. See “9-2 Memory Operations” for details.
8-4-4 File Management 3. Press w to register the file name and password. Now you can input the contents of the program file. 4. After inputting the program, press !i(QUIT) to exit the program file and return to the program list. Files that are password protected are indicated by an asterisk to the right of the file name. k Recalling a Password Protected Program ○ ○ ○ ○ ○ Example To recall the file named AREA which is protected by the password CASIO 1.
8-5-1 Command Reference 8-5 Command Reference k Command Index Break ............................................................................................................... 8-5-6 ClrGraph ....................................................................................................... 8-5-11 ClrList ............................................................................................................ 8-5-11 ClrText .........................................................................
8-5-2 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] ........
8-5-3 Command Reference ^ (Output Command) Function: Displays an intermediate result during program execution. Description: • This command momentarily interrupts program execution and displays alpha character text or the result of the calculation immediately before the command. • The output command should be used at locations where you would normally press the w key during a manual calculation. : (Multi-statement Command) Function: Connects two statements for sequential execution without stopping.
8-5-4 Command Reference k Program Commands (COM) 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 IfEndstatement is always executed following either the Then-statement or Else-statement.
8-5-5 Command Reference Description: • The default step value is 1. • 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. Do~LpWhile Function: This command repeats specific commands as long as its condition is true (nonzero).
8-5-6 Command Reference While~WhileEnd Function: This command repeats specific commands as long as its condition is true (nonzero). Syntax: While numeric expression _ : ^ _ : ^ WhileEnd Parameters: expression Description: • 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.
8-5-7 Command Reference Prog Function: This command specifies execution of another program as a subroutine. In the RUN • MAT Mode, this command executes a new program. Syntax: Prog ”file name” Example: Prog ”ABC” Description: • Even when this command is located inside of a loop, its execution immediately breaks the loop and launches the subroutine. • This command can be used as many times as necessary inside of a main routine to call up independent subroutines to perform specific tasks.
8-5-8 Command Reference Return Function: This command returns from a subroutine. Syntax: Return Description: Execution of the Return command inside a main routine causes execution of the program to stop. Execution of the Return command within a subroutine terminates the subroutine and returns to the program from which the subroutine was jumped to. Stop Function: This command terminates execution of a program. Syntax: Stop Description: • This command terminates program execution.
8-5-9 Command Reference 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. Syntax: Variable Value G 0 Dsz : Variable Value = 0 _ : ^ Parameters: variable name: A to Z, r, θ [Example] Dsz B : Decrements the value assigned to variable B by 1.
8-5-10 Command Reference Goto~Lbl Function: This command performs an unconditional jump to a specified location. Syntax: Goto
8-5-11 Command Reference Isz Function: This command is a count jump that increments the value of a control variable by 1, and then jumps if the current value of the variable is zero. Syntax: Variable Value G 0 Isz : _ : ^ Variable Value = 0 Parameters: variable name: A to Z, r, θ [Example] Isz A : Increments the value assigned to variable A by 1. Description: This command increments the value of a control variable by 1, and then tests (checks) it.
8-5-12 Command Reference ClrText Function: This command clears the text screen. Syntax: ClrText Description: This command clears text from the screen during program execution. ClrMat Function: This command deletes matrix data. Syntax: ClrMat ClrMat Parameters: matrix name: A to Z, Ans Description: This command deletes the data in the matrix specified by “matrix name”. All matrix data is deleted if nothing is specified for “matrix name”.
8-5-13 Command Reference DrawFTG-Con, DrawFTG-Plt No parameters Function: This command uses values in a generated table to graph a function. Description: • This command draws a function graph in accordance with current conditions. • DrawFTG-Con produces a connect type graph, while DrawFTG-Plt produces a plot type graph. DrawGraph No parameters Function: This command draws a graph. Description: • This command draws a graph in accordance with current conditions.
8-5-14 Command Reference DrawRΣ-Con, DrawRΣ-Plt No parameters Function: These commands use values in a generated table to graph a recursion expression with Σan(Σbn or Σ cn) as the vertical axis and n as the horizontal axis. Description: • These commands graph recursion expressions in accordance with current conditions, with Σan(Σbn or Σcn) as the vertical axis and n as the horizontal axis. • DrawRΣ-Con produces a connect type graph, while DrawRΣ-Plt produces a plot type graph.
8-5-15 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: • This command returns the code that corresponds to the last key pressed.
8-5-16 Command Reference Locate Function: This command displays alpha-numeric characters at a specific location on the text screen.
8-5-17 Command Reference Receive ( / Send ( Function: This command receives data from and sends data to a connected device. Syntax: Receive () / Send () Description: • This command receives data from and sends data to a connected device. • The following types of data can be received (sent) by this command.
8-5-18 Command Reference k Conditional Jump Relational Operators (REL) =, G, >, <, ≥, ≤ Function: These relational operators are used in combination with the conditional jump command.
8-6-1 Using Calculator Functions in Programs 8-6 Using Calculator Functions in Programs k 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 ”CASIO” CASIO ?→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.
8-6-2 Using Calculator Functions in Programs `Row) u To calculate a scalar multiplication (` ○ ○ ○ ○ ○ Example 2 To calculate the product of Row 2 of the matrix in Example 1 and the scalar 4 The following is the syntax to use for this program. `Row 4, A, 2_ Row Matrix name Multiplier Mat A Executing this program produces the following result.
8-6-3 Using Calculator Functions in Programs u To add two rows (Row+) ○ ○ ○ ○ ○ Example 4 To add Row 2 to Row 3 of the matrix in Example 1 The following is the syntax to use for this program. Row+ A, 2, 3_ the row number to be added to the row number to be added Matrix name Mat A Executing this program produces the following result. k Using Graph Functions in a Program You can incorporate graph functions into a program to draw complex graphs and to overlay graphs on top of each other.
8-6-4 Using Calculator Functions in Programs u Syntax of other graphing functions • V-Window View Window , , , , , , , , StoV-Win .............. area: 1 to 6 RclV-Win .............. area: 1 to 6 • Zoom Factor , ZoomAuto ........... Non-parameter • Pict StoPict ................ area: 1 to 20 RclPict ................
8-6-5 Using Calculator Functions in Programs k Using Dynamic Graph Functions in a Program 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.
8-6-6 Using Calculator Functions in Programs k Using Table & Graph Functions in a Program 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.
8-6-7 Using Calculator Functions in Programs k Using Recursion Table & Graph Functions in a Program 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.
8-6-8 Using Calculator Functions in Programs Example Program View Window 0, 1, 1, –0.2, 1, 1_ 1 63gc 3bc 3 3bd 4 J62cb 5 2cc 6 2cd 7 2cC 8 !J662fb 9 2fci 0 63bd 1 an+1 Type_ 2 3 ”–3an 2 + 3an ” → an+1_ 2 4 0 → R Start_ 5 6 → R End_ 6 0.01 → a0 _ 7 0.01 → an Start_ 8 DispR-Tbl^ 9 DrawWeb an +1, 30 0 Executing this program produces the results shown here.
8-6-9 Using Calculator Functions in Programs k Using Solve Calculation Function in a Program The following is the syntax for using the Solve function in a program. Solve( f(x), n, a, b) Upper limit Lower limit Initial estimated value Example Program K4h 1 1 Solve( 2X2 + 7X – 9, 1, 0, 1) • In the function f(x), only X can be used as a variable in the expression.
8-6-10 Using Calculator Functions in Programs The graph conditions that are required depends on the graph type. See “Changing Graph Parameters” (page 6-1-2). • The following is a typical graph condition specification for a scatter diagram or xyLine graph. S-Gph1 DrawOn, Scatter, List 1, List 2, 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 normal probability plot.
8-6-11 Using Calculator Functions in Programs • The following is a typical graph condition specification for a sinusoidal regression graph. S-Gph1 DrawOn, Sinusoidal, List 1, List 2 _ • The following is a typical graph condition specification for a logistic regression graph.
8-6-12 Using Calculator Functions in Programs • Paired-variable statistical calculation 1 2-Variable List 1, List 2, List 3 Frequency data (Frequency) y-axis data (YList) x-axis data (XList) 4gc 1 • Regression statistical calculation 1 LinearReg List 1, List 2, List 3 Calculation type* Frequency data (Frequency) y-axis data (YList) x-axis data (XList) 4gd 1 * Any one of the following can be specified as the calculation type. LinearReg .......... linear regression Med-MedLine ....
8-7-1 Program Mode Command List 8-7 Program Mode Command List RUN Program GRPH SelOn G_SelOn_ [OPTN] key Level 1 Level 2 Level 3 Command SelOff G_SelOff_ Level 1 Level 2 Level 3 Command MAT LIST STAT Swap Swap_ TYPE Y= Y=TYPE *Row *Row_ r= r=TYPE *Row+ *Row+_ Row+ Row+_ nPr P List List_ nCr C Dim Dim_ Ran# Ran#_ Param ParamTYPE Seq Seq( P( P( X=c X=cTYPE Min Min( Q( Q( S-GPH S-Gph1 S-Gph1_ Y> Y>Type Max Max( R( R( S-Gph2 S-Gph2_ Y< Y
8-7-2 Program Mode Command List [VARS] key x1 x1 [SHIFT][VARS](PRGM) key [CTRL][F3](SET UP) key Level 1 Level 2 Level 3 Command y1 y1 Level 1 Level 2 Level 3 Command Level 1 Level 2 Level 3 Command V-WIN Xmin Xmin x2 x2 Prog Prog_ ANGL Deg Deg Xmax Xmax y2 y2 JUMP Lbl Lbl_ Rad Rad Xscale Xscl x3 x3 Goto Goto_ Gra Gra Xdot Xdot y3 y3 lsz lsz_ Fix Fix_ Ymin Ymin GRPH Yn Y Dsz Dsz_ Sci Sci_ Ymax Ymax rn r ? ? Norm Norm Yscale Yscl Xtn Xt ^ ^ Eng
8-7-3 Program Mode Command List BASE Program [SHIFT][OPTN](V-Window)key [CTRL][F3](SETUP) key Level 1 Level 2 Level 3 Command Level 1 Level 2 Level 3 Command Level 1 Level 2 Level 3 Command V-Win ViewWindow_ d~o d d Dec Dec Sto StoV-Win_ h h Hex Hex Rcl RclV-Win_ b b Bin Bin o o Oct Oct Neg Neg_ Not Not_ and and or or xor xor xnor xnor 'Dec 'Dec 'Hex 'Hex 'Bin 'Bin 'Oct 'Oct LOG DISP [SHIFT][VARS](PRGM) key Level 1 Level 2 Level 3 Command Prog Prog_ JUMP
8-8-1 Program Library 8-8 Program Library • Be sure to check how many bytes of unused memory are remaining before attempting to perform any programming. Program Name Prime Factorization Description This program continually divides a natural number by factors until all its prime factors are produced. Purpose This program accepts input of natural number A, and divides it by B (2, 3, 5, 7....) to find the prime factors of A.
8-8-2 Program Library egcw w ww w 19990401
8-8-3 Program Library Program Name Arithmetic-Geometric Sequence Differentiation Description After inputting sequence terms 1, 2, and 3, this program determines whether it is an arithmetic sequence or geometric sequence based on the differences and ratios of the terms. Purpose This program determines whether a specific sequence is an arithmetic sequence or geometric sequence. ○ ○ ○ ○ ○ Example 1 ○ ○ ○ ○ ○ 5, 10, 15, ... Arithmetic sequence Example 2 5, 10, 20, ...
8-8-4 Program Library Example 1 Example 2 fw fw baw baw bf ca w w 19990401
8-8-5 Program Library Program Name Ellipse Description This program displays a number table of the following values based on input of the foci of an ellipse, the sum of the distance between the loci and foci, and the pitch (step size) of X. Y1: Coordinate values of upper half of ellipse Y2: Coordinate values of lower half of ellipse Y3: Distances between right focus and loci Y4: Distances between left focus and loci Y5: Sum of Y3 and Y4 Next, the program plots the foci and values in Y1 and Y2.
8-8-6 Program Library d wba wb w wua 19990401 19991201
8-8-7 Program Library Program Name Rotation Description This program draws an angle at the coordinate defined by an input vertex, and then rotates it to a specified angle around the vertex. Purpose This program demonstrates coordinate transformation using a matrix. Important! Deg must be set as the angle unit for this program.
8-8-8 Program Library dw fcde fcde ww wwfcde daw wwfcde ww 19990401 19991201
8-8-9 Program Library Program Name Interior Angles and Surface Area of a Triangle Description This program calculates the interior angles and surface area of a triangle defined by input coordinates for angles A, B, and C. Purpose This program calculates the interior angles and surface area of a triangle defined by coordinates for angles A, B, and C. Important! Inputting the same coordinates for any two angles (A, B, C) causes an error.
8-8-10 Program Library b awaw bwaw aw9d w 19990401