I need to solve a bunch of systems of n
equations in n
unknowns where n
varies. I can do them, one by one, but I wish to automate the process.
The first equation equals 1 and the rest all equal zero. I currently type in each set of equations manually as follows. I have the n
unknowns in a list: list1 = {r,s,...,t}
. I have the expressions for the LHS in a 2nd list: list2 = {expr1, ..., exprn}
. I write
sol = Solve[list2[[1]]==1 && list2[[2]]==0 ... && list2[[n]]==0, list1]
I would like to just type Solve[expr, list]
where expr
is something like
list2[[1]]==1 && list2[[2]]==0 ... && list2[[n]]==0.
I experimented with Table
, RowBox
, BoxData
, and even CellPrint
but I don't know enough to write an expression involving &&
and ==
that will work inside the Solve
function.
Solve[Thread[list2==Prepend[ConstantArray[0,Length[list2]-1],1]], list1]
? $\endgroup$ – kglr Sep 29 '19 at 3:41Solve[First@list2 == 1 && And @@ Thread[Rest@list2 == 0], list1]
$\endgroup$ – Bob Hanlon Sep 29 '19 at 5:50