Systems of linear equations

Joshua R. Davis, Carleton College, Math 134, Fall 2024

One equation in two variables

Here is an equation in two variables x and y. The equation is linear, meaning that the variables are scaled by constants and added together, but no more complicated operations are involved: squaring the unknowns, taking cube roots, taking cosines, etc. (In Mathematica, you enter an equation using a double equals sign == rather than a single equals sign =.)

2 x + 3 y == 0

Activate the code cell above, by clicking on the equation and pressing Shift-Return. Mathematica just parrots the equation back at you, because it doesn’t know what x and y are, and it doesn’t know what you want to do with the equation.

Here are two ways to graph the equation. In the first way, we manually solve for y in terms of x, and plot that function. In the second, we ask Mathematica to numerically find all of the points (x, y) where 2 x + 3 y is equal to 0 (and less than 0 and greater than 0). The two approaches are mathematically identical but computationally different. (As you read through this Mathematica notebook, activate every code cell and try to understand the results.)

Plot[
(-2 / 3) x, 
{x, -6, 6}, AspectRatio->1]
ContourPlot[
2 x + 3 y, 
{x, -6, 6}, {y, -4, 4}, AspectRatio->1, Contours->{0}]

Here we ask Mathematica to solve the equation. It can’t nail down a single solution, because there are infinitely many solutions (all of the points along the line). But it can simplify the equation to a form where, if we declare a value for one variable, then the other variable’s value is determined.

Solve[
2 x + 3 y == 0, 
{x, y}]

Two equations in two variables

Suppose now that we have another linear equation. We can plot it and solve it on its own.

-5 x + 5 y == 5
Plot[
x + 1, 
{x, -6, 6}, AspectRatio->1]
ContourPlot[
-5 x + 5 y, 
{x, -6, 6}, {y, -5, 7}, AspectRatio->1, Contours->{5}]
Solve[
-5 x + 5 y == 5, 
{x, y}]

But things get more interesting when we try to solve both equations simultaneously. That is, we seek to discover all points (x, y) that satisfy both equations. Now there is a single algebraic answer, which corresponds to the point of intersection between the two lines. (Compute this answer by hand on paper as well.)

2 x + 3 y == 0
-5 x + 5 y == 5
Plot[
{(-2 / 3) x, x + 1}, 
{x, -6, 6}, AspectRatio->1]
Solve[
{2 x + 3 y == 0, -5 x + 5 y == 5}, 
{x, y}]

Do two linear equations always have exactly one solution? Well, do two lines always intersect in exactly one point? What if I change the “2” in the first equation to a -3? (Compute this answer by hand on paper as well.)

-3 x + 3 y == 0
-5 x + 5 y == 5
Plot[
{ x, x + 1}, 
{x, -6, 6}, AspectRatio->1]
Solve[
{-3 x + 3 y == 0, -5 x + 5 y == 5}, 
{x, y}]

And what if I change the “0” to a “3”? (Compute this answer by hand on paper as well.)

-3 x + 3 y == 3
-5 x + 5 y == 5
Plot[
{ x + 1, x + 1}, 
{x, -6, 6}, AspectRatio->1]
Solve[
{-3 x + 3 y == 3, -5 x + 5 y == 5}, 
{x, y}]

In these three most recent examples, we have found 1, 0, or infinitely many solutions. That always happens. The number of solutions to a system of linear equations is always 0, 1, or infinite.

One equation in three variables

Here is one linear equation in three variables.

y + 2 x == 3 z

It’s more common to move all of the variables to the left side, move all of the constant terms to the right side, and put the variables in alphabetical order. After we do that, we get an equivalent equation.

2 x + y - 3 z == 0

Let’s try plotting it. In the first way, we solve for z as a function of x and y, and plot that function. In the second way, we ask Mathematica to numerically find all points (x, y, z) where the quantity 2 x + y - 3 z is equal to 0. In both ways, the plot is 3D, because there are three variables. You can rotate it by dragging it with your mouse.

Plot3D[
(2 / 3) x + (1 / 3) y, 
{x, -6, 6}, {y, -6, 6}, BoxRatios->{1, 1, 1}]
ContourPlot3D[
2 x + y - 3 z, 
{x, -6, 6}, {y, -6, 6}, {z, -6, 6}, Contours->{0}]

If we ask Mathematica to solve the linear equation, it effectively simplifies it to a point where, if we knew the values of two variables, then they would determine the value of the third variable.

Solve[
2 x + y - 3 z == 0, 
{x, y, z}]

Two equations in three variables

Let’s throw in another linear equation.

2 x + y - 3 z == 0
x + 3 z == 1

Each equation determines a plane. So now we have two planes floating in 3D. What is the meaning of the line where they intersect?

Plot3D[
{(2 / 3) x + (1 / 3) y, (-1 / 3) x + (1 / 3)}, 
{x, -6, 6}, {y, -6, 6}, BoxRatios->{1, 1, 1}]

Here’s what happens when we ask Mathematica to solve the linear system. Why?

Solve[
{2 x + y - 3 z == 0, x + 3 z == 1}, 
{x, y, z}]

Three equations in three variables

Let’s throw in yet another linear equation.

2 x + y - 3 z == 0
x + 3 z == 1
x - y + 2 z == 1

Now we have three planes floating in 3D. Do they intersect in a line, or a point, or what? And what does that intersection mean?

Plot3D[
{(2 / 3) x + (1 / 3) y, (-1 / 3) x + (1 / 3), (-1 / 2) x + (1 / 2) y + (1 / 2)}, 
{x, -6, 6}, {y, -6, 6}, BoxRatios->{1, 1, 1}]

Here’s what happens when we ask Mathematica to solve the linear system. Why?

Solve[
{2 x + y - 3 z == 0, x + 3 z == 1, x - y + 2 z == 1}, 
{x, y, z}]

Is it possible for a system of three linear equations in three unknowns to have no solution? Yes.

2 x + y - 3 z == 0
x + 2 y + 3 z == 1
x - y - 6 z == 1
Plot3D[
{(2 / 3) x + (1 / 3) y, (-1 / 3) x - (2 / 3) y + (1 / 3), (1 / 6) x - (1 / 6) y - (1 / 6)}, 
{x, -6, 6}, {y, -6, 6}, BoxRatios->{1, 1, 1}]
Solve[
{2 x + y - 3 z == 0, x + 2 y + 3 z == 1, x - y - 6 z == 1}, 
{x, y, z}]

Is it possible for a system of three linear equations in three unknowns to have infinitely many solutions? Yes.

2 x + y - 3 z == 0
x + y + 3 z == 1
2 x + 2 y + 6 z == 2
Plot3D[
{(2 / 3) x + (1 / 3) y, (-1 / 3) x - (1 / 3) y + (1 / 3), (-1 / 3) x - (1 / 3) y + (1 / 3)}, 
{x, -6, 6}, {y, -6, 6}, BoxRatios->{1, 1, 1}]
Solve[
{2 x + y - 3 z == 0, x + y + 3 z == 1, 2 x + 2 y + 6 z == 2}, 
{x, y, z}]

Again, we have seen examples of linear systems with 1, 0, or infinitely many solutions. The number of solutions to a system of linear equations is always 0, 1, or infinite.

Five equations in five variables

When there are many variables --- say, more than four --- we tend to give them names such as (Subscript[x, 1]), (Subscript[x, 2]), (Subscript[x, 3]), ... rather than x, y, z, w, .... Here is an example of five equations in five variables. In principle, such a system can be solved by hand, using the methods introducted in Sections 1.1 and 1.2. In practice, solving big systems is time-consuming and error-prone. So I won’t ask you to solve systems this big by hand. But Mathematica can do it quickly. :)

Solve[
{x1 + x2 - x3 == 3, x2 + x4 + x5 == 7, x1 - 4 x2 + 3 x5 == -1, x4 + 2 x5 == 4, x3 - 2 x4 + 3 x5 == 2}, 
{x1, x2, x3, x4, x5}]

Notice that I’m not including a picture this time. There is a geometric interpretation to the system: Each equation defines a four-dimensional “hyperplane” sitting inside 5D space. Those five hyperplanes intersect in a single 5D point, which is the solution shown above. As humans, we just can’t visualize it.