# Solve with variables as single vector

Say I have a set of equations where the unknown variables are the elements of a vector $c=(c_1,c_2,\ldots)$ and want to solve it for $c$. Is there a way to do this with Solve without typing out all the elements?

In other words: Instead of writing something like

Solve[{c1*x + c2*y == 1, -c1*x + 2*c2*y == -2}, {c1, c2}]


which works and gives

{{c1 -> 4/(3 x), c2 -> -(1/(3 y))}}


I'd like to write something like

Solve[{c[[1]]*x + c[[2]]*y == 1, -c[[1]]*x + 2*c[[2]]*y == -2}, c]


which doesn't work

• What workflow do you have in mind, exactly? – Igor Rivin Oct 20 '14 at 17:35
• Workflow? In my real computation I will solve much more complicated sets of equations where it would be nice to try different numbers of elements in $c$ without typing each element every time. Is that what you mean? – jorgen Oct 20 '14 at 17:45
• What I have in mind is that the solution I had in mind (which is similar to the ones offered, one of which you had accepted) saves very little effort. – Igor Rivin Oct 20 '14 at 18:41

 cv = Array[ c , 2 ]
Solve[
{ cv[[1]] x + cv[[2]] y == 1 ,  -cv[[1]] x  + 2 cv[[2]] y  == -2} , cv]


{{c[1] -> 4/(3 x), c[2] -> -(1/(3 y))}}

 cv /. First@%


{4/(3 x), -(1/(3 y))}

And another completely different approach is to use LinearSolve

Clear[c1, c2, x, y]
eqs = {c1*x + c2*y == 1, -c1*x + 2*c2*y == -2};
vars = {c1, c2};
{b, mat} = CoefficientArrays[eqs, vars];
LinearSolve[mat, -b]


Another option:

vars = {c1, c2};
eqs = MapThread[{#1*x + #2*y == 1, -#1*x + 2*#2*y == -2} &, Map[List, vars]];
Solve[First@eqs, vars]