Skip to main content

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

Section 3.2 Solving Systems of Equations

Sage allows for us to generalize the previous methods to solve systems of equations. In order to do this we must first define multiple symbolic variables, then we use the solve function as we did before.
There are various ways to create multiple symbolic variables at once. The following are all valid.
Notice how these symbolic variables are all equivalent regardless of how they are created.
To solve a system of equations algebraically, we first define the variables and the equations in the system.
In this case, the first argument to solve is a list of equations and the following arguments are the variables being solved for.
Observe that Sage returns a nested list structure. The outer list contains all possible solutions to the system (in this case, there is only one solution). Each solution is represented as an inner list of equations showing the value of each variable.
Since each equation defines implicitly a function, we can use implicit_plot to graph each equation in 2D-space.
We can also plot a point whose coordinates are the ones given in the solution.
Now the full plot with the equations, the solution, and a legend.
We also can solve a system of three equations with three variables.
We can plot the equations in 3D-space using implicit_plot3d.
Let’s add some color to the plot so we can distinguish the equations.
The following is an example of a system with infinitely many solutions. The general solution is expressed as a parameterized function.
The following is an example of an inconsistent system. Since the system has no solutions, Sage returns an empty list.