Search code examples
listti-basic

How do you append values to list then iterate through lists?


I am trying to write a basic program for my TI-84 that finds the area of polygons on a 2d plane. For reference, I have written this in python many times, here is what it does:

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

this just does the very basic algorithm also shown here in regular mathematics: http://www.mathopenref.com/coordpolygonarea.html

now when I try to write the same thing in TI-Basic (using the TI Connect application and sending to calculator), it returns a syntax error on the first reference to one of the lists; "Check all arguments entered". The line is surrounded in asterisks. comments are not in the actual code

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)

when changing the code on the calculator by changing the L1 to the list1 character and L2 to the list2 character, all it did was return the value 12.5*number of vertices-2. My questions are:

  1. How can I represent lists in the code on the computer? When I write L1 in the code, it's not actually the built-in list variable I think, and that's what's causing the syntax error. I think.
  2. Do I need to reset list variables? The very first time I tested this, the 12.5*vertices-2 worked, so did it just permanently set the list variables to that, and now when it adds things to list in later runs of the program, it never reaches those indices?
  3. Is the code flawed in any way that causes it to not work at all? I'm entirely new to TI-Basic.

Solution

  • got it, i'm silly.

    1st, used the list variables given on the syntax reference in ti-connect

    2nd, the algorithm in the second for loop was wrong.