Author Topic: TI - Npsire, CAS; many programming questions  (Read 7486 times)

0 Members and 1 Guest are viewing this topic.

Offline dduce

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
TI - Npsire, CAS; many programming questions
« 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.
« Last Edit: May 11, 2011, 08:21:00 pm by dduce »

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #1 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! :)
« Last Edit: May 11, 2011, 08:21:05 pm by apcalc »


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI - Npsire, CAS; many programming questions
« Reply #2 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.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI - Npsire, CAS; many programming questions
« Reply #3 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
« Last Edit: May 11, 2011, 09:01:06 pm by DJ_O »

Offline dduce

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #4 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 :)
« Last Edit: May 11, 2011, 09:06:52 pm by dduce »

Offline dduce

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #5 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?

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #6 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
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI - Npsire, CAS; many programming questions
« Reply #7 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.
« Last Edit: May 11, 2011, 09:11:11 pm by DJ_O »

Offline dduce

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #8 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.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI - Npsire, CAS; many programming questions
« Reply #9 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.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #10 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.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline dduce

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #11 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.
« Last Edit: May 11, 2011, 10:47:37 pm by dduce »

Offline dduce

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #12 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!

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: TI - Npsire, CAS; many programming questions
« Reply #13 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
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI - Npsire, CAS; many programming questions
« Reply #14 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