Skip to main content

Linear Algebra with SageMath: Learn math with open-source software

Section 4.2 Systems of Equations with Matrices

As an introduction to solving equations in Sage, we worked with equations symbolically. Now, we will learn how to solve systems of equations with vectors and matrices.
Let’s solve the following system of equations:
\begin{align*} \amp x + 2y \amp = 4\\ \amp y - z \amp = 0\\ \amp x + 2z \amp = 4 \end{align*}
In Sage, we can create an coefficient matrix using the matrix function.
Next, provide a list of constants to the vector function.
Finally, call the solve_right method on the matrix and pass the solution vector as its argument.
The output (4, 0, 0) expresses a solution to the system:
\begin{gather*} x = 4, \; y = 0, \; z = 0 \end{gather*}