Search code examples
ti-basicti-nspire

Evaluating values in a linear equation with 2 variables given by the user


I'm trying to make a TI-Basic script for my "TI-nspire CX II CAS" that evaluates linear equations with 2 variables.

This is my code:

Define LibPub test()=
Prgm
 request "Insert function: ",fxy
 request "Point X: ",a
 request "Point Y: ",b

 Define p1(x,y)=fxy
 result:= p1(a,b)

 disp "The value is: ",result
 clearAz
EndPrgm

If I run this script with the following data: fx=x+y a=1 and b=2

The output I'm getting is:

res=x+y

The expected output / What I need is:

res=3


P.S.:

I noticed that removing the first request and typing an equation directly in the code (in the define) makes the code work as intended:

Define LibPub test()=
Prgm
 request "Point X: ",a
 request "Point Y: ",b

 Define p1(x,y)=x+y
 result:= p1(a,b)

 disp "The value is: ",result
 clearAz
EndPrgm

Input: a=1 and b=2. Output:res=3

But it is essential that the script evaluates the function and values given by the user.

Any ideas of how to fix this code?

Cheers


Solution

  • Using the pipe operator |, we can pass in specific values to an expression. This is often used to circumvent the need to write a function to pass in values.

    Define LibPub test()=
    Prgm
     request "Insert function: ",fxy
     request "Point X: ",a
     request "Point Y: ",b
    
     result:= fxy|x=a and y=b
    
     disp "The value is: ",result
     clearAz
    EndPrgm