Revision history [back]

To complement @ortollj's answer which explains how to input the matrix by hand and solve it, here we explain how to enter the system as equations and get matrix form automatically.

Define the symbolic variables and equations:

sage: x, y = SR.var('x, y')
sage: eqns = [3*x + 2*y == 16,
....:         7*x +   y == 19]


Define list of unknowns in desired order, then extract matrix and vector:

sage: unks = [x, y]
sage: m = matrix([[lhs.coefficient(u) for u in unks] for eq in eqns for lhs in [eq.lhs()]])
sage: v = vector([eq.rhs() for eq in eqns])

sage: m
[3 2]
[7 1]
sage: v
(16, 19)


Solve:

sage: sol = m.solve_right(v)
sage: sol
(2, 5)


Check whether there are other solutions:

sage: m.right_kernel()
Vector space of degree 2 and dimension 0 over Symbolic Ring
Basis matrix:
[]


Since the kernel of the matrix has dimension zero, there are no other solutions.

Related: