Skip to article frontmatterSkip to article content

5.1 Linear Functions

a simple function class

Dept. of Electrical and Systems Engineering
University of Pennsylvania

Binder

Lecture notes

1Reading

Material related to this page, as well as additional exercises, can be found in ALA 7.1.

2Learning Objectives

By the end of this page, you should know:

  • definition of Linear functions and some examples
  • how to verify linearity of functions
  • how matrix-vector multiplication relates to linear functions
  • composition of linear functions
  • inverses of linear functions

3Introduction to Linearity

A strategy that we have embraced so far has been to turn algebraic questions into geometric ones. Our foundation for this strategy has been the vector space, which allows us to reason abut a wide range of objects (vectors, polynomials, word histograms, and functions) as “arrows” that we can add, stretch, flip and rotate. Our canonical approach to transforming one vector into another has been through matrix-vector multiplication: we start with a vector x\vv x and create a new vector via the mapping xAx\vv x \mapsto A \vv x.

Our goal in this lecture is to give you a brief introduction to the theory of linear functions, of which the function f(x)=Axf(\vv x) =A \vv x, is a special case. Linear functions are also known as linear maps, or when applied to function spaces, linear operators. These functions lie at the heart of robotics, computer graphics, quantum mechanics, and dynamical systems. We will see that by introducing just a little bit more abstraction, we can reason about all of these different settings using the same mathematical machinery.

4Linear Functions

We start with the basic definition of a linear function which captures the fundamental idea of linearity: closed under addition and scalar multiplication. A formal definition is given below.

Before looking at some common examples, we make a few comments:

4.1Python break!

In the below example, we illustrate the rotation of vectors in Python by constructing a rotation matrix as given in Example 3 and applying the linear transform to the original vector.

import numpy as np
import matplotlib.pyplot as plt

def plot_vecs(origin, v1, v2):
    fig, ax = plt.subplots()
    ax.quiver(*origin, *v1, angles='xy', scale_units='xy', scale=1, color='r', label='Original')
    ax.quiver(*origin, *v2, angles='xy', scale_units='xy', scale=1, color='b', label='Rotated')
    ax.set_xlim(-3, 3)
    ax.set_ylim(-3, 3)
    plt.legend()
    plt.grid()
    ax.set_xlabel('X-axis')
    ax.set_ylabel('Y-axis')
    plt.show()

def rot_mat_cons(theta):
    return np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]])
    
theta = np.pi/6 # change this and observe how much the vector is rotated
rot_mat = rot_mat_cons(theta)

v1 = np.array([[1, 2]]).T
v2 = rot_mat @ v1

# Define the origin
origin = np.array([[0, 0]]).T

plot_vecs(origin, v1, v2)
<Figure size 640x480 with 1 Axes>

5Composition

Applying one linear function after another is called composition: let V,W,ZV, W, Z be vector spaces. If L:VWL: V \to W and M:WZM: W \to Z are linear functions, then the composite function ML:VZM \circ L: V \to Z, defined by (ML)(v)=M(L(v))(M \circ L)(\vv v) = M(L(\vv v)), is also linear (easily checked to satisfy rule (L)).

This gives us a “dynamic” interpretation of matrix-matrix multiplication. If L(v)=AvL(\vv v) = A\vv v maps Rn\mathbb{R}^n to Rm\mathbb{R}^m and M(w)=BwM(\vv w) = B\vv w maps Rm\mathbb{R}^m to Rl\mathbb{R}^l, so that ARm×nA \in \mathbb{R}^{m \times n} and BRl×mB \in \mathbb{R}^{l \times m}, then:

(ML)(v)=M(L(v))=B(Av)=(BA)v (M \circ L)(\vv v) = M(L(\vv v)) = B(A\vv v) = (BA)\vv v

so that the matrix representation of ML:RnRlM \circ L: \mathbb{R}^n \to \mathbb{R}^l is the matrix product BARl×nBA \in \mathbb{R}^{l \times n}. And, like matrix multiplication, composition of linear functions is in general not commutative (order of applying the function matters!)

5.1Python break!

In the below code, we illustrate composition of rotations in Python by multiplying rotation matrices.

theta1 = np.pi/6
theta2 = np.pi/2

rot1 = rot_mat_cons(theta1)
rot2 = rot_mat_cons(theta2)

v1 = np.array([[3, 0]]).T
v2 = rot1 @ rot2 @ v1 # composition of rotations

plot_vecs(origin, v1, v2)

## A reverse rotation

theta3 = -np.pi/2

rot3 = rot_mat_cons(theta3)

v3 = rot3 @ rot1 @ rot2 @ v1 # How can you get to v3 from v2?

plot_vecs(origin, v1, v3)
<Figure size 640x480 with 1 Axes><Figure size 640x480 with 1 Axes>

6Inverses

Just as with square matrices, we can define the inverse of a linear function. Let L:VWL: V \to W be a linear function. If M:WVM: W \to V is a linear function such that:

LM=IWandML=IVL \circ M = I_W \quad \text{and} \quad M \circ L = I_V

where IWI_W and IVI_V are identity maps on WW and VV respectively, then MM is the inverse of LL and is denoted M=L1M = L^{-1}.

Binder