Free preview

61 lessons

Essential Linear Algebra for ML

Free preview

Essential Linear Algebra for ML · 61 lessons

Master the linear algebra that powers modern ML

No surprise gaps

Actually remember it

Skip what you know

One subscription. All learning paths included.

Our content is best on a larger screen

Solving systems of two linear equations

Understanding and representing systems of linear equations

Explanation

A system of linear equations is a set of two or more linear equations that involve the same variables. When there are two variables, each equation describes a straight line when plotted on a graph. In higher dimensions, each equation represents a flat surface (such as a plane in three variables). The variables are the unknowns we want to solve for, and a solution to the system is a set of values for the variables that make all the equations true at the same time.

For example, consider the following system with two variables, xx and yy:

{x+y=4xy=2\begin{cases} x + y = 4 \\ x - y = 2 \end{cases}

Here:

  • Each line is a linear equation in the variables xx and yy.
  • The system consists of both equations together.
  • A solution is a pair of values for xx and yy that satisfy both equations at once.

Algebraic representation

We often write a system of equations by listing all the equations together, often using a curly brace to show they are part of the same system:

{x+y=4xy=2\begin{cases} x + y = 4 \\ x - y = 2 \end{cases}

Visual representation

We can also represent a system of two equations in two variables by drawing both lines on the same graph. Each equation corresponds to a straight line. The point where the two lines cross (if they do) is the solution to the system, because it is the point that satisfies both equations.

For the example above, the two lines intersect at a single point. This point is the solution to the system.

Below is an interactive graph showing both equations. The blue and red lines represent the two equations. The point where they intersect, (3,1)(3, 1), is the solution to the system. This means that x=3x = 3 and y=1y = 1 makes both equations true.

Have a play around by modifying the lines and watch the system update.

246−2−4−6246−2−4−6
x+y=4.0
xy=2.0
(3.0,1.0)
{x+y=4.0xy=2.0
Solution: (3.0,1.0)

Drag the lines and any of the four points to change the lines. Watch how the equations and solution point update automatically.

Solving by substitution

Explanation

When we have a system of two linear equations with two variables, we can solve it using the substitution method. This method involves the following steps:

  1. Solve one equation for one variable.

    We start by choosing one of the equations and rearranging it so that one variable is written in terms of the other. For example, consider the system:

    {x+y=52xy=4\begin{cases} x + y = 5 \\ 2x - y = 4 \end{cases}

    We can solve the first equation for xx:

    x=5yx = 5 - y
  2. Substitute this expression into the other equation.

    Next, we substitute x=5yx = 5 - y into the second equation wherever xx appears:

    2xy=42(5y)y=4\begin{align*} 2x - y &= 4 \\ 2(5 - y) - y &= 4 \end{align*}
  3. Solve for the remaining variable, then back-substitute.

    Now we solve for yy:

    2×52yy=4102yy=4103y=43y=6y=2\begin{align*} 2 \times 5 - 2y - y &= 4 \\ 10 - 2y - y &= 4 \\ 10 - 3y &= 4 \\ 3y &= 6 \\ y &= 2 \end{align*}

    Now substitute y=2y = 2 back into the expression for xx:

    x=5yx=52x=3\begin{align*} x &= 5 - y \\ x &= 5 - 2 \\ x &= 3 \end{align*}

So the solution to the system is:

x=3,y=2x = 3, \quad y = 2

Summary of steps

  1. Rearrange one equation to write one variable in terms of the other.
  2. Substitute this expression into the other equation.
  3. Solve for the remaining variable.
  4. Substitute back to find the value of the first variable.

Example

Solve the system of equations:

{y=2x+13x+y=11\begin{cases} y = 2x + 1 \\ 3x + y = 11 \end{cases}

using the substitution method.

Solution

Step 1: The first equation is already solved for yy:

y=2x+1y = 2x + 1

Step 2: Substitute yy into the second equation by replacing yy with 2x+12x + 1:

3x+(2x+1)=113x + (2x + 1) = 11

Step 3: Solve for xx:

3x+2x+1=115x+1=115x=10x=2\begin{align*} 3x + 2x + 1 &= 11 \\ 5x + 1 &= 11 \\ 5x &= 10 \\ x &= 2 \end{align*}

Step 4: Substitute xx back into the expression for yy:

y=2x+1y=2×2+1y=4+1y=5\begin{align*} y &= 2x + 1 \\ y &= 2 \times 2 + 1 \\ y &= 4 + 1 \\ y &= 5 \end{align*}

So the solution to the system is:

x=2,y=5x = 2, \quad y = 5

Practice questions

3 questions

Solve the following system of equations using the substitution method:

{x=y+62x+y=13\begin{cases} x = y + 6 \\ 2x + y = 13 \end{cases}

What is the value of yy?

Select the correct answer:

+ 2 more questions

Solving by elimination (addition/subtraction method)

Explanation

When solving a system of two linear equations with two variables, we can also use the elimination method (also called the addition or subtraction method). The idea is to add or subtract the equations so that one of the variables is eliminated, allowing us to solve for the other variable.

Suppose we have the system:

{a1x+b1y=c1a2x+b2y=c2\begin{cases} a_1x + b_1y = c_1 \\ a_2x + b_2y = c_2 \end{cases}

We use elimination when the coefficients of one variable are equal or opposites (possibly after multiplying one or both equations by a constant). This allows us to combine the equations so that one variable cancels out.

Steps

  1. Make coefficients match: If needed, multiply one or both equations by a constant so that the coefficients of either xx or yy are equal or opposites.
  2. Add or subtract the equations:
    • Add the equations if the coefficients are opposites (e.g. b1=b2b_1 = -b_2).
    • Subtract one equation from the other if the coefficients are equal (e.g. b1=b2b_1 = b_2).
  3. Solve for the remaining variable: The result is a single equation with one variable, which we can solve.
  4. Substitute back: Substitute the value found into one of the original equations to solve for the other variable.

Note:

To add or subtract two equations, we perform the operation on both sides of the equations. For example, adding the equations means adding the left sides together and the right sides together:

(a1x+b1y)+(a2x+b2y)=c1+c2(a_1x + b_1y) + (a_2x + b_2y) = c_1 + c_2

Example

Solve the system:

{2x+3y=82xy=4\begin{cases} 2x + 3y = 8 \\ 2x - y = 4 \end{cases}

Solution

Since the coefficients of xx are already equal and the same sign, we can subtract the second equation from the first to eliminate xx. Note that it does not matter which equation we subtract from the other, as long as we are consistent on both sides - the solution will be the same.

Here, we chose to subtract the second equation from the first equation so that the right-hand side stays positive, but this is just a preference.

(2x+3y)(2xy)=842x+3y2x+y=44y=4y=1\begin{align*} (2x + 3y) - (2x - y) &= 8 - 4 \\ 2x + 3y - 2x + y &= 4 \\ 4y &= 4 \\ y &= 1 \end{align*}

Now substitute y=1y = 1 into one of the original equations (for example, the second):

2x1=42x=5x=52\begin{align*} 2x - 1 &= 4 \\ 2x &= 5 \\ x &= \dfrac{5}{2} \end{align*}

So the solution to the system is:

x=52,y=1.x = \dfrac{5}{2}, \quad y = 1.

Practice questions

3 questions

Solve the system of equations using the elimination method:

{3x+2y=115x2y=9\begin{cases} 3x + 2y = 11 \\ 5x - 2y = 9 \end{cases}

What is the solution (x,y)(x, y)?

Select the correct answer:

+ 2 more questions