Computing Library › Linear Algebra
Linear Algebra

Scalars, Vectors, and Matrices

The three basic containers of linear algebra: a single number, an ordered list of numbers, and a rectangular grid of numbers.

The building blocks

Linear algebra is the study of quantities arranged in structured collections and the linear operations that transform them. A scalar is a single number, such as 3 or -0.5. A vector is an ordered list of scalars, written as a column, for example [2, 5, -1]. A matrix is a rectangular array of scalars with rows and columns; an m-by-n matrix has m rows and n columns.

Notation is conventional: scalars are lowercase italics (a, x), vectors are lowercase bold (v, x), and matrices are uppercase bold (A, M). The entry in row i and column j of A is written A[i,j] or a_ij. A vector of length n lives in the space R^n; an m-by-n matrix maps vectors from R^n to R^m.

Kronos motion — three machines

Why the structure matters

The power of these containers comes from treating a whole collection as one object. Adding two vectors adds them component by component, and multiplying a vector by a scalar scales every component. These two operations, addition and scalar multiplication, are what make a set a vector space. A matrix is best understood not as a static grid but as a rule that transforms vectors: multiplying a vector by a matrix produces a new vector.

Shapes and conformability

Shape governs what is legal. You can add two matrices only if they have identical dimensions. You can multiply A by B only if the number of columns of A equals the number of rows of B. Keeping careful track of shapes prevents most errors in numerical code, and libraries such as NumPy report a shape mismatch immediately when dimensions do not conform.

python
import numpy as np
s = 3.0                       # scalar
v = np.array([2, 5, -1])      # vector in R^3
A = np.array([[1, 0],
              [0, 2],
              [3, 1]])        # 3x2 matrix
print(v.shape, A.shape)       # (3,) (3, 2)

In physics and engineering these containers describe fields, states, and operators. A simulation of a magnetized plasma, such as the design work behind the breeder Hyperion, represents field values on a grid as large vectors and the physics operators acting on them as matrices.