Assume that I want to solve a simultaneous equation below.
\begin{cases} 2x_1+3x_2=5\\ x_1-x_2=0 \end{cases}
First I construct two lists
coefs = {{2, 3, 5}, {1, -1, 0}};
vars = Array[x, 2];
Note that I feel more comfortable to put the constants 5
and 0
in the coefficient list rather than separating them into another list.
Because I don't know how to construct equ
from the above lists, I manually construct as follows.
equ = 2 x[1] + 3 x[2] == 5 && x[1] - x[2] == 0
Finally equ
is passed to Solve[equ, vars]
.
Question
What is the simplest way to construct equ
from the available two list coefs
and vars
?
Minimal Working Example
The following template will save your typing time.
coefs = {{2, 3, 5}, {1, -1, 0}};
vars = Array[x, 2];
equ = 2 x[1] + 3 x[2] == 5 && x[1] - x[2] == 0
Solve[equ, vars]
1st attempt
coefs = {{2, 3, 5}, {1, -1, 0}};
vars = Array[x, 2];
temp1 = {#1, #2} & @@@ coefs.vars
temp2 = Table[temp1[[i]] == coefs[[i, 3]], {i, 1, 2}]
equ = temp2[[1]] && temp2[[2]]
Solve[equ, vars]
I also want to know what is the best way to concatenate temp2
in
equ = temp2[[1]] && temp2[[2]]
.