我正在尝试为TI-84编写一个基本程序,该程序可以找到2d平面上的多边形区域。作为参考,我已经用python编写了很多次,这是它的作用:
x_list,y_list,verts,tot_1,tot_2=[],[],int(input("How many vertices are on the polygon: ")),0,0 //sets vars to defaults and gets num of vertices
for i in range(verts): //gets X and Y values of each point for num. of vertices
x_list.append(float(input("X value of point %s: " % str(i+1)))) //appends x value given to x list
y_list.append(float(input("Y value of point %s: " % str(i+1)))) //appends y value given to y list
for ind in range(verts-1):
tot_1 += (x_list[ind]*y_list[ind+1])-(y_list[ind]*x_list[ind+1])
print(str(abs((tot_1)/2))) //prints area: abs value of total over two
这只是常规数学中也显示的非常基本的算法:http : //www.mathopenref.com/coordpolygonarea.html
现在,当我尝试使用TI-Basic(使用TI Connect应用程序并将其发送到计算器)编写相同的内容时,它在对其中一个列表的第一次引用时返回语法错误。“检查所有输入的参数”。该行被星号包围。注释不在实际代码中
ClrHome //clears screen
Prompt V //gets number of vertices
0→T //sets total to 0
Disp V //displays vertices, was used for testing
For(N,1,V,1) //runs code for number of vertices
Input "x val: ",X //gets latest x val
Input "y val: ",Y //gets latest y val
**X→L1(1+dim(L1))** //appends x to listand
Y→L2(1+dim(L2)) //y to list
End //end for
For(I,1,P,1)
T+((L1(I)*L2(I+1))-(L2(I)*L1(I+1))→T //adds up total
End
Disp abs(T/2)
通过将L1更改为list1字符并将L2更改为list2字符来更改计算器上的代码时,所做的只是返回值12.5 * vertices-2。我的问题是:
知道了,我很傻。
1,使用了ti-connect语法参考中给出的列表变量
第二,第二个for循环中的算法错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句