Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: ShortsOnFire79 on March 26, 2012, 12:07:44 am

Title: 83+ to nspire nx rewrite fail
Post by: ShortsOnFire79 on March 26, 2012, 12:07:44 am
Hey,

So I'm in the process of rewriting some of my more useful programs from my TI-83 plus onto my TI-nspire cx cas.
I've written myself a program that will ask for 4 variables, and depending on which variable is set as the one to solve for, it will perform a certain equation.  By making my variables equal each other (ex: p=p) then that tells my code to solve for that variable.

Heres the code thats on my 83, it works just fine.
Spoiler For Spoiler:
:Disp "pv=(0.08206)nt"
:Input "enter p:atm=",p
:Input "enter v:l=",v
:Input "enter n=",n
:Input "enter t:k=",t
:If p=p:then
:Disp (0.08206nt)/v
:If v=v:then
:Disp (0.08206nt)/p
:If n=n:then
:Disp (pv)/(0.08206t0
:If t=t:then
:Disp (pv)/(n0.08206)

I'm basically writing the same exact code, except without the 'input' command, since it isn't in the catalog function on the cas, but that is what the 'define' command is for.  Here is the code I have on my cas, it gives me syntax errors when I try to 'check it', and when I run it, it says I have too many arguments.  I also tried writing the code with instead of 'func', using 'prgm', which didn't change anything.  I attempted to have the code recognize the variable '?' which would symbolize which variable to solve for, but it would not recognize it either.
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
func
If p=p, then disp 0.08206nt/v
If v=v, then disp 0.08206nt/p
If n=n, then disp pv/0.08206t
If t=t, then disp pv/0.08206n
endfunc

I know that my knowledge of coding is quite diminutive, which is why I'm here, to learn.  So feel free to poke and make fun of my codes and how sloppy it is and whatnot.  I'm sure there are numerous ways to shorten my code, but I only know the very basics at the moment.  Any bits of knowledge you could offer me would be greatly received, I am here to learn!

Thank you for your time. :)
Title: Re: 83+ to nspire nx rewrite fail
Post by: ElementCoder on March 26, 2012, 05:14:46 am
First of all, input can be gained from the Request (for numerical values) and RequestStr (for strings).
The major problem that's causing all the trouble is that you don't close the if statements.
On the TI-Nspire you have to do this:
Spoiler For Spoiler:
If <condition> then
<actions to perform>
EndIf

Also, all the variables are ALWAYS equal to themselves. So v=v no matter what. So you will always get four results.
Here's how I would've done it:
Spoiler For Spoiler:
Your code, but with closed if statments. Will always return four answers
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p=p Then
 Disp ((0.08206*n*t)/(v))
EndIf
If v=v Then
 Disp ((0.08206*n*t)/(p))
EndIf
If n=n Then
 Disp ((p*v)/(0.08206))*t
EndIf
If t=t Then
 Disp ((p*v)/(0.08206))*n
EndIf
EndPrgm

Another option: make the variable to solve different from the others. The gaslaw for example would never have negative numbers or zero, so consider this (Stop terminates the program):
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p<0 Then
 Disp ((0.08206*n*t)/(v))
 Stop
EndIf
If v<0 Then
 Disp ((0.08206*n*t)/(p))
 Stop
EndIf
If n<0 Then
 Disp ((p*v)/(0.08206))*t
 Stop
EndIf
If t<0 Then
 Disp ((p*v)/(0.08206))*n
 Stop
EndIf
EndPrgm

Personally, I would do this:
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p=0 Then
 Disp "p=",((0.08206*n*t)/(v))
ElseIf v=0 Then
 Disp "v=",((0.08206*n*t)/(p))
ElseIf n=0 Then
 Disp "n=",((p*v)/(0.08206))*t
ElseIf t=0 Then
 Disp "t=",((p*v)/(0.08206))*n
Else
 Disp "Error: nothing to solve, check syntax."
EndIf
EndPrgm

Finally, not really needed, if you want nice input:
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
Request "Enter p:atm=",p
Request "Enter v:l=:",p
Request "Enter n=",n
Request "Enter t:k=:

If p=0 Then
 Disp "p=",((0.08206*n*t)/(v))
ElseIf v=0 Then
 Disp "v=",((0.08206*n*t)/(p))
ElseIf n=0 Then
 Disp "n=",((p*v)/(0.08206))*t
ElseIf t=0 Then
 Disp "t=",((p*v)/(0.08206))*n
Else
 Disp "Error: nothing to solve, check syntax."
EndIf
EndPrgm

I hope this was helpful. And if you want to learn, check my tutorial (link coming soon in my sig)
Title: Re: 83+ to nspire nx rewrite fail
Post by: Jonius7 on March 26, 2012, 06:00:17 am
Yeah TI-nspire Basic Code is different and cannot be written as concisely as Code on the TI-83+.
I'm actually surprised that the TI-83+ Code actually works. I didn't know that EndIfs were not needed.

And Hi ElementCoder! I'm Jonius7, also known as jhgenius01 (you would have visited my website at jhgenius01.webs.com)
Haven't really seen you around that much, but good to see you!
Wonder if superbany has an account here.
Title: Re: 83+ to nspire nx rewrite fail
Post by: ShortsOnFire79 on March 26, 2012, 08:00:22 pm
First of all, input can be gained from the Request (for numerical values) and RequestStr (for strings).
The major problem that's causing all the trouble is that you don't close the if statements.
On the TI-Nspire you have to do this:
Spoiler For Spoiler:
If <condition> then
<actions to perform>
EndIf

Personally, I would do this:
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p=0 Then
 Disp "p=",((0.08206*n*t)/(v))
ElseIf v=0 Then
 Disp "v=",((0.08206*n*t)/(p))
ElseIf n=0 Then
 Disp "n=",((p*v)/(0.08206))*t
ElseIf t=0 Then
 Disp "t=",((p*v)/(0.08206))*n
Else
 Disp "Error: nothing to solve, check syntax."
EndIf
EndPrgm
I hope this was helpful. And if you want to learn, check my tutorial (link coming soon in my sig)

Thanks for walking me through the if-thens, that'll be really helpful on my next project.

I ended up using your code that you personally would use.  Works great!  One thing I don't understand though, is why at the second to last line, you have an EndIf?  Is that to tell the code to end, if the previous error was witnessed?

Also, what will your tutorials be covering?  If they're as descriptive as the post you left me, I will surely check them out! Thank you!
Title: Re: 83+ to nspire nx rewrite fail
Post by: chattahippie on March 26, 2012, 08:12:36 pm
If <condition> then
<actions to perform>
EndIf

From this code example, the EndIf is a command that Ends the If statement
Title: Re: 83+ to nspire nx rewrite fail
Post by: Jonius7 on March 27, 2012, 07:53:05 am
Is EndIf or End not required in TI-BASIC (83/84)?
I know that End is required in Casio Basic and EndIf in TI-nspire Basic
End (for function in Lua) too.
Title: Re: 83+ to nspire nx rewrite fail
Post by: ElementCoder on March 27, 2012, 10:15:01 am
Also, what will your tutorials be covering?  If they're as descriptive as the post you left me, I will surely check them out! Thank you!

I plan to make them as descriptive as my post, with useful examples and quizes to test knowledge :P

@Jonius7: yeah, lets say I took a forced break. School and such, and with exams upcoming I don't know how much time I can spend around here and coding stuff. I'm doing a little too much atm so I'm a bit *.* (learning java, learning lua (does anyone know a good tutorial?), playing a lot of guitar :P)
Title: Re: 83+ to nspire nx rewrite fail
Post by: Jonius7 on March 27, 2012, 08:11:25 pm
Yeah, true, posting posts and stuff is definitely time consuming. But I've been here a while, so I guess it's not too bad. Just that I need some good projects!
Title: Re: 83+ to nspire nx rewrite fail
Post by: chattahippie on March 27, 2012, 09:24:06 pm
Is EndIf or End not required in TI-BASIC (83/84)?
I know that End is required in Casio Basic and EndIf in TI-nspire Basic
End (for function in Lua) too.


84+ only uses End, there is no such thing as EndIf (unless you use Axe :P )
Title: Re: 83+ to nspire nx rewrite fail
Post by: cyanophycean314 on March 27, 2012, 10:27:59 pm
learning lua (does anyone know a good tutorial?)

For Lua, first learn Lua itself, http://www.lua.org/pil/ (http://www.lua.org/pil/)
Then, head to Inspired Lua for Nspire API, www.inspired-lua.org (http://www.inspired-lua.org)

Good luck!