How to pass a mathematical expression to a function
7 posts
• Page 1 of 1
How to pass a mathematical expression to a function
I was trying to write a program on my Ti-Nspire CX that would make use of the nsolve() function; however, I cannot seem to get nsolve() to accept the input equation. I have the calculator request a string from the user. I have tried directly referencing the input string in nsolve() and also tried using the expr() function to convert it to an expression. If anyone could offer advice, it would be much appreciated.
-
GuardedAirplane
Niveau 1: MD (Membre Débutant)- Posts: 3
- Joined: 12 Nov 2015, 04:51
- Gender:
- Calculator(s):→ MyCalcs profile
Re: How to pass a mathematical expression to a function
You must be using a wrong syntax because
For example:
No need of a string.
Full syntax :
nSolve(equation,variable)
works fine.For example:
nSolve(x^3=26,x)
No need of a string.
Full syntax :
nSolve(Equation, Var[=Guess], lowerBound, upperBound)
MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)My calculator programs
Mes programmes pour calculatrices
-
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)- Posts: 14840
- Images: 1133
- Joined: 01 Jun 2007, 00:00
- Location: France
- Gender:
- Calculator(s):→ MyCalcs profile
- Twitter: adriweb
- GitHub: adriweb
Re: How to pass a mathematical expression to a function
Can you spot the error?
- Code: Select all
Define LibPub ensolve()=
Prgm
:RequestStr "Enter the function",function
:RequestStr "Enter the variable",variable
:Disp nSolve(function, variable)
:EndPrgm
-
GuardedAirplane
Niveau 1: MD (Membre Débutant)- Posts: 3
- Joined: 12 Nov 2015, 04:51
- Gender:
- Calculator(s):→ MyCalcs profile
Re: How to pass a mathematical expression to a function
I'm not sure you can do that on a Nspire (CX) non-CAS... because if you write
And if you try to expr() it within nSolve, you're just postponing the problem
You could do a Request on the equation and save it to func(x) for example, but then you'd lose the custom variable.
(but at least nSolve(func(x),x) would work, I tested that)
At this point, doing it with Lua instead of (in conjunction with, rather) TI-Basic would work around those stupid non-CAS limitations.
Request
instead of RequestStr
, which is what is supposed to be done, it'll evaluate the x variable because of the non-CAS math engine, so there won't be any correct function to solve...And if you try to expr() it within nSolve, you're just postponing the problem

You could do a Request on the equation and save it to func(x) for example, but then you'd lose the custom variable.
(but at least nSolve(func(x),x) would work, I tested that)
At this point, doing it with Lua instead of (in conjunction with, rather) TI-Basic would work around those stupid non-CAS limitations.
MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)My calculator programs
Mes programmes pour calculatrices
-
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)- Posts: 14840
- Images: 1133
- Joined: 01 Jun 2007, 00:00
- Location: France
- Gender:
- Calculator(s):→ MyCalcs profile
- Twitter: adriweb
- GitHub: adriweb
Re: How to pass a mathematical expression to a function
Of course it can be done... but you have to work your way to it !
As Adriweb said, you have to use
Something like below should work :
As Adriweb said, you have to use
expr(...)
but it has to be done in last position.Something like below should work :
- Code: Select all
Define LibPub ensolve()=
Prgm
:RequestStr "Enter the function",function
:RequestStr "Enter the variable",variable
:Disp expr("nSolve(" & function & "," & variable & ")")
:EndPrgm
-
BisamAdmin
Niveau 15: CC (Chevalier des Calculatrices)- Posts: 5670
- Joined: 11 Mar 2008, 00:00
- Location: Lyon
- Gender:
- Calculator(s):→ MyCalcs profile
Re: How to pass a mathematical expression to a function
I... can't believe I missed that, of course 
(Also I did try indirection, but it failed (on a CX at least). Maybe I did it wrong, I'm not sure.)

(Also I did try indirection, but it failed (on a CX at least). Maybe I did it wrong, I'm not sure.)
MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)My calculator programs
Mes programmes pour calculatrices
-
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)- Posts: 14840
- Images: 1133
- Joined: 01 Jun 2007, 00:00
- Location: France
- Gender:
- Calculator(s):→ MyCalcs profile
- Twitter: adriweb
- GitHub: adriweb
Re: How to pass a mathematical expression to a function
I just tested the code on mine and it works perfectly! Thanks!
-
GuardedAirplane
Niveau 1: MD (Membre Débutant)- Posts: 3
- Joined: 12 Nov 2015, 04:51
- Gender:
- Calculator(s):→ MyCalcs profile
7 posts
• Page 1 of 1
Return to Problèmes divers / Aide débutants
Who is online
Users browsing this forum: ClaudeBot [spider] and 33 guests