# Treat strings as variables?

I have a list of strings,

{"x1", "x2", "x3", "x4"}


And a list of linear equations:

{"x1" + "x3" - "x4" == 0, "x1" + "x2" + "x3" == 0}


How can I use Eliminate to eliminate "x1" from these equations? It complains that "x1" is not a valid variable. Is there a workaround?

-
I'd suggest you apply something like s_String:>v[s] to your list of equations before using Eliminate. – Ymareth May 16 '14 at 12:58
@Ymareth That works. My only complain is that it adds clutter. – becko May 16 '14 at 13:14
You can use Symbol[str] to convert a string str into a symbol, and then work with the symbol in the usual way. – Stephen Luttrell May 16 '14 at 15:27

Unfortunately the various Solve like functions don't show the same behavior concerning string-type variable names. Some do accept strings (e.g. NDSolve in version 9):

NDSolve[{"x"'["t"] == 0.1*"x"["t"], "x"[0] == 1}, "x", {"t", 0, 1}]


but others don't. For your case, Eliminate obviously doesn't, but you only need to convert those variables which you want to eliminate, like so:

Eliminate[{"x1" + "x3" - "x4" == 0, "x1" + "x2" + "x3" == 0} /. "x1" -> x1, x1]


you could even localize that variable, which won't prevent the variable to be generated in the Globalcontext but at least they won't be affected from any potential values of such a variable...

-
var = {"x1", "x2", "x3", "x4"};

eq = {"x1" + "x3" - "x4" == 0, "x1" + "x2" + "x3" == 0};


-x4 == x2

Eliminate[ToExpression[ToString[{"x1"+"x3"-"x4"==0,"x1"+"x2"+"x3"==0}]],{x1}]
`