I'm writing a program that will solve the value of 1 variable in a 4-variable equality equation, but the variable to be solved will depend on the user's input to the program.
This is what I've come up with: Create a Mathematica script that reads in 4 parameters from the commandline. Read in the given 4 values and assign it to 4 variables. The variable that needs to be solved will have a specific value (say -100). I need to identify that variable and Remove
it from the Mathematica namespace, so that 3 variables remain.
I can then call the Solve
function that contains n variables, but since I've used Remove on 1 of those, Mathematica solves the value for that variable.
The only part that I don't get to work, is to identify which symbol's value is -100 so that I can call Remove
on the symbol.
Can anyone suggest a solution? I've tried putting all my variables in a list and find the symbol with value -100 using Position
or Case
, but it only returns the -100 numerical value and not the symbol name. As so:
(* Values for a, b, c and d have been read from the commandline using *)
(* a = ToExpression[$CommandLine[[4]]] etc *)
list = {a, b, c, d}
(* {1, 2, 3, -100} *)
Position[list, -100]
(* {{4}} *)
Cases[list, -100]
(* {-100} *)
(* I can't call Remove on the answers given by Position and Cases to remove variable d *)
I've tried some other solutions as well but with no luck. In case it's relevant - I'm new to Mathematica.
Clear
on the variable you want to be value-free than to callRemove
. $\endgroup$