This is my second program I wrote for TI-89. Can someone who thinks that knows TI-BASIC well, takes a quick look.

Please make some comment. Tell me what is good and what should I change to make this faster, more efficient or simply not so complicated.

Thanks


Program takes input from user, and calculates some equations stored in global variables, that are dependent on x and y coordinates.

User can than choose to input some points (up to 6 for each equation) and get results in those points.


Code:

()
Prgm
ClrIO
Local a,b,h,e,v,m,n,amn,dd2,dd3,dd4,dd5,dd6,dd7,dd8,z,x_1,x_2,x_3,x_4,x_5,x_6,y_1,y_2,y_3,y_4,y_5,y_6,st,i,old,j,q,key,txt

DelVar ch

// Home screen with custom menu
Lbl home
ClrIO
Output 20,22,"Program za izracun"
Output 28,20,"prostolezecih plosc"
Output 62,2,"v.1.3.1"

Toolbar
Title "Program"
Item "Pobrisi podatke",clr
Item "Izhod",end

Title "Plosca"
Item "Vnos podatkov",vnos
Item "Izracunaj",racun
Item "Tocke",koor
EndTbar
Goto home

// User input
Lbl vnos
ClrIO
Input "Stranica a=? [m]",a
Input "Stranica b=? [m]",b
Input "Debelina h=? [m]",h
Input "Elast. modul e=? [kN/m2]",e
Input "Poissonov kolicnik v=?",v
Prompt m,n,amn
1ch
Goto home

Lbl racun
ClrIO
// Chek if input was made, if not display warning and return to home
If isVar(ch)true Then
Output 33,0,"Pred racunom vnesi podatke."
Pause
Goto home
EndIf

// Calculations
setMode({"3","1","14","1"})old
DelVar x,y

e*h^3/(12*(1-v^2))k
Pause "k="&string(k)

amn/(k*Œ^4*(m/a^2+n/b^2)^2)wmn
Pause "w"&string(m)&string(n)&"="&string(wmn)

wmn*sin(Œ*x/a)*sin(Œ*y/b)w
Pause "w(x,y)="&string(w)
­k*(¼(w,x,2)+v*¼(w,y,2))mxx
Pause "mxx(x,y)="&string(mxx)

­k*(¼(w,y,2)+v*¼(w,x,2))myy
Pause "myy(x,y)="&string(myy)

­k*(1-v)*¼(¼(w,x),y)mxy
Pause "mxy(x,y)="&string(mxy)

­k*(¼(w,x,3)+¼(¼(w,x),y,2))qx
Pause "qx(x,y)="&string(qx)

­k*(¼(w,y,3)+¼(¼(w,y),x,2))qy
Pause "qy(x,y)="&string(qy)

­k*(¼(w,x,3)+(2-v)*¼(¼(w,x),y,2))qxp
Pause "qxp(x,y)="&string(qxp)

­k*(¼(w,y,3)+(2-v)*¼(¼(w,y),x,2))qyp
Pause "qyp(x,y)="&string(qyp)

setMode(old)
Goto home

// Calculate values in points (x,y)
Lbl koor
ClrIO
setMode({"3","1","14","1"})old

// Choose number of points for each equation
Dialog
Text "Izberi zeljeno stevilo tock za:"
DropDown "w?",{"0","1","2","3","4","5","6"},dd1
DropDown "Mxx?",{"0","1","2","3","4","5","6"},dd2
DropDown "Myy?",{"0","1","2","3","4","5","6"},dd3
DropDown "Mxy?",{"0","1","2","3","4","5","6"},dd4
DropDown "qx?",{"0","1","2","3","4","5","6"},dd5
DropDown "qy?",{"0","1","2","3","4","5","6"},dd6
DropDown "qxp?",{"0","1","2","3","4","5","6"},dd7
DropDown "qyp?",{"0","1","2","3","4","5","6"},dd8
EndDlog

{"w","Mxx","Myy","Mxy","qx","qy","qxp","qyp"}txt


For i,1,8              //For loop from 1 to 8, one for each equation. Input all coordinates for one equation.
 #("dd"&string(i))z
 If z1 Then           // If user chooses 0 points, skip to the next equation
  For p,1,z-1          // For loop, for number of points (1-6), displays that many dialogs for coordinate input (x1,y1) (x2,y2)...
   Dialog
    Title "Vnesi koordinate tock"
    Text string(txt[i])&"    Tocka  "&string(p)&"/"&string(z-1)
    Request "x"&string(p),#("x_"&string(p))
    Request "y"&string(p),#("y_"&string(p))
   EndDlog
 EndFor
 ClrIO
 For j,1,z-1               // Another For loop, for number of points (1-6). Display all resualts for one equation.
  expr("x_"&string(j))x  // Converts x coordinates from previous for loop to expression
  expr(x)x
  expr("y_"&string(j))y  // Converts y coordinates from previous for loop to expression
  expr(y)y
  If i=1 and j<z Then      // Put coordinates in equations stored in w,mxx,myy...and display values in points
    Output 2+(j-1)*11,2,"w("&string(x)&","&string(y)&")="&string(w)
   ElseIf i=2 and j<z Then
    Output 2+(j-1)*11,2,"Mxx("&string(x)&","&string(y)&")="&string(mxx)
   ElseIf i=3 and j<z Then
    Output 2+(j-1)*11,2,"Myy("&string(x)&","&string(y)&")="&string(myy)
   ElseIf i=4 and j<z Then
    Output 2+(j-1)*11,2,"Mxy("&string(x)&","&string(y)&")="&string(mxy)
   ElseIf i=5 and j<z Then
    Output 2+(j-1)*11,2,"qx("&string(x)&","&string(y)&")="&string(qx)
   ElseIf i=6 and j<z Then
    Output 2+(j-1)*11,2,"qy("&string(x)&","&string(y)&")="&string(qy)
   ElseIf i=7 and j<z Then
    Output 2+(j-1)*11,2,"qxp("&string(x)&","&string(y)&")="&string(qxp)
   ElseIf i=8 and j<z Then
    Output 2+(j-1)*11,2,"qyp("&string(x)&","&string(y)&")="&string(qyp)
  EndIf
 EndFor
  Pause
 EndIf
EndFor
setMode(old)
Goto home

// Clear all results
Lbl clr
DelVar a,b,h,e,v,m,n,amn,dd2,dd3,dd4,dd5,dd6,dd7,dd8,z,x_1,x_2,x_3,x_4,x_5,x_6,y_1,y_2,y_3,y_4,y_5,y_6,st,i,old,j,mxx,myy,mxy,qx,qy,qxp,qyp,k,wmn,w,ch,txt
Goto home

Lbl end
ClrIO
DelVar x,y,ch
Pause
DispHome
EndPrgm
The only thing that (immediately) stands out to me is your use of Lbl and Goto. The 89 has much better ways to jump around a program than them: their use is generally discouraged for almost everything (except 83+ Basic where they are sometimes the only option). For instance, you can define a subroutine like so:


Code:
:Define subprgm()=Prgm
: © subprogram code
:EndPrgm


And then you can call it using subprgm() from inside your program. You can also define functions and have them return values. For more information on how to make subprograms see this page in particular.

That would probably make it easier to read, if not necessarily more efficient.

Unfortunately the 68k section of TI-Basic Developer is less fleshed out compared to the 83+ one, but it's still a useful resource (if you weren't already aware of it).
Thanks for replay.

I thought of subroutines and in the next program i will probably use them.
The "problem" with subroutines is that no local variable form lets call it main program, can't be recognized in a subroutine and vice versa. Solution is probably to work in maybe just temporary separate folder, with everything stored in global variables that are deleted on exit.

Or is there some better way?
timijan wrote:
Thanks for replay.

I thought of subroutines and in the next program i will probably use them.
The "problem" with subroutines is that no local variable form lets call it main program, can't be recognized in a subroutine and vice versa. Solution is probably to work in maybe just temporary separate folder, with everything stored in global variables that are deleted on exit.

Or is there some better way?


You can pass arguments to the subroutine just like you can pass arguments to a "main" program or function:


Code:
:Define subprgm(x,y,z)=Prgm
: © subprogram code
:EndPrgm


And as I said, you can use Return to return a value to whatever called the function.

But if you need to return multiple variables, I think you either have to return a list or do what you described.
Most programming languages let you return a list or structure from a subroutine in order to do what you're describing, although the ones that I'm thinking of that give the programmer the most flexibility, namely PHP and Python, allow mixed-type lists. TI-68k-BASIC, of course, does not.

Edit: I've been informed that my 68k BASIC is horribly rusty, and that you can in fact have mixed-type lists. Huzzah!
KermMartian wrote:
Most programming languages let you return a list or structure from a subroutine in order to do what you're describing, although the ones that I'm thinking of that give the programmer the most flexibility, namely PHP and Python, allow mixed-type lists. TI-68k-BASIC, of course, does not.


Actually, 68k Basic does have multi-typed lists- {1, 2, "abc"} is a perfectly valid list.

Well, actually, there is a "data" object that you can store whatever you want in, either in one or two dimensions. There are matrix and list objects as well, which are about the same as their z80 equivalents.

And, Kerm just edited his post as I was writing this one. Razz
So using subprograms and returning values is good programming practice.

I'll probably rewrite my program for practice and and paste the code here so somebody can comment it.

Thanks
  
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