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.

  • 2
    $\begingroup$ maybe Solve[Thread[list2==Prepend[ConstantArray[0,Length[list2]-1],1]], list1]? $\endgroup$ – kglr Sep 29 '19 at 3:41
  • 2
    $\begingroup$ Solve[First@list2 == 1 && And @@ Thread[Rest@list2 == 0], list1] $\endgroup$ – Bob Hanlon Sep 29 '19 at 5:50
  • $\begingroup$ Both of these work perfectly. Thank you kglr and Bob Hanion. $\endgroup$ – matrixbud Sep 29 '19 at 11:53

You can try

Solve[Thread[list2 == Prepend[ConstantArray[0, Length[list2] - 1], 1]], list1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.