Section 3.1 Solving Equations
The
solve
function algebraically solves an equation, system of equations, or inequality. By default, Sage assumes the equation is equal to \(0\text{.}\) Let’s solve for \(x\) in the equation \(8 + x = 0\text{.}\)
Let’s solve for \(x\) in the equation \(8 + x = 5\text{.}\)
To use a variable other than
x
, we need to create a symbolic variable object with the var()
function. Otherwise, Sage will not recognize the variable as a symbolic variable.We can store the equation in a new variable and perform operations on it. Recall the single equal sign (
=
) is the assignment operator, while the double equal sign (==
) is the equality operator.Observe that the solution of a equation is given between square brackets, indicating that the data type is a list. We can access the solution by indexing the list with square brackets. Notice that after accessing the solution, the brackets are no longer present.
We can also access each side of the equation. Here is the right-hand side of the equation.
Here is the left-hand side of the equation.
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.
Now let’s define a system of equations.
In this case, the first argument to
solve
is a list of equations. Next, we specify the variables to solve 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 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. We can express the general solution as a function of a parameter.