{:check ["true"]}

Index

Vector Spaces

Algebra

Linear Algebra

In [1]:
import numpy as np
import matplotlib.pyplot as pl
from mpl_toolkits.mplot3d import Axes3D

Vectors

Vectors are points in some space.

$u = \left[\begin{array}{c} 1 \\ 3 \end{array}\right]\in\mathbb{R}^2$

$v = \left[\begin{array}{c} -2 \\1 \\ 3 \end{array}\right]\in\mathbb{R}^3$

In [2]:
u = np.array([1,3])
v = np.array([-2, 1, 3])
In [11]:
pl.figure(figsize=(6,6))
pl.scatter(u[0], u[1], s=100)
pl.xlim(-5,5)
pl.ylim(-5,5)
pl.grid(True)
In [17]:
fig = pl.figure(figsize=(6,6))
ax = fig.gca(projection='3d')
ax.scatter(v[0], v[1], v[2], s=100)
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_zlim(-5, 5);

Lines

An infinite line is given by:

$$ L = \{\mathbf{u} + t\cdot\mathbf{v}: t\in\mathbb{R}\} $$

A finite line segment is given by

$$ L = \{\mathbf{u} + t\cdot\mathbf{v}: t\in[0,1]\} $$
In [60]:
ts = np.linspace(0, 1, 20)
u = np.array([1, -1.5])
v = np.array([-1.5, 1])

L = np.array([u + t * v for t in ts])


fig = pl.figure(figsize=(10,5))
pl.subplot(1,2,1)
pl.grid(True)
pl.scatter(L[:,0], L[:,1])
pl.xlim(-2, 2)
pl.ylim(-2, 2);

pl.arrow(0, 0, *v, width=0.1)
pl.scatter(*u, color='r', s=200);

Planes

Planes are sets of points formed as linear combinations of basis vectors.

In 3D, a plane has two basis vectors.

$$ P = \{s\mathbf{u} + t\mathbf{v}: s, t\in\mathbb{R}\}$$

For higher dimensions, we will need more basis vectors to describe a plane... unless we use a normal vector.

In [67]:
u = np.array([1, 2, 0.])
v = np.array([1, 2, 1])

S = np.linspace(-1, 1, 10)
T = np.linspace(-1, 1, 10)

P = np.array([s*u + t*v for s in S for t in T])
fig = pl.figure(figsize=(10, 10))
ax = fig.gca(projection='3d')
for point in P:
    ax.scatter(*point, color='blue')

Normal Vectors of Planes

It turns out that a plane can be described by a single vector in any dimension.

Given a vector $\mathbf{w}\in\mathbb{R}^3$, we can define the plane as any vector that is orthogonal to $\mathbf{w}$.

$$P = \{ \mathbf{x}\in\mathbb{R}^3: \left<\mathbf{x}, \mathbf{w}\right> = 0\} $$

Getting the normal vector

From the basis vectors of $P$, we can get its normal vector using the cross product:

$$ \mathbf{w} = \mathbf{u}\times \mathbf{v} $$

Getting the basis vectors

If we have the normal vector $\mathbf{w}\mathbb{R}^n$, we can compute the basis vectors by solving the equations:

  • $\left<\mathbf{w},\mathbf{u}\right>$ = 0

  • $\left<\mathbf{w},\mathbf{v}\right>$ = 0

In [69]:
w = np.cross(u, v)
w
Out[69]:
array([ 2., -1.,  0.])
In [72]:
# Let's check points in P

P @ w
Out[72]:
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
In [ ]: