Is there a command in BASIC that returns the value of a token? I'm trying to make a derivative equation finder, and I want to know if some one inputs something like cos(). It'll read something like: if the variable that's going through the string (whole equation) equals 196 (cos( ) or any of the other trig functions, then do this. For example, I know the cos( command is number 196. Is there a command that returns this number? Something like if it was getToken(): getToken('cos(') would return 196.

If you input a string and then use the expr( command on the stored string, it will do the math stored in that function. E.x. if you typed '2+2' and it was stored into Str1, followed by using expr(Stri1 , it give you the result: 4 . Hope that helps!

InString should do the stuff.

For example when the equation string is stored in Ans:

`:inString(Ans,cos(`

This will return 0 if cos( was not used and it will return any other positive number (to be exact, it will return the position of cos( in the equation), if cos was used.

Hope this helps.

As far as I know there does not exist any getToken() or that…

Wake me, when you need me.

expr( may be the command you are searching for.

Get futuristicOS 8 for your TI-84+

Learn more about futuristicOS 8

But how does expr( return whether cos( was used or not?

expr( only calculates the equation but does not help with finding the derivative, or am I wrong?

Wake me, when you need me.

I was going to post that inString() solution, too as that would be the most useful for a CAS-like derivative calculator.

The way I did it was I created a simple program like the following:

```
Input "FUNC:",Str1
":→Str2
Str1+Ans→Str1
prgmDERIV
Str2
```

Then prgmDERIV had a complicated code that used recursion to evaluate things like "cos(2X)" . Essentially, it would read the 'cos(' and then it looked for ending parentheses or a colon (I will explain this later). Anything in between, it would need to find the derivative of, so then it would do:

```
sub(Str1,A+1,B-A-1)+":"+Str1→Str1
prgmDERIV
```

B points to the end parentheses (4, in this case), A points to the "cos(", so at this point, Str1 is "2X:cos(2X):". Now prgmDERIV is called again and its job is to find the derivative of 2X because it only reads up to the colon, using inString(). Because cosine was a separate case, after evaluating to "2" and storing this to Str2, making Str2 as "2:" the next lines of code are:

```
inString(Str1,":→A
inString(Str2,":→B
"-
If B>1
Ans+sub(Str2,1,B-1
Ans+"sin("+sub(Str1,1,A-1)+")"+sub(Str2,Ans,length(Str2)-Ans+1→Str2
inString(Ans,")",A
sub(Str1,Ans,length(Str1)-Ans→Str1
End
```

That is a really unreadable code, so you would want to look at it in parts. However, the main thing it does is it uses a negative sign in front (derivative of cosine is -sine), then it adds the last computed derivative to that. That would be anything up to the first colon in Str2. For our example, that is "2". So now we have "-2" and then we add the "sin(" token and then whatever was inside the original cosine. Since this is up to the first colon in Str1, we have "2X" giving us the "-2sin(2X" and then we add a ")". Now we get rid of the "2:" and then we need to add our new string to the front of Str2 before returning (because if this was part of a more complicated derivative, like sin(cos(2X)), this call tot he program would just be returning the derivative of what's inside the sin() ). To do this, I just took the chunk of Str2 after and including the colon (colon=":", by the way) and added that to the end of the string. Now we have Str2="-2sin(2X):" and Str1 needs to have info removed. First we need to remove everything up to the parentheses in the cos(), so we currently have "2X:cos(2X):" A points to the colon, so we use the optional third argument of inString( to locate the first end parentheses after that colon. Then we just remove everything up until that point, including the end parentheses. Now we are left with ":" for Str1.

At this point, I made my program clean up a little and it loops until Str1=":". By cleaning up, I mean any "—" get changed to "+", any "+-" get changed to "-". My program never handled multiplication or division, or anything like that, but you can try that if you want. What you would do is, instead of deleting the "cos(2X)" from Str1, you would store it to Str3, for example, then delete. If the next token was not "+" or "-" then that implies either implicit multiplication, multiplication, division, or raising to a power. Then you can handle it accordingly.

47%? Take a look and try to imagine how cool 100% will be. This has won zContest 2011 and made news on TICalc. This compromise between Assembly and BASIC parses like BASIC and is fast like assembly. Grammer 2

What about this kind of approach:

```
ClrHome
Input Str9
If "SOLVE"=sub(Str9,1,5
Then
sub(Str9,7,length(Str9)-6→Str9
If inString(Str9,"=
Then
solve(expr(sub(Str9,1,inString(Str9,"=")-1)+"-("+sub(Str9,inString(Str9,"=")+1,length(Str9)-inString(Str9,"="))),X,1→A
Else
solve(expr(Str9→A
End
Disp "X=",A
End
```

See more: Forum Page

Get futuristicOS 8 for your TI-84+

Learn more about futuristicOS 8

How about using nDeriv() for multiple values of x, and then coming up with a formula for a function that goes through all those points using something like Xeda's Interpl8?

The problem is that nDeriv( uses iteration. Therefore you dont get the derivation equation, but that is what he wants.

Same is with futuristic: He does not want to solve the equation but he wants to find the derivative

Wake me, when you need me.

I did actually think of this idea, too, but it would be pretty slow (though a lot easier). For simple functions, it would actually work, but transcendental functions would require infinitely many points for that process to work.

@MasterChief2552: Basically, given a *n* degree polynomial, evaluating *n* points and then perfectly interpolating between them could work.

47%? Take a look and try to imagine how cool 100% will be. This has won zContest 2011 and made news on TICalc. This compromise between Assembly and BASIC parses like BASIC and is fast like assembly. Grammer 2

Ok, this is a really good idea. The last 2 days I created a program that creates the derivative by using this method of interpolating and it works!

It is able to find the derivative of any polynomial with an degree of 1 to 5. It also supports exponential functions.

For my program I use the standart regression commands.

Although there is also a intern regression for the logarithm, somehow it does not work with the logarithm.

Due to finding the derivative with an iteration (nDeriv is a iteration method) sometimes ugly results will be displayed:

For example I inputtet 8X^2 and 16,0000000157734X was displayed. I will try to debug this.

I will upload my code soon when I have more time.

But one question: Is there any way to read the a value and only the a value of the ax+b(Lin Reg) command. Otherwise I will have to do a complex method using inString(

Wake me, when you need me.

Excellent, and yes, you can access each variable by going to [vars][statistics][right][right].

I am glad it has worked for you!

47%? Take a look and try to imagine how cool 100% will be. This has won zContest 2011 and made news on TICalc. This compromise between Assembly and BASIC parses like BASIC and is fast like assembly. Grammer 2

Holy crap that was fast! Thanks a bunch you guys, I was using inString( before, but I just discovered it and had no clue what I was doing. Y'all rock!

Holy crap that was fast!

Yeah, as I postet for the first time something in this forum, I also wondered how a forum about a calculator (!) can be so active…

Wake me, when you need me.