π
<-

How to pass a mathematical expression to a function

:32tins: :32tinsktpb: :32tinsktpn: :32tinscas: :32tinstpkc: :32tinstpktpb: :32tinstp: :32tinscastp: :32tinscmc: :32tinscx: :32tinscxcas:

How to pass a mathematical expression to a function

Unread postby GuardedAirplane » 13 Nov 2015, 05:13

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.
User avatar
GuardedAirplane
Niveau 1: MD (Membre Débutant)
Niveau 1: MD (Membre Débutant)
Level up: 60%
 
Posts: 3
Joined: 12 Nov 2015, 04:51
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: How to pass a mathematical expression to a function

Unread postby Adriweb » 13 Nov 2015, 05:23

You must be using a wrong syntax because 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
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14840
Images: 1133
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: How to pass a mathematical expression to a function

Unread postby GuardedAirplane » 13 Nov 2015, 05:29

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
User avatar
GuardedAirplane
Niveau 1: MD (Membre Débutant)
Niveau 1: MD (Membre Débutant)
Level up: 60%
 
Posts: 3
Joined: 12 Nov 2015, 04:51
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: How to pass a mathematical expression to a function

Unread postby Adriweb » 13 Nov 2015, 06:25

I'm not sure you can do that on a Nspire (CX) non-CAS... because if you write 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
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14840
Images: 1133
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: How to pass a mathematical expression to a function

Unread postby Bisam » 13 Nov 2015, 06:43

Of course it can be done... but you have to work your way to it !

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
User avatar
BisamAdmin
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Level up: 69.6%
 
Posts: 5670
Joined: 11 Mar 2008, 00:00
Location: Lyon
Gender: Male
Calculator(s):
MyCalcs profile

Re: How to pass a mathematical expression to a function

Unread postby Adriweb » 13 Nov 2015, 06:48

I... can't believe I missed that, of course :P

(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
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14840
Images: 1133
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: How to pass a mathematical expression to a function

Unread postby GuardedAirplane » 13 Nov 2015, 13:42

I just tested the code on mine and it works perfectly! Thanks!
User avatar
GuardedAirplane
Niveau 1: MD (Membre Débutant)
Niveau 1: MD (Membre Débutant)
Level up: 60%
 
Posts: 3
Joined: 12 Nov 2015, 04:51
Gender: Not specified
Calculator(s):
MyCalcs profile


Return to Problèmes divers / Aide débutants

Who is online

Users browsing this forum: ClaudeBot [spider] and 33 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
2926 utilisateurs:
>2878 invités
>41 membres
>7 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)