@sym
: [A, b] =
equationsToMatrix (eqns, vars)
¶@sym
: [A, b] =
equationsToMatrix (eqns)
¶@sym
: [A, b] =
equationsToMatrix (eq1, eq2, …)
¶@sym
: [A, b] =
equationsToMatrix (eq1, …, v1, v2, …)
¶Convert set of linear equations to matrix form.
In its simplest form, equations eq1, eq2, etc can be passed as inputs:
syms x y z [A, b] = equationsToMatrix (x + y == 1, x - y + 1 == 0) ⇒ A = (sym 2×2 matrix) ⎡1 1 ⎤ ⎢ ⎥ ⎣1 -1⎦ ⇒ b = (sym 2×1 matrix) ⎡1 ⎤ ⎢ ⎥ ⎣-1⎦
In this case, appropriate variables and their ordering will be
determined automatically using symvar
(see ‘@sym/symvar’).
In some cases it is important to specify the variables as additional inputs v1, v2, etc:
syms a [A, b] = equationsToMatrix (a*x + y == 1, y - x == a) -| ??? ... nonlinear... [A, b] = equationsToMatrix (a*x + y == 1, y - x == a, x, y) ⇒ A = (sym 2×2 matrix) ⎡a 1⎤ ⎢ ⎥ ⎣-1 1⎦ ⇒ b = (sym 2×1 matrix) ⎡1⎤ ⎢ ⎥ ⎣a⎦
The equations and variables can also be passed as vectors eqns and vars:
eqns = [x + y - 2*z == 0, x + y + z == 1, 2*y - z + 5 == 0]; [A, B] = equationsToMatrix (eqns, [x y]) ⇒ A = (sym 3×2 matrix) ⎡1 1⎤ ⎢ ⎥ ⎢1 1⎥ ⎢ ⎥ ⎣0 2⎦ B = (sym 3×1 matrix) ⎡ 2⋅z ⎤ ⎢ ⎥ ⎢1 - z⎥ ⎢ ⎥ ⎣z - 5⎦
See also: @sym/solve.
Package: symbolic