How do I iterate through a list in a TI-83 calculator program

James T picture James T · Nov 16, 2010 · Viewed 13.2k times · Source

I created a set of programs to calculate the area under a graph using various methods of approximation (midpoint, trapezoidal, simpson) for my Calculus class.

Here is an example of one of my programs (midpoint):

Prompt A,B,N
(A-B)/N->D
Input "Y1=", Y1
0->X
0->E
For(X,A+D/2,b-D/2,D)
Y1(x)+E->E
End
Disp E*D

Instead of applying these approximation rules to a function (Y1), I would like to apply them to a list of data (L1). How do I iterate through a list? I would need to be able to get the last index in the list in order for a "For Loop" to be any good. I can't do anything like L1.length like I would do in Java.

Answer

Jeff Mercado picture Jeff Mercado · Nov 16, 2010

You can obtain the length of the list using dim(). That can be found in 2nd->LIST->OPS->dim(. Just make sure that you use a list variable otherwise dim() will complain about the type. You could then index into the list with a subscript.

e.g.,

{1, 2, 3, 4} -> L1
For (X, 1, dim(L1), 1)
Disp L1(X)
End