Ask Your Question

Revision history [back]

To solve this system of two equations in two unknowns, one can either use solve or, since the equations are linear, one could use linear algebra.

Here is how to use solve:

sage: x1, x2 = SR.var('x1 x2')
sage: p = [-10*x1 - 4*x2 + 14, -4*x1 - 2*x2 + 6]
sage: solve(p, x1, x2)
[[x1 == 1, x2 == 1]]

The following could help getting started with Sage:

To solve this system of two equations in two unknowns, one can either use solve or, since the equations are linear, one could use linear algebra.

Here is how to use solve:

sage: x1, x2 = SR.var('x1 x2')
sage: p = [-10*x1 - 4*x2 + 14, -4*x1 - 2*x2 + 6]
sage: solve(p, x1, x2)
[[x1 == 1, x2 == 1]]

The Using linear algebra, the question translates as solving $a u = b$ for $u$, where $a = \begin{pmatrix}10 & 4 \newline 4 & 2 \newline \end{pmatrix}$ and $b = \begin{pmatrix}14 \newline 6\end{pmatrix}$.

Here is how to solve that:

sage: a = matrix([[10, 4], [4, 2]])
sage: b = vector([14, 6])
sage: a \ b
(1, 1)

Now it's easy to change the vector b.

sage: a \ vector([3, 8])
(-13/2, 17)

To solve in the general case $b = \begin{pmatrix}b_x \newline b_y\end{pmatrix}$:

sage: a = matrix(SR, [[10, 4], [4, 2]])
sage: bx, by = SR.var('bx by')
sage: b = vector([bx, by])
sage: a \ b
(1/2*bx - by, -bx + 5/2*by)

Note that this amounts to computing the inverse of a:

sage: a.inverse()
[1/2  -1]
[ -1 5/2]

To read more about this and other topics, consider the following could help getting started with Sage:resources: