Vous êtes sur la page 1sur 12

LEFT-HAND SUM PROGRAM

WITH EXTENSION TO RIGHT-HAND SUMS AND THE TRAPEZOID RULE

Texas Instruments TI-82 and TI-83


This program inputs A,B,N and evaluates the left-hand sum on [A,B], with N equal subdivisions, of the function
f(X) stored as an expression in location Y1.
General: To type an upper case letter, press ALPHA key, followed by the letter. To begin entering the program,
press the PGRM key, and select NEW from the menu. The calculator will go into ALPHA mode and prompt
you to enter the name. Type in (for example) LEFTSUM and press ENTER. The program now displays a colon
: which must appear at the beginning of each command.
To enter the program commands (all the words in the program that start with a Capital Letter), press PRGM
key, then select one of the two menus:

CTL (Control commands)


I/O (Imput-output commands).

Select the command you need from the appropriate menu. After typing each command, press the ENTER key.
(You may also stay on the same line by typing a colon : (ALPHA .)
Commands:

Remarks and keying instructions:

:Prompt A,B,N

Program asks for A, B and N. Prompt


is 2 on the I/O menu.
For ->, press STO key. For X, Press the
[X,T,theta] key. This command sets the
variable X equal to the input A.
0 is zero! (S will be the running total
of the sum)
I counts the number of steps taken
- is the key to the right of the 6 key.
For /, press the division key,
which is under the ^ key.
This spot in the program is labelled P.
Lbl is 9 on the CTL menu; access this menu
with the PRGM key.
For Y1 (the value of the function you are
summing, at the current X) press Y-VARS
(2nd VARS), select Function, select Y1,
ENTER. For *, press the multiplication
key, which is to the right of the 9 key.
Update X.
IS>( is on the CTL menu. The comma is the
key below SIN. This command ("Increment
and Skip on test") adds 1 to I. If the
new I-value is greater than N, the next
instruction in the program is skipped.
(So if I+1>N, i.e. I is greater than or
equal to N, program skips to Disp
"LSUM",S; other-wise it recycles to the
Lbl P command.)

:A->X
:0->S
:1->I
:(B-A)/N->H
:Lbl P
:S+Y1*H->S

:X+H->X
:IS>(I,N)

:Goto P
:Disp "LSUM",S

" is ALPHA +

Ending: After pressing the ENTER key for the last command, press the QUIT (2nd MODE) key.

Running the program: First you have to type in the expression for the function you want to sum. Press the Y=
key (under screen) and enter your function as Y1. Use the [X,T,theta] key for your variable. As a test, put in xcubed, i.e. [X,T,theta], then ^, then 3, then ENTER. Then press QUIT. Now to run the sum, press PRGM, select
EXEC, and select LEFTSUM (It is selected automatically if it is the only program you have.) The screen will
display a prompt pgrmLEFTSUM. press ENTER. Enter the A, B, N you want at the question mark (?) prompts.
Some trouble shooting: When typing in the program, be sure to use the STO key as above , and not the equality
(=) key!!
Check: For Y1=f(x)=x^3, lower limit 1, upper limit 3, and N = 100, left-hand sum should be 19.7408.
Exercise: Rewrite this program to give right-hand sums.
RIGHT HAND SUMS AND THE TRAPEZOID RULE
Add these instructions to the end of the program:
:A->X
:S-Y1*H->R
:B->X
:R+Y1*H->R
:Disp "RSUM",R
:(S+R)/2->T
:Disp "TRAP",T

For ->,X,Y1,*,Disp," follow the keying


instructions above.

Check: For Y1=f(X)=sin X, lower limit 0, upper limit pi/2, and N = 10, LSUM = .91940317, RSUM =
1.076482803, TRAP = .9979429864.

SIMPSON'S RULE PROGRAM


TI-82 and TI-83
General: This program inputs A,B,N and evaluates the Simpson method sum on [A,B], with N equal subdivisions, of the
function f(X) stored as an expression in location Y1. See instructions for the Left and Right sum programs for details on
how to enter programs on the TI-82. Remember that "->" below is obtained by pressing the "STO" key (above "ON" key).
Commands:

Remarks and keying instructions

Prompt A,B,N

Receive the interval endpoints and


number of subdivision points from user.
Prompt is 2 on the I/O menu, reached
via the PRGM button.

iPart ((N+1)/2)->M

The function iPart means "integer


part", for example iPart(3.2)=3. To
enter it, use the MATH menu, then
press right-arrow for "NUM", followed
by 2 for iPart. For /, press the
division key, under the the ^ key.
The reason for this line is that
Simpson's rule requires n to be even.
We want m=n/2, but if the value of n
entered is not an even integer, m
would have a fractional part. The
more complicated formula used here
ensures that eg n=3 and n=4 both give
m=2.

2*M->N

By setting n=2*m, we have made sure that n


will be even in what follows.

(B-A)/N->H

H is what we usually call "delta-x",


the subinterval size.

A->X

This initializes x to equal the first


point x0 in the subdivision.

Y1->S

Initialize the sum s to equal f(x) = f(x0).


"Y1" is obtained by pressing "2nd"
then "VARS" for the Y-Vars menu, then
1 for Functions and 1 again for Y1.
Y1 must be defined to give the
function f which we are integrating
(see below)

FOR(I,0,M-1,1)

Begin a loop with counter I, beginning


at 0 and continuing through M-1,
incrementing by 1 each time. Thus, I is set
to 0 (zero) here, and the instructions
below are executed until the command
END is reached. Then I is incremented
by 1 and we go through the same list
of instructions again. This repeats
for each value of I including M-1. Finally
after running through the instructions
the last time with I=M-1, we

proceed with the first command


following the END.
X+H->X

Move to the next point of the subdivision.

S+4*Y1->S

Add 4*f(x) to the sum s.

X+H->X

Move to the next point of the subdivision.

S+2*Y1->S

Add 2*f(x) to the sum s.

End

Increment I by 1, then go back to beginning


of FOR loop unless I has reached M.

S-Y1->S

The program gets here with x = b, Y1 = f(b)


and s=f(x0)+4f(x1)+2f(x2)+...+4f(x(n-1))+2f(xn),
but in Simpson's rule the last term in s should
be f(xn), so we need to subtract off one lot of
f(xn)=f(b), which is what we do in this line.

S*H/3->R

The result (r) of Simpson's rule is s*h/3.

Disp "RESULT ",R

The calculator will display RESULT value

Ending: After pressing the ENTER key for the last command, Press the QUIT ("2nd" "MODE") key.
Running the program: First you have to type in the expression for the function you want to sum. Press the Y= key (under
screen) and enter your function as Y1. Use the [X,T,theta] key for your variable. As a test, put in x to the 4th, i.e.
[X,T,theta], then "^", then 4, then ENTER. Then press QUIT. Now to run the sum, press PRGM, select EXEC, and select
SIMPSON (If that's what you called it.) The screen will display a prompt pgrmSIMPSON. press ENTER. Enter the A, B, N
you want at the question mark (?) prompts.
Check: For Y1=f(x)= x^4, lower limit A = 0, upper limit B = 1, and N = 4, Simpson sum should be: .2005208333
Remark: To run the program again you can type ENTER just after it displays the answer, and it will prompt you for new A,
B and N.

Euler's Method on the Texas Instruments TI-82 and TI-83


Calculators
This program applies Euler's method to the solution of the differential equation Y'=f(X,Y) on the X-interval [A,B]. The
program prompts for input of A, B, an initial value Y = Y(A) and the number N of steps. It displays the resulting
approximate value for Y(B). The function f is stored in the ``Y='' register as Y3. To key in the program, start from the main
screen (hit QUIT if you are somewhere else), hit PGRM and select NEW from the menu. The calculator goes into Alphalock mode and prompts you for the Name of the new program. Type in EULER, for example, and hit ENTER. Calculator
will move to a new line and display a colon : which means the beginning of an instrction. Hit ENTER after each
instruction has been keyed in. Calculator will move to a new line and display the colon.
Program

Explanation and Keying instructions

:Prompt A,B,Y,N

Asks you to input A,B,Y,N. The Prompt


command is 2 on the I/O menu. The comma
key is just below SIN.
Calculate the step-size H. -> is one
character, obtained by pressing STO.

:(B-A)/N -> H
:A -> X
:1 -> I
:Lbl P
:Y + Y3*H -> Y
:X + H -> X

:IS>(I,N)

:Goto P
:Disp Y

Initialize X and the counter I


Label this spot in the program as P.
Lbl is on the CTL menu.
The new Y value is computed from the
current X and Y values. Then X is
updated. The symbol Y3 is selected from
the Y-VARS Function... menu.
IS>( is on the CTL menu. This command
adds 1 to the counter I and then tests
if the new value is greater then N. If
it is, the following instruction is skipped
(so the program displays the current value
Y and terminates). Otherwise it cycles back
back to location P.
Goto from the CTL menu.

To finish keying the program hit QUIT (2nd MODE). To run it, enter the expression for f(X,Y) in the Y3 position (use the Y=
key). Then QUIT to get back to the main screen, PGRM and select EXEC EULER from the menu.

Check: Enter Y in Y3, so the differential equation in question is Y'= Y, with solution Y = C exp(X). Run the
program with A=0, B=1, Y=1, N=10. The result should be 2.59374246.
Exercise: Show that if f(X,Y) (the expression entered in Y3) is a function of X alone, then the number this
program gives with initial value Y=0 is the left-hand sum approximation to the integral of f from A to B with N
equal subdivisions.

Euler's Method for linear homogeneous second-order equations on


the Texas Instruments TI-82 and TI-83 Calculators
This program applies Euler's method to the solution of the differential equation Y'' + c1Y' + c0Y = 0 on the X-interval [A,B].
The program prompts for input of A, B, initial values Y = Y(A), V = Y'(A)and the number N of steps. It displays the graph of
the solution.

The program treats Y'' + c1Y' + c0Y = 0 as a set of two coupled first-order equations:
Y' = V
V' = -c1V - c0Y
The function -c1V - c0Y is stored in the Y= register as Y3.
For a readable display, you must first set the window size with Xmin = A, Xmax = B, and Ymin and Ymax
appropriate for your problem.
To key in the program, start from the main screen (hit QUIT if you are somewhere else), hit PGRM and select
NEW from the menu. The calculator goes into Alpha-lock mode and prompts you for the Name of the new
program. Type in EULER2, for example, and hit ENTER. Calculator will move to a new line and display a
colon : which means the beginning of an instrction. Hit ENTER after each instruction has been keyed in.
Calculator will move to a new line and display the colon.
Program
:ClrDraw
:FnOff

Explanation and Keying instructions


Clears the screen. DRAW (2nd PRGM), 1.
Turns off the function graphing. Y-VARS
(2nd VARS),5,2.

:Prompt A,B,Y,V,N

Asks you to input A,B,Y,V,N. The Prompt


command is 2 on the PRGM --> I/O menu.
The comma key is just below SIN.
Calculate the step-size H. -> is one
character, obtained by pressing STO.

:(B-A)/N -> H
:A -> X
:1 -> I
:Lbl P
:Y + V*H -> Y
:V + Y3*H -> V
:X+H->X

Initialize X and the counter I


Label this spot in the program as P.
Lbl is 9 on the CTL menu: PRGM --> CTL,9
The new Y value is computed from the
current V value. The new V value is
computed from the equation. Then X is
updated. The symbol Y3 is selected from
the Y-VARS Function... menu.

:X->K:Y->L
:Pt-On(X,Y)
:K->X:L->Y

Pt-On(X,Y) draws a point at coordinates


(X,Y). The other two instructions work
around the Pt-On's tendency to erase X and Y.
Pt-On is DRAW -> POINTS, 1.

:IS>(I,N)

IS>( is on the PRGM --> CTL menu. This command


adds 1 to the counter I and then tests
if the new value is greater then N. If
it is, the following instruction is skipped
(so the program displays the current value
Y and terminates). Otherwise it executes
the following instruction.

:Goto P
:DispGraph

Cycle back to location P. Goto is 0


on the CTL menu.
Displays the graph. PRGM --> I/O,4.

To finish keying the program hit QUIT (2nd MODE). To run it, enter the expression for -c1V - c0Y in the Y3 position (use
the Y= key). Then QUIT to get back to the main screen, PGRM and select EXEC EULER2 from the menu.

Check: Enter -4Y in Y3, so the differential equation in question is Y''+ 4Y = 0, with general solution Y = A
cos(2X) + B sin(2X). Prepare the window with Xmin = 0, Xmax = 10, and Ymin = -1.5, Ymax = 1.5 Run the
program with A=0, B=10, Y=1, V=0, N=100. The window should display a good likeness of Y = cos(2X). Run
it with A=0, B=10, Y=0, V=1, N=100. The window should display a good likeness of Y = (1/2)sin(2X).
Note: This program can also be used for more general second-order equations.

Slope fields on the Texas Instruments TI-82 and TI-83 Calculators


This program draws a 96-element (12 x 8) slope field in the rectangle [Xmin,Xmax]x[Ymin,Ymax]. The slopes
are given by the function of X and Y stored as Y1.
General: To type an upper case letter, press ALPHA key, followed by the letter. To begin entering the program,
press the PGRM key, and select NEW from the menu. The calculator will go into ALPHA mode and prompt
you to enter the name. Type in (for example) SLOPE and press ENTER. The program now displays the colon :
which must appear at the beginning of each command.
To enter the program commands (all the words in the program that start with a Capital Letter), press PRGM
key, then select one of the two menus:

CTL (Control commands)


I/O (Imput-output commands).

Select the command you need from the appropriate menu. After typing each command, press the ENTER key.
(You may also stay on the same line by typing a colon : (ALPHA .)
When navigating menus, use CLEAR to return to where you were.
This program is more elaborate than the others because it must link the computational and graphing operations
of the calculator.
COMMAND:
:FnOff

Explanation and keying instructions:


Inactivates function graphing. Y-VARS
(2nd VARS),5,2.
:ClDrw
Clears the screen. DRAW (2nd PRGM),1
:Prompt Xmin,Xmax,Ymin,
Ymax
Prompts for input of screen parameters. Prompt is
PRGM, and 2 from the I/O menu. Xmin, etc. are
on the VARS,1 menu.
:7(Xmax - Xmin)/83->H Calculates horizontal step-size. - is to the
right of 6, / is the division key, which is under
the ^ key, -> is STO.
:7(Ymax - Ymin)/55->K Calculates vertical step-size.
:1/(0.4H)^2->A
The numbers A and B are used in calculating
:1/(0.4K)^2->B
the how long the lines should be.
:Xmin+0.5H->X
Calculates position of lower left-hand slope line.
:Ymin+0.5K->Z
Use [X,T,theta] to get X.
:1->I
Initialize I: counts columns.
:Lbl P
Labels this program location. Lbl is PRGM, and 9
from the CTL menu.
:1->J
Initialize J: counts rows.
:Z->Y
Initialize Y for the current column.
:Lbl Q
Labels this program location.
:Y1->T
Program applies expression stored as Y1 to compute
the current slope. To get Y1, press Y-VARS and
select 1 twice.
:1/sqrt(A+B*T^2)->C
sqrt is the square-root (2nd x-squared, to the
left of comma). * is the times key (next to 9).
:T*C->S
These two instructions calculate the horizontal and
vertical extent of the line segment to be drawn.
:X->U
Store current X,Y values as U and V.
:Y->V
:Line(U-C,V-S,U+C,V+S) Draws a line segment through (X,Y). Line( is 2 on
the DRAW (2nd PGRM) menu. Comma is the key above 7.
:V+K->Y
Increment Y.
:IS>(J,8)
Add 1 to J and test. If less than or equal 8,
go to the next instruction (i.e. proceed up
the column). If greater, skip next instruction.
For IS>(, PGRM, and select A from the CTL menu.

:Goto Q
:U+H->X
:IS>(I,12)
:Goto P

For Goto: PGRM, 0 on the CTL menu.


Increment X (i.e. move to next column).
Test if all columns are done.

Ending: After pressing the ENTER key for the last command, press the EXIT key.
Running the program: First enter the function giving the slope: Press Y= (below the screen) then type it in on
the Y1 line as a function of the two variables X (use [X,T.theta]) and Y. (e.g. X+Y). Then QUIT (2nd MODE)
to return to home screen. Now PRGM, select SLOPE from the EXEC menu, ENTER. Enter numbers at the
question mark (?) prompts.
Check: For Y1 = -X/Y get circles centered at the origin. The circles will be round if
your screen parameters have the correct aspect ratio.
Check: For Y1 = X+Y and window [-3,3]x[-2,2], calculator screen should have the
image shown on the right.

GAUSS JORDAN ELIMINATION PROGRAM


Texas Instruments TI-82
This program inputs the dimensions M and N of a matrix, the exactness R of the calculation, and the matrix [E],
and then calculates the reduced row echelon form ("RREF") of [E]. The algorithm used is the standard Gauss
Jordan Elimination Algorithm (without pivoting), as described e.g. in O. Bretscher, "Linear Algebra with
Applications" (Prentice Hall 1997), p.21.
General: To type an upper case letter, press ALPHA key, followed by the letter. To begin entering the program,
press the PGRM key, and select NEW from the menu. The calculator will go into ALPHA mode and prompt
you to enter the name. Type in (for example) RREF and press ENTER. The program now displays a colon ":"
which must appear at the beginning of each command.
To enter the program commands (all the words in the program that start with a Capital Letter), press PRGM
key, then select one of the two menus:

CTL (Control commands)


I/O (Input-output commands).

Select the command you need from the appropriate menu. After typing each command, press the ENTER key.
(You may also stay on the same line by typing a colon ":", which is ALPHA . ).
To enter or access matrices or matrix operations, press the MATRX key, then select one of the three menus:

NAMES (to access previously defined matrices or select matrix names)


MATH (matrix operations)
EDIT (to edit or define matrices).

We will also need some logical operations within this program. You can access these by pressing the TEST (=
2nd MATH) key, and then selecting one of the menus

TEST (contains the comparison operations "=", "<", etc.)


LOGIC (for the logical operations "and", "or", etc.)

Commands:

Remarks and keying instructions:

:Prompt M,N,R

Program asks for M, N and R. "Prompt"


is 2 on the (PRGM) I/O menu.
Defines the dimensions of the matrix we
want to row reduce. "{" and "}" are the
2nd( and 2nd) keys; for "->", press
the STO key; "dim" is 3 in the (MATRX)
MATH menu.
Program asks for the matrix [E] (for
instructions how to enter [E] see below!).
Sets I to 1; I will be the current row
during row reduction.
J will be the current column.
Specifies how long we have to row
reduce. "While" is 5 on the (PRGM)
CTL menu. You find "<=" as 6 in the
(TEST) TEST menu and "and" as 1 in the

:{M,N}->dim[E]

:Prompt [E]
:1->I
:1->J
:While(I<=M and J<=N)

(TEST) LOGIC menu.


Initiates the check if we have to swap
the I-th and the K-th column.
:While(K<=M-1 and round([E](K,J),R)=0)
Checks if, up to the specified exactness
R, the current matrix element is zero.
You find "round" as 1 in the (MATH) NUM
menu, and the "=" that we need here as 1
in the (TEST) TEST menu.
:K+1->K
If the matrix element is zero, go down
one step in the current column.
:End
End of last "While" loop; "End" is 7 in
menu (PRGM) CTL.
:If(K=M and round([E](K,J),R)=0)
"If" is 1 in the (PRGM) CTL menu;
:Goto P
"Goto" is 0 in the (PRGM) CTL menu.
The last two lines check if we have to
go to the next column to be able to proceed.
:rowSwap([E],I,K)->[E]
Swaps the current row with the first row
that does not have a leading zero in the
current column; "rowSwap" is 8 in the
(MATRX) MATH menu.
:*row(1/[E](I,J),[E],I)->[E]
Sets the first entry in the current row =1;
"*row" is 0 in the (MATRX) MATH menu.
:For(H,1,I-1,1)
Initiates the first loop: Row reduction
on the rows above the current one. "For"
is 4 in the (PRGM) CTL menu.
:*row+(-[E](H,J),[E],I,H)->[E] Adds the proper multiple of the I-th row
to the H-th row. "*row+" is A in the
(MATRX) MATH menu. Careful: "-" is
the (-) key here, NOT the - key!!
:0->[E](H,J)
This matrix element should be zero from
the last step; however, due to rounding
errors, it often is not. This step
guarantees it, by "brute force".
:End
Ends the first "For" loop.
:For(H,I+1,M,1)
Initiates the second loop: Row reduction
on the rows below the current one.
:*row+(-[E](H,J),[E],I,H)->[E] The next steps correspond to the steps
:0->[E](H,J)
in the first loop.
:End
Ends the second "For" loop.
:I+1->I
Go to the next row.
:Lbl P
This spot in the program is labelled P.
"Lbl" is 9 in the (PRGM) CTL menu.
:J+1->J
Go to the next column.
:End
Ends the first "While" loop at the
beginning of the program.
:round([E],R)->[E]
Rounds the matrix to the exactness we
specified.
:Disp "RREF",[E]
Output of the row reduced echelon form
of our matrix. "Disp" is 3 in the (PRGM)
I/O menu, " is ALPHA +
:I->K

Ending: After pressing the ENTER key for the last command, press the QUIT (2nd MODE) key.
Running the program: To run the program, press PRGM, select EXEC, and then RREF, or the name that you
choose for this program (it is selected automatically if it is the only program you have.) The screen will display
a prompt "prgmRREF". Press ENTER. Enter the M, N, R you want at the question mark (?) prompts. Here, M is
the number of rows and N the number of columns that the matrix you want to row reduce has; R specifies the
number of decimal places to which your result should be correct, and can be any integer between 1 and 9 (one
usually will choose the maximum, R=9; see remarks below!).

Next, the program will ask you for the matrix [E] that you want to row reduce. You can enter [E] either directly,
by using the "[" and "]" keys (= 2nd x and 2nd -, respectively) as follows: the input
[[1,2,3][4,5,6]]

will enter the matrix


[ 1
[ 4

2
5

3 ]
6 ]

Alternatively, you may enter the matrix under some other name in the (MATRX) EDIT menu, say as matrix
[A], and then just select (MATRX) NAMES 1 at the "[E]=?" prompt. The latter method is recommended, since
otherwise the input-matrix will be "lost" after the program is executed.
In any case, you have to make sure that the dimensions of the matrix you enter coincide with the numbers
M of rows and N of columns that you specified at the start of the program! Otherwise, the program will be
interrupted and an error message displayed if your matrix is too small, or you will not obtain the reduced row
echelon form of the matrix if it is too big.
Pressing ENTER after entering [E] starts the program, which after a little while will return the reduced row
echelon form of the matrix, but only display the first columns and rows (of big matrices). If you want to see the
other rows and columns, just select (MATRX) NAMES 5, and use the cursor keys to move within the matrix.
Remarks on rounding errors: Unfortunately, the Gauss Jordan Elimination Algorithm is not stable with respect
to rounding errors; that means that accumulated rounding errors do not only change the numbers of the output a
little, but they can in fact dramatically change the outcome: Instead of e.g. infinitely many solutions (with "free
parameters"), you might seemingly obtain a "unique solution"! The boldfaced parts of the program above are
included to minimize the effect of these rounding errors, but they cannot completely eliminate them. If you are
in doubt that you got the correct type of solution, run the program again, with a smaller value of R. However,
for most matrices the maximum value of R=9 will give you the correct outcome.
If you always want to run the program with R=9, delele ",R" from the first line, and add the line ":9->R" as a
new second line.
If you want to run the program without these rounding procedures, just delete all boldfaced parts. If you want
to have both options, copy the program under another name (like "XREF" or so; please see the Manual
Guidebook of your TI-82 on how to copy a program), and just delete all boldfaced parts in the second one.
Check: The 3x6 matrix
[A] =

[[ 3
[ 7
[-4

6
14
-8

9
21
-12

5
9
5

25
53
-10

53 ]
105 ]
11 ]]

will give you (with M=3, N=6, R=9) the result


[E] =

[[ 1
[ 0
[ 0

2
0
0

3
0
0

0
1
0

5
2
0

6 ]
7 ]
0 ]]

which is the exact reduced row echelon form of [A]. However, if you run the modified program without the
boldfaced parts, you will get the incorrect result
[E] =

[[ 1
[ 0
[ 0

2
0
0

3
0
0

0
1
0

0
0
1

-37.75 ]
-10.5 ]
8.75 ]]

Note that if this matrix was the augmented matrix of a system of 3 linear equations in 5 variables, the the correct
solution will have 3 free parameters, the incorrect one only 2!

Vous aimerez peut-être aussi