简体   繁体   English

如何遍历TI-83计算器程序中的列表

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

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). 我不想将这些近似规则应用于函数(Y1),而是将它们应用于数据列表(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. 我需要能够获得列表中的最后一个索引,以便“For循环”有任何好处。 I can't do anything like L1.length like I would do in Java. 我不能像在Java中那样做L1.length这样的事情。

You can obtain the length of the list using dim() . 您可以使用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. 这可以在2nd->LIST->OPS->dim( 。确保你使用一个列表变量,否则dim()会抱怨这个类型。然后你可以用下标索引到列表中。

eg, 例如,

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

The for loop is the simplest way to iterate over a list in TI-Basic, as it is in many languages. for循环是在TI-Basic中迭代列表的最简单方法,因为它在许多语言中。 Jeff Mercado already covered that, so I'll mention a few techniques that are powerful tools in specialized situation. Jeff Mercado已经介绍了这一点,所以我将提到一些在特殊情况下是强大工具的技术。

Mapping over lists 映射列表

TI-Basic supports simple mapping operation over lists that have the same effect as a map function in any other language. TI-Basic支持对列表进行简单的映射操作,这些列表与任何其他语言的map函数具有相同的效果。 TI-Basic support for this extends to most basic arithmetic function, and selection of other functions. TI-Basic对此的支持扩展到大多数基本算术功能和其他功能的选择。

The syntax could not be simpler. 语法不可能更简单。 If you want to add some number X to every element in some list L1 you type X+L1→L1 . 如果要为某些列表L1每个元素添加一些数字X ,请键入X+L1→L1

seq( SEQ(

Most for loops over a lists in TI-Basic can be replaced by cleverly constructed seq( command that will outperform the for loop in time and memory. The exceptions to this rule are loops that contain I/O or storing variables. TI-Basic中列表上的大多数for循环可以由巧妙构造的seq(在时间和内存中优于for循环的命令)替换。此规则的例外是包含I / O或存储变量的循环。

The syntax for this command can be quite confusing, so I recommend reading over this documentation before using it. 此命令的语法可能非常混乱,因此我建议您在使用之前阅读本文档 In case that link dies, here's the most relevant information. 如果链接死亡,这是最相关的信息。

Command Summary 命令摘要

Creates a list by evaluating a formula with one variable taking on a range of values, optionally skipping by a specified step. 通过评估公式来创建列表,其中一个变量采用一系列值,可选择跳过指定的步骤。

Command Syntax 命令语法

seq(formula, variable, start-value, end-value [, step]) seq(公式,变量,起始值,结束值[,步骤])

Menu Location 菜单位置

While editing a program, press: 编辑程序时,按:

2nd LIST to enter the LIST menu RIGHT to enter the OPS submenu 5 to choose seq(, or use arrows. 第二个LIST进入LIST菜单RIGHT进入OPS子菜单5选择seq(或使用箭头。

Calculator Compatibility 计算器兼容性

TI-83/84/+/SE TI-83/84 / + / SE

Token Size 令牌大小

1 byte 1个字节

The documentation should do a good job explaining the syntax for seq( , so I'll just provide a sample use case. 文档应该很好地解释seq(的语法seq(所以我只提供一个示例用例。

If you want the square of every number between 1 and 100 you could do this 如果你想要1到100之间的每个数字的平方,你可以这样做

For Loop 对于循环

DelVar L1100→dim(L1
for(A,1,100
A²→L1(A
End

or, this 或这个

seq 以次

seq(A²,A,1,100→L1

The drawback of seq( is that you can't do any I/O or store any variables inside the expression. seq(的缺点seq(就是你不能做任何I / O或在表达式中存储任何变量。

Predefined list iteration function 预定义列表迭代函数

Go to the LIST menu and check out all the operations under OPS and MATH . 转到LIST菜单,查看OPSMATH下的所有操作。 These predefined function are always going to be faster than a for loops or even a seq( expression designed to do the same thing. 这些预定义的函数总是比for循环或甚至seq(设计用于执行相同操作的表达式)更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM