I have this piece of code: http://pastebin.com/UNCeB2Tx

Code:
#
:For(G,0,Z-2,1)
#
:(∟L3(G+2)-∟L3(G+1))/(∟L1(G+3)-∟L1(G+1))→∟L4(1+dim(∟L4
#
:End


I want to cycle through lists depending on the value of the dim(∟L1)→K, that value will tell me how many lists I should have created. So ideally I want something like this


Code:
#
:For(G,1,K,1)
#
:(∟LG(G+2)-∟LG(G+1))/(∟LG(G+3)-∟LG(G+1))→∟L(G+3)(1+dim(∟L4
#
:End


I don't know how to do this though, or if it's even possible.
I'm confused, do you want to cycle through the elements in a list, or through a list of lists? Also, that last piece of code does not have correct syntax. You can't do "→∟L(G+3)(1+dim(∟L4 ".
souvik1997 wrote:
I'm confused, do you want to cycle through the elements in a list, or through a list of lists? Also, that last piece of code does not have correct syntax. You can't do "→∟L(G+3)(1+dim(∟L4 ".


Yes I know the syntax isn't correct, it's only a matter of understanding what I want. Regarding the 1st question, I want to cycle through L1, L2, L3, etc... until the last one.
Well, that is not possible in BASIC, since there is no way of retrieving values from lists whose names aren't predetermined. However, if there is a limit on the number of lists you can have, it is possible with a massive amount of If:Then statements.
souvik1997 wrote:
Well, that is not possible in BASIC, since there is no way of retrieving values from lists whose names aren't predetermined. However, if there is a limit on the number of lists you can have, it is possible with a massive amount of If:Then statements.


yeah I have a limit, like 6. That's what I thought, only using IF:then.

EDIT: Would it be possible to do this using matrices?
2n2u wrote:
souvik1997 wrote:
Well, that is not possible in BASIC, since there is no way of retrieving values from lists whose names aren't predetermined. However, if there is a limit on the number of lists you can have, it is possible with a massive amount of If:Then statements.


yeah I have a limit, like 6. That's what I thought, only using IF:then.

EDIT: Would it be possible to do this using matrices?


Yes, it would be possible to do this with matrices.
Maybe too hard for me though Razz
Actually, it is quite simple. The dimensions of a matrix is outputted as {Height,Width}, so you can essentially create multiple lists which fill a row in the matrix, and have other lists occupy different rows.
No, you can do it! If you have a 6xN matrix, you could easily just select one column (or row) and the element within that column (or row). The one limitation would be that all six lists would have to be the same length.
Ohh I didn't know that was possible to "insert" lists on a matrix Surprised

Can you give me a example code?

EDIT: Kerm they aren't Sad, unless I fill the rest with zeros
This code will take all the elements from L1 and store them to the Xth row of matrix [A]

Code:

dim(L1->A
dim([A]
{Ans(1),A->dim([A]
For(B,1,A
L1(A->[A](X,A
End
Guess I solved the issue with lists, well at least not using an IF:Then Razz


Code:
:Lbl 0
:Menu("Interpolacao","Comecar",1,"Sair",99)
:Lbl 1
:dim(∟L1)→K
:K→A
:While A≥K
:For(G,1,K-1,1)
:(∟L2(G+1)-∟L2(G))/(∟L1(G+1)-∟L1(G))→∟L3(1+dim(∟L3
:K-1→A
:End
:For(G,1,K-2,1)
:(∟L3(G+1)-∟L3(G))/(∟L1(G+2)-∟L1(G))→∟L4(1+dim(∟L4
:K-2→A
:End
:For(G,1,K-3,1)
:(∟L4(G+1)-∟L4(G))/(∟L1(G+3)-∟L1(G))→∟L5(1+dim(∟L5
:K-3→A
:End
:For(G,1,K-4,1)
:(∟L5(G+1)-∟L5(G))/(∟L1(G+4)-∟L1(G))→∟L6(1+dim(∟L6
:K-4→A
:End
:End
:
Just some optimization tricks: you can omit closing parenthesis at the end of lines, and you can omit the ending ,1 on For() loops. Also, you just need L6, not ∟L6. I don't like the idea of you changing K inside the For() loops themselves; that seems like it wouldn't work to me.
The parameters of For() loops are constant in TI Basic, even if you change their values, so if I did 10->K:For(X,1,K):K-X->K:End, the loop would still repeat 10 times.
The final code working:


Code:
:Lbl 0
:Menu("Interpolacao","Comecar",1,"Sair",99)
:
:Lbl 1
:dim(∟L1)→K
:K→A
:For(G,1,K-1,1)
:(∟L2(G+1)-∟L2(G))/(∟L1(G+1)-∟L1(G))→∟L3(1+dim(∟L3
:K-1→A
:End
:If A≥0
:Then
:For(G,1,K-2,1)
:(∟L3(G+1)-∟L3(G))/(∟L1(G+2)-∟L1(G))→∟L4(1+dim(∟L4
:K-2→A
:End
:Else
:Stop
:End
:If A≥0
:Then
:For(G,1,K-3,1)
:(∟L4(G+1)-∟L4(G))/(∟L1(G+3)-∟L1(G))→∟L5(1+dim(∟L5
:K-3→A
:End
:Else
:Stop
:End
:If A≥0
:Then
:For(G,1,K-4,1)
:(∟L5(G+1)-∟L5(G))/(∟L1(G+4)-∟L1(G))→∟L6(1+dim(∟L6
:K-4→A
:End
:Else
:Stop
:End


Well that ∟L6 is because my list is named "L""6"(custom list) and not with the button "L6", I don't know if you're understanding me Razz
As you find yourself adding another code block for each iteration, you should begin to wonder what patterns you're missing, then proceed to make your code a little more flexible.

For any number of data points:

Code:
∟L2
While 1≠dim(Ans
Pause ΔList(Ans)/seq(∟L1(G+dim(∟L1)-dim(Ans)+1)-∟L1(G),G,1,dim(Ans)-1 //►Frac if preferred
End
KermMartian wrote:
Just some optimization tricks: you can omit closing parenthesis at the end of lines, and you can omit the ending ,1 on For() loops. Also, you just need L6, not ∟L6. I don't like the idea of you changing K inside the For() loops themselves; that seems like it wouldn't work to me.


If you're using IS>( or DS<( commands in the For loops, you'll want to keep the ending parenthesis though.
Weregoose wrote:
As you find yourself adding another code block for each iteration, you should begin to wonder what patterns you're missing, then proceed to make your code a little more flexible.

For any number of data points:

Code:
∟L2
While 1≠dim(Ans
Pause ΔList(Ans)/seq(∟L1(G+dim(∟L1)-dim(Ans)+1)-∟L1(G),G,1,dim(Ans)-1 //►Frac if preferred
End


I am aware of the patterns, I don't know how to "generalize" them at TI Basic though.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement