from edumath.linear_algebra import dot_product, vector_add, vector_norm
u = [2, 1]
v = [-1, 2]
print(vector_add(u, v))
print(vector_norm(u))
print(dot_product(u, v))[1. 3.]
2.23606797749979
0.0
A vector is an ordered list of numbers. In two dimensions, the vector \(\langle 3,4\rangle\) can mean “move 3 units right and 4 units up.” The same vector can also represent a point, a velocity, a force, a row of data, or a pair of unknowns. Linear algebra starts with vectors because they let us talk about many related numbers as one object.
By the end of this lesson, you should be able to:
A vector in two dimensions is often written
\[ \mathbf{v}=\begin{bmatrix}a\\b\end{bmatrix} \quad \text{or} \quad \langle a,b\rangle. \]
The first coordinate tells horizontal movement. The second coordinate tells vertical movement. The vector \(\langle 3,4\rangle\) can be drawn as an arrow from \((0,0)\) to \((3,4)\).
The ordered pair \((3,4)\) names a point. The vector \(\langle 3,4\rangle\) names a movement or displacement. They are drawn in similar places, but the vector idea emphasizes direction and length.
To add vectors, add matching coordinates:
\[ \begin{bmatrix}a\\b\end{bmatrix} + \begin{bmatrix}c\\d\end{bmatrix} = \begin{bmatrix}a+c\\b+d\end{bmatrix}. \]
Geometrically, vector addition means doing one movement and then the other. For example,
\[ \begin{bmatrix}3\\1\end{bmatrix} + \begin{bmatrix}-2\\4\end{bmatrix} = \begin{bmatrix}1\\5\end{bmatrix}. \]
You moved 3 right and 1 up, then 2 left and 4 up. The total movement is 1 right and 5 up.
A scalar is a single number. Scalar multiplication stretches, shrinks, or flips a vector:
\[ 3\begin{bmatrix}2\\-1\end{bmatrix} = \begin{bmatrix}6\\-3\end{bmatrix}. \]
If the scalar is negative, the vector reverses direction. If the scalar is between 0 and 1, the vector gets shorter.
The length of a vector is also called its norm or magnitude. In two dimensions,
\[ \lVert \mathbf{v} \rVert = \sqrt{a^2+b^2} \quad \text{for} \quad \mathbf{v}=\langle a,b\rangle. \]
This is the Pythagorean theorem. The vector \(\langle 3,4\rangle\) makes a right triangle with legs 3 and 4, so its length is
\[ \sqrt{3^2+4^2}=\sqrt{9+16}=\sqrt{25}=5. \]
The dot product combines two vectors and returns one number:
\[ \langle a,b\rangle \cdot \langle c,d\rangle = ac+bd. \]
Example:
\[ \langle 1,2\rangle \cdot \langle 3,4\rangle = 1\cdot 3 + 2\cdot 4 = 11. \]
The dot product is not just arithmetic. It measures how much two vectors point in the same direction.
A dot product produces a scalar, not a vector. Do not write \(\langle 1,2\rangle \cdot \langle 3,4\rangle = \langle 3,8\rangle\). Multiplying matching coordinates is only the first step; you must add the products.
Let \(\mathbf{u}=\langle 2,1\rangle\) and \(\mathbf{v}=\langle -1,2\rangle\).
Try these before opening the solutions.
Vectors become easier when you separate three ideas: coordinates tell movement, length measures size, and dot products compare directions.
Guess first. Does the vector <-2, 5> move right or left? Up or down?
Guided exercise.
Read the coordinates in order:
-2, so the horizontal movement is 2 units left.5, so the vertical movement is 5 units up.Checkpoint. Describe the movement of <4, -3> in words. Then say where the arrow ends if it starts at (0,0).
Guess first. If one vector moves right and another moves left, can their horizontal parts cancel?
Guided exercise.
Add <3, -1> + <-5, 4> by matching positions:
horizontal: 3 + (-5) = -2
vertical: -1 + 4 = 3
So
<3, -1> + <-5, 4> = <-2, 3>
The result means the combined movement is 2 units left and 3 units up.
Checkpoint. Compute <6, 2> + <-1, -7> and explain which coordinate changed direction.
Guess first. What does a negative scalar do to the direction of a vector?
Guided exercise.
Compute -3<2, -4> by multiplying every coordinate:
-3<2, -4> = <-6, 12>
Because the scalar is negative, the vector points in the opposite direction from the original vector.
Checkpoint. Compute (1/2)<8, -6> and describe how the length changes.
Guess first. Is the length of <5, 12> closer to 12, 13, or 17?
Guided exercise.
Use the norm formula:
length of <5, 12> = sqrt(5^2 + 12^2)
= sqrt(25 + 144)
= sqrt(169)
= 13
Length is never negative. It measures distance from the tail of the arrow to the tip.
Checkpoint. Find the length of <-8, 15>.
Guess first. If the dot product of two nonzero vectors is 0, are the vectors pointing the same way, opposite ways, or perpendicular?
Guided exercise.
Let u = <4, 1> and v = <-1, 4>. Then
u dot v = 4(-1) + 1(4) = 0
The zero dot product tells us these nonzero vectors are perpendicular.
Checkpoint. Compute <2, 3> dot <5, -1>. Are the vectors perpendicular?
<4, -3> moves right 4 and down 3. Starting at (0,0), it ends at (4,-3).<6, 2> + <-1, -7> = <5, -5>. The vertical coordinate changed from positive to negative.(1/2)<8, -6> = <4, -3>. The vector points the same direction and has half the length.sqrt((-8)^2 + 15^2) = sqrt(289) = 17.2(5) + 3(-1) = 7, so the vectors are not perpendicular.Guess lengths, dot products, and perpendicular relationships. If you miss a question, read the feedback and connect it to the formula.
Use the visible code below to reproduce the main computations. In a browser, these examples can also be adapted for PyScript/Pyodide because they use normal Python packages.
[1. 3.]
2.23606797749979
0.0