HOME Mathematics Computer Science
Vector Addition
Show All
Hide All
Pythagorean Theorem

Right Triangles
  • A right triangle, or right-angled triangle, is a triangle in which one of the corners has an angle of 90o
  • For example:
  • To show that it is a 90o angle we add a little square in the corner:
    This is also called a 'right angle'
  • The longest side of the triangle is always the one opposite the right angle. This side is called the 'hypotinuse':
Pythagorean theorem
  • The pythagorean theorem can be used to find the length of the hypotinuse given the length of the other two sides.
  • if a, b, and c are the length of the three sides:
  • The pythagorean theorem states that:
    c2 = a2 + b2
  • if a = 4 and b = 3, calculate the length of c
  • Using the pythagorean theorem, we know that:
  • Now we just solve for c:
Finding other sides
  • We can also use the pythagorean theorem to find the length of any side, given that we know the other two.
  • For example: if a = 8 and c = 10, calculate the length of b
  • Using the pythagorean theorem, we know that:
  • Now we solve for b:
import math

a = 4
b = 3
c = math.hypot(a, b)

print(c) # prints: 5

  • Vectors are mathematical objects which represent change.
  • They are the complement to coordinates, which represent fixed points.
  • They have two properties:
    • Direction
    • Magnitude (or length)
  • They are often written as how much change they apply in each dimension:
    • A two dimensional vector that changes 3 in the first dimension and 5 in the second dimension is written as [3, 5]
  • When writing a variable which holds a vector, an arrow is placed above its symbol:

    LaTeX: \vec a = [3, 5]
Vectors in one dimension
  • A vector with only one dimension is written as a single value enclosed in a set of square brackets:
  • This can also be represented graphically:
  • Magnitude:
    • The magnitude of a one dimensional vector is simply the absolute value of its only element.
    • The vectors [5] and [-5] both have a magnitude of 5
  • Direction:
    • A one dimensional vector can only have two possible directions: forwards and backwards.
    • The vectors [5] and [-5] have the same magnitude but different directions.
    • The vectors [-3] and [-5] have different magnitudes but the same direction.
Vectors in two dimensions
  • A vector with two dimensions is written as a pair of values enclosed in a set of square brackets:
  • This can also be represented graphically:
  • Magnitude:
    • The magnitude of a two dimensional vector can be calculated using the Pythagorean theorem.
    • The two components of the vector form two sides of a right triangle.
    • The magnitude of the vector is equal to the hypotinuse.
    • For example:
    • If we apply the Pythagorean theorem:
Vectors in more than two dimensions
  • Vectors can be defined in as many dimensions as desired.
  • For example, a 5 dimensional vector would look like this:
  • Magnitude:
    • To calculate the magnitude of a vector with n dimensions we use the following formula:
    • For example, the magnitude of:
In python, vectors are represented as arrays.
import math
import numpy as np

vector = [3, 6, 2]

magnitude = math.sqrt(np.dot(vector, vector))
print(magnitude) # prints: 7.0

Vector Addition

  • Vectors can be added and subtracted to produce new matrices.
  • This is only possible if the vectors have the same number of elements.
  • To add (or subtract) two vectors, you add (or subtract) the corresponding elements.
Mathematical Definition
import numpy as np

a = [3, 6, 2]
b = [1, 3, 10]

c = np.add(a, b)
print(c) # prints: [4, 9, 12]