6

I'm trying to write a function for a TI-Nspire cx cas calculator. I have to solve a large system, using the built-in solve function. I want to save the result of solve in some variables. For example, if the result is u1=2 and u2=3, I would like to store 2 and 3 respectively in the variables u1 and u2. Does anyone know how to do this automatically in a program?

ankh-morpork
  • 1,732
  • 1
  • 19
  • 28
  • 2
    You can use `string(Solve(...))` to convert the output of `Solve` to a string, then do some intensive string handling (using `inString` looking for characters between `"="` and `" "`) to extract the numerical values and convert them to numbers using `expr`. This is the only way I can think of doing it. Sorry I don't have time at the moment to actually write the code, but I did check and `string` will convert the expression to a string. – PGmath Mar 01 '15 at 03:23
  • In summary, there is no built-way way to do this – daparic Jul 13 '20 at 09:58

2 Answers2

4

Try exp▶list(Expr,Var) function. Example>

res:=solve({x+2*y=5,x-y=2},{x,y})

x=3 and y=1

l1:=exp▶list(res,{x,y})

[[3,1]]

fragg
  • 351
  • 1
  • 7
0

For linear equations you can simply use linsolve():

linSolve(x=5 and y=x+5, x, y)
-> {5,10}

Very handy is the pipe character for accessing the variables of the output:

solve(x=5 and y=x+5, x, y)
-> x=5 and y=10

x|x=5 and y=10
-> 5

You can also store the value:

res:={x, y}|x=5 and y=10

Unfortunately that does not work with an or in the output of solve.

jeanggi90
  • 741
  • 9
  • 24