help equationsToMatrix
--- help for sym/equationsToMatrix ---
equationsToMatrix Convert linear equations to matrix notation.
[A,b] = equationsToMatrix([eq1,eq2,eq3,...],[x1,x2,...,xn]) converts
the equations eq1,eq2,eq3,... to matrix notation. Equations need to be
linear in the variables specified as second argument. eq1,eq2,eq3,...
can be SYM equations or simply SYM objects. In case eq1,eq2,eq3,...
are generic SYM objects, they will be interpreted as left sides
of equations, whose right sides are equal to 0. The equations just
need to be linear in the given variables, it does not play a role how
they are ordered or on which side of the equations the unknowns show up.
[A,b] = equationsToMatrix([eq1,eq2,eq3,...]) converts the equations
[eq1,eq2,eq3,...] to matrix notation. Equations need to be linear in
all variables of the equations. The system is interpreted as a linear
system of equations in the variables symvar([eq1,eq2,eq3,...]).
[A,b] = equationsToMatrix(eq1,eq2,eq3,...,x1,x2,...,xn) does the same
as equationsToMatrix([eq1,eq2,eq3,...],[x1,x2,...,xn]).
[A,b] = equationsToMatrix(eq1,eq2,eq3,...) does the same as
equationsToMatrix([eq1,eq2,eq3,...]).
If you do not assign the output to variables A and b or just assign the
output to a single variable, only the matrix A will be returned.
Examples:
syms x y z
eq1 = x + y + z
eq2 = x - 2*y - 5*z == 0
eq3 = x - z == 1
[A,B] = equationsToMatrix([eq1,eq2,eq3],[x,y,z])
A = equationsToMatrix([eq1,eq2,eq3],[x,y,z])
[A,B] = equationsToMatrix(eq1,eq2,eq3,x,y,z)
A = equationsToMatrix(eq1,eq2,eq3,x,y,z)
[A,B] = equationsToMatrix([eq1,eq2,eq3])
A = equationsToMatrix([eq1,eq2,eq3])
[A,B] = equationsToMatrix(eq1,eq2,eq3)
A = equationsToMatrix(eq1,eq2,eq3)
See also LINSOLVE, MLDIVIDE, SYM/LINSOLVE, SYM/MLDIVIDE, SOLVE, DSOLVE
Documentation for sym/equationsToMatrix
doc sym/equationsToMatrix
For example.
syms x y
E1 = x + y == 1
E1 = ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1124900/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1124900/image.png)
E2 = x - y == 2
E2 = ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1124905/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1124905/image.png)
[A,B] = equationsToMatrix(E1,E2,[x,y])
A =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1124910/image.png)
B =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1124915/image.png)