equationsToMatrix

Coefficient matrix and right-hand side of a linear system.

Category: Mathematics > Equation Solving

Syntax

[A, b] = equationsToMatrix(eqs, vars)

Writes the linear system as A*vars.' == b.

A = equationsToMatrix(eqs, vars)

Returns only the coefficient matrix.

Description

The equations must be linear in vars; anything not multiplying a variable moves to b. The matrices can then be handed to linsolve, rank or det.

Input arguments

eqs
Vector of linear symbolic equations or expressions.
vars
Vector of the unknowns, which fixes the column order.

Output arguments

A
Coefficient matrix, one row per equation and one column per variable.
b
Column vector of constants.

Example

Two equations in two unknowns

syms x y
[A, b] = equationsToMatrix([x + 2*y == 3, 4*x - y == 1], [x y])
Output
A = 
[1,  2]
[4, -1]
b = 
3
1

See also

linsolve solve jacobian eliminate