Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: dduce on May 11, 2011, 07:39:17 pm

Title: TI - Npsire, CAS; many programming questions
Post by: dduce on May 11, 2011, 07:39:17 pm
Hello everyone! This is my first post, and first time finding the board. I'm glad to have found you all. Hopefully I can find some answers here.

About me:
I'm a Chemical Engineering student. I'm fairly familiar with programming in MATLAB, and I've been programming on the Nspire CAS for about a month steady now. I'm not a complete beginner, but I'm far from a novice. ;)

Anyway, as I said, I have many questions that I will be posting on my journey, and hopefully I can answer a few questions too. Please, if you have any Chemistry questions, or the like, feel free to ask away. As for programming.... ::)

About the program:
I am developing a very sophisticated program that will collect strings and values, ultimately plugging these values into tons of equations and displaying answers, activities, equations, and loads more of helpful calculations and features that will help other colleagues in my field.

One problem that I am having is, you'll see the variables here, ion - charge - sznm. These are values that are stored in a spread sheet, and the headings of the columns, are the same as the variable names (as I'm sure you're all aware... just trying to be as specific as possible):
Quote
mstm:={ion,charge,sznm}

This works perfectly. If I type mstm[3], on the calculator application, for example, and press enter, the 3rd row of the matrix is displayed. Likewise, if I type in the calc promt: mstm[1,1]    , it will display the value in row one, column one. Works perfect. Now, here's the question, how do I tell it to display "ALL" rows of column 3? In MATLAB you would say mtsm(:,3) , meaning all rows in the 3rd column...

Another question that I have: is there a way to do a search for a string and/or a value?

InString and Frequency, unless I'm doing it wrong, don't appear to be what I need in order to perform this task.

in MATLAB it's a simple "find" command, and in excel, I believe it's Vlookup or Hlookup, meaning vertical/horizontal lookup, if that helps anyone.



Another question: is anyone familiar with the "indirection operator"?

I'm curious if I were to have string values stored in a list, is there a way to write a while loop, for example, that would grab each string value and convert it to a variable?


I've searched for days for this answer, which led me here. Can you help? Please  :) Much appreciation.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: apcalc on May 11, 2011, 08:20:15 pm
Its been a while since I did any Nspire BASIC programming, but I'll take a shot at some of your questions! :)

For displaying all of the values, I think a for loop would be best.  I am not 100% sure that this will work with an array of more than one dimension (and I can't test now :().

Code: [Select]
For x,1,dim(mstm)
Disp mstm[x][3]
EndFor

For the string issue, do you want to find the index of a certain substring in a string?

First, to convert from a number to string, use "string(number)" and to do the opposite, use "expr(string)"
To find the index of a substring in a string, use "inString(string,substring)", which will return the index of the substring if it is in the string (with the first index being "1", not "0").

If you need any more help, or I answered incorrectly, please feel free to ask!  Also, welcome to Omnimaga! :)
Title: Re: TI - Npsire, CAS; many programming questions
Post by: DJ Omnimaga on May 11, 2011, 08:28:11 pm
Heya and welcome on the forums. :)

What OS do you use by the way? I don't remember if BASIC was the same on every one of them.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: DJ Omnimaga on May 11, 2011, 09:00:43 pm
Ah ok. OS 2.1 should have most recent functions then. As for the BASIC language, it is more like the TI-89, but it is much more limited. Basically it doesn't have Getkey, Pixel-On/Off, Line() and Output/Text/Locate() equivalents, so the language is not suitable for people who are using their calculator for other purposes than school (such as gaming).

EDIT: Your post vanished O.O
Title: Re: TI - Npsire, CAS; many programming questions
Post by: dduce on May 11, 2011, 09:03:25 pm
Excellent, I'm grateful for the quick replies!

apcalc,

this seems very logical. I'm going to go and sit down and play around with this. I greatly appreciate you explaining those commands. I wasn't using them properly. I'll post back.

The hand held os is v2.1.1.38, and I should probably mention that I'm using the computer software, os v2.1.0.631, to program with. I've read the nspire BASIC is a lot a like the 83+ basic, but their are 4 or 5 generations worth of subtle differences between them and the nspire cas. No idea really though. I've never owned an 83 or 84.

Thanks again everyone! and for the welcoming :)
Title: Re: TI - Npsire, CAS; many programming questions
Post by: dduce on May 11, 2011, 09:05:51 pm
Ah ok. OS 2.1 should have most recent functions then. As for the BASIC language, it is more like the TI-89, but it is much more limited. Basically it doesn't have Getkey, Pixel-On/Off, Line() and Output/Text/Locate() equivalents, so the language is not suitable for people who are using their calculator for other purposes than school (such as gaming).

EDIT: Your post vanished O.O

Sorry about that. I didn't realize apcalc had posted as well. I wanted to reply to both. :)

I did run across the TI89 for dummies book. I tried to follow what was going on, but the 89 is so different than the nspire, I was lost to say the least.

What do you mean that the language is a lot more limited? Is there a way to fix this?
Title: Re: TI - Npsire, CAS; many programming questions
Post by: ruler501 on May 11, 2011, 09:10:25 pm
TI's stance with this calc is that the more locked up it is to games/utilities the better it will be. We have programs like Ndless that let us run C/Asm programs on our calcs. If TI doesn't remove it before they rerelease 3.x we have Lua, but our guesses are that it was unintentional to give it to us
Title: Re: TI - Npsire, CAS; many programming questions
Post by: DJ Omnimaga on May 11, 2011, 09:10:28 pm
Oh ok I see now. From what I could see, the language syntax seemed more similar to the TI-89 than the 83+, because of commands ending with () and stuff like that.

As for the language limitations, unfortunately there are no ways to fix that. TI has made it more limited so basically it is impossible to create games in it. Basically you will not be able to do stuff like
on the TI-Nspire using the on-calc language. Math programs will be possible, but you will not be able to create menus with moving cursors and stuff like that. If you only want to use the calculator for math/science purposes you should be fine, though.

To sum things up, in 2007 Texas Instruments started a crusade against calculator gaming.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: dduce on May 11, 2011, 09:27:32 pm
TI's stance with this calc is that the more locked up it is to games/utilities the better it will be. We have programs like Ndless that let us run C/Asm programs on our calcs. If TI doesn't remove it before they rerelease 3.x we have Lua, but our guesses are that it was unintentional to give it to us


I've read about ndless, but I thought it wouldn't work for my OS, being that the download that I find mentions it's for v1.7 and theirs not much talk further that I have found. Never heard of Lua. ... I'm really in the dark about C/Asm. I've seen it mentioned but over looked it. Is it a different language?

DJ_O,
That sucks. I was hoping to utilize the menu's and cursor... unfortunately for me though, I don't have time to really play around, as cool as these other capabilities are, Math and Science is my life for some time to come. I'm curious though, and again I may just be to novice still, but the calc came loaded with a bunch of examples. Within these examples, there are functions which utilize the menu and cursors. ... no idea yet how it's done though. Think that's part of the OS, or a separate script wrote particularly for these examples?

I'll have to jump on the software now and check these out.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: DJ Omnimaga on May 11, 2011, 09:35:08 pm
C and ASM are different languages. They're much harder to learn than BASIC and must be programmed on a computer. Ndless will run on OS 1.7, 2.0.1 and 2.1.0. I don't think it will run on OS 2.1.1, though. You need to download Ndless 2.0 Beta from the Ndless sub-forum here.

I don't think you need to worry about those languages if you are only planning to use the calculator for educational purposes, though.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: ruler501 on May 11, 2011, 09:37:31 pm
If you want to use Ndles I would suggest you downgrade to 2.0.1 it is smaller and there isn't much more in 2.1.
there is an Ndless section under Our Projects. Look there for any information you might need.
C is a higher level language than Asm and is slower. Asm is compiled directly into machine code and if written correctly is the fastest possible code.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: dduce on May 11, 2011, 10:29:29 pm
For displaying all of the values, I think a for loop would be best.  I am not 100% sure that this will work with an array of more than one dimension (and I can't test now :().

Code: [Select]
For x,1,dim(mstm)
Disp mstm[x][3]
EndFor

For the string issue, do you want to find the index of a certain substring in a string?

First, to convert from a number to string, use "string(number)" and to do the opposite, use "expr(string)"
To find the index of a substring in a string, use "inString(string,substring)", which will return the index of the substring if it is in the string (with the first index being "1", not "0").

I tried playing with the for loop, but it errors out, say "Domain Error". And it highlights the "mstm[ x][ 3]". I've tried mstm[x,3] , and that returns everything. The problem appears to be with way you tell the calc "all", there must be a symbol which means "all" when referencing the row... Very frustrating. Arg!  :banghead:


I did figure out this:
Code: [Select]
{xx,yy}=dim(mstm)
Returns:
{xx=3,yy=64}

However, the values xx and yy are not stored as a variable. So when I type "xx" in the calc prompt, it displays "xx" and not 3. Any ideas how to fix this? I tried {xx,yy}:= , with the colon, but it doesn't like that.

Regarding the search issue. Yes, I'd like to search be able to find the index number.

Also, I used you For ... EndFor suggestion and modified it like this:
Code: [Select]
indexd:=0
While indexd<dim(ion)
indexd:=indexd+1
disp mstm[indexd]
EndWhile

But it errors too.

Quote
First, to convert from a number to string, use "string(number)" and to do the opposite, use "expr(string)"
To find the index of a substring in a string, use "inString(string,substring)", which will return the index of the substring if it is in the string ...

I'm still struggling. Sorry. Maybe an example might help: my string value, for example are: "Br" , "Ag" , and "Cl", and these reside in the ion portion of the newly created matrix/list named mstm, and there are 2 other lists which correspond each ion. These lists are charge (row2) and size (row3). An example, let's say "Ag" is the second value of row 1, but lets pretend I don't know it's the second value of row 1. Lets say I write a program that asks you to enter a string value for the ion which you are searching for, the request is stored in the variable "ur_ion".

So the idea now is to compare ur_ion with row 1 of mstm, find that strings index, then using that index # it will grab the corresponding charge and size values associated with it, and create new variables storing the charge (named: nwchrg) and size (named: nwsznm)

Using those variables the calculation will continue. The program will request input, and so on...

Maybe instring, string, and expr are what I need to be using, but I still can't seem to figure it out.

Thanks again for the help.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: dduce on May 11, 2011, 10:35:18 pm
C and ASM are different languages. They're much harder to learn than BASIC and must be programmed on a computer. Ndless will run on OS 1.7, 2.0.1 and 2.1.0. I don't think it will run on OS 2.1.1, though. You need to download Ndless 2.0 Beta from the Ndless sub-forum here.

I don't think you need to worry about those languages if you are only planning to use the calculator for educational purposes, though.

Still, I think I need to invest the time to do some more researching. You've got my curiosity up. I'll keep poking around the site. There's tons of info that I haven't even discovered yet. Thanks again for the replies!
Title: Re: TI - Npsire, CAS; many programming questions
Post by: ruler501 on May 11, 2011, 10:54:37 pm
You should make an introduction topics so you can get  your peanuts(you'll understand once you make the topic).
This is a good community because they have absolutely everything you could possibly want from Nspire-Prizm-TI30. we program on-comp on-calc and on-calc-portable-device. We have an interesting math/science part also. It is a nice community to be a member of
Title: Re: TI - Npsire, CAS; many programming questions
Post by: DJ Omnimaga on May 11, 2011, 11:19:32 pm
Yeah at first we didn't have a math section, but then I added one (along with general technology/hardware/computer sections) and it became more popular than I expected.

As a suggestion, however, when replying to multiple posts, I suggest editing your reply with the second one included in the post, though, to avoid double-posting. Double-posting is allowed only after several hours (if for example nobody replied to a question or if you have another).

Also feel free to introduce yourself as ruler501 said. The intro section is a bit random, though. O.O
Title: Re: TI - Npsire, CAS; many programming questions
Post by: Jim Bauwens on May 12, 2011, 04:04:59 am
To get all the row cells in a columns, the best way is to flip the matrix using the 'transpose' command:
disp mstmT[3]
This should give you the data you want.

Then, about the indirection thing (#), it works like this:
Code: [Select]
"hello"->var1
"test"->#var1
var1 will then contain "hello", and hello will contain "test".
This will also work with values in a matrix ("test"->#mat[1,1]).

For the string searching, I assume you want too look through a list and or matrix?
As far as I know, you can't search matrixes and lists. You will have to make your own routine to do that:

This is for a matrix:
Code: [Select]
"findme"->searchstr
0->result
rowdim(matrix)->rowsize
coldim(matrix)->colsize
for yyy,1,rowsize
  for xxx,1,colsize
    if matrix[yyy,xxx] = searchstr then
      1->result
      exit
    endif
  endfor
endfor

searchstr is the string (it can also be a number) you want to search for.
If it is found, result will be 1, and the coordinates will be in yyy and xxx.
It might be that I switched rowsize and colsize, but thats easy to fix if its wrong.
You only need one for loop if you are searching a list.
Another way to check if something is in your matrix and/or list, but you don't need to know the position is this:
Code: [Select]
instring(string(matrix),"searchme")->result
If result is not 0, is means that "searchme" is in the matrix. This will also be faster than the above routine, but you don't have an accurate index.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: dduce on May 12, 2011, 01:06:56 pm
jimbauwens, that's brilliant!

It took a little work, but I got it working. Here's the section of code. It stores the row and column index in separate variables. I can certainly work with this. Thank you, and thank you for covering the indirection portion as well. This is very helpful, being that row1 of my matrix has all my variables stored in it as a string.

Thank you all for everything!

here's the working code:
Code: [Select]
{ion,charge,sznm}→mstm
Request "For which Ion?",searchstr
rowsize:=rowDim(mstm)
colsize:=colDim(mstm)
For xxx,1,rowsize
For yyy,1,colsize
If mstm[xxx,yyy]=searchstr Then
rowHERE:=xxx
colHERE:=yyy
Exit
EndIf
EndFor
EndFor

Thanks again!
Title: Re: TI - Npsire, CAS; many programming questions
Post by: Jim Bauwens on May 12, 2011, 02:26:02 pm
I'm glad you found it helpful :)

If you need any other help, I'll be here ;)
Title: Re: TI - Npsire, CAS; many programming questions
Post by: p2 on June 15, 2011, 09:00:49 am
Uses the TI-Nspire CX CAS the same language as the TI 84+ or is it a different one??
Title: Re: TI - Npsire, CAS; many programming questions
Post by: JosJuice on June 15, 2011, 09:04:06 am
Uses the TI-Nspire CX CAS the same language as the TI 84+ or is it a different one??
It uses a different one - the Nspire variant of TI-BASIC, and also Lua.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: Lionel Debroux on June 15, 2011, 09:04:30 am
All models of Nspire CAS support a BASIC language similar to that of the TI-68k (89, 92+, V200, 89T) series, which is quite different from the TI-Z80 (73, 76, 80, 81, 82, 83, 83+, 84+, 85, 86) BASIC.
The Nspire CAS's BASIC does not support drawing pixels or reading from the keyboard, though.
The latest versions of the Nspire CAS support a stripped-down version of the Lua programming language.
Title: Re: TI - Npsire, CAS; many programming questions
Post by: p2 on June 15, 2011, 09:08:43 am
 :'( :(
Do you know where I can get a guide which tells me all differents between TI83-Basic and this one?












Do you mean from education.ti.com ??
Title: Re: TI - Npsire, CAS; many programming questions
Post by: Lionel Debroux on June 15, 2011, 09:11:48 am
At least in the respective documentations of the TI-Z80 series, of the TI-68k series and of the Nspire series, which can be downloaded freely from TI :)
Title: Re: TI - Npsire, CAS; many programming questions
Post by: p2 on June 15, 2011, 09:18:53 am
http://education.ti.com/calculators/downloads/US/Guidebooks/Search/ (http://education.ti.com/calculators/downloads/US/Guidebooks/Search/)
Which is the correct one?
Title: Re: TI - Npsire, CAS; many programming questions
Post by: Ashbad on June 15, 2011, 09:25:09 am
Here's a good overview for Nspire programming:

http://tibasicdev.wikidot.com/nspire
Title: Re: TI - Npsire, CAS; many programming questions
Post by: Ghost on October 11, 2011, 10:24:34 am
hello guys, I am also new to the forum and am a complete rookie with the TI Nspire CX CAS. I have had it 48 hours, primary purpose is college math but I will eventually be using it for science as well. I have some very basic questions that I was hoping to get answered but as time goes on I'm sure they will develope into more complicated questions too.
 me trying to comunicate with it right now looks like this  :banghead:

the questions:
1 is the TI CAS for dummies a worthwhile pick up for a complete beginer?
2 while multiplying polynominals it doesn't correctly solve the equation. Is there a settings menu to tell it to do so or another way of inputting the problem to get the right answer?
3 along the same lines as #2 but on some equations it just refrazes the question instead of solving it (im using it in scratchpad mode if that matters)

a few examples to better explain it...sorry if you didnt need this part, just wanting to be clear.

if you input (x+1)^2
it will refraze as (x+1)*(x+1)
if you input the refraze the answer does not include x^2
I know how to do the math as 3 seperate problems to get the answer but is there a way to tell the CAS to solve it in 1 step ?
Similarly if you were to input -5(x+1)
it will refraze as 5(-x-1)
i used simple numbers where the math is easy to do in your head to make the explanation easier but is there a way to tell it to solve the equation ?
thanks in advance for any help provided