6. Vector algebra

Vectors support two basic operations. The first is addition. Two vectors of the same size can be added together elementwise. (The same is true for subtraction.) If the vectors have different sizes, the operation is not defined.

Example

If \(\bfx=[1;\: 2;\: 3]\) and \(\bfy=[-2;\: 2;\: 0]\), then

\[\begin{split}\bfx + \bfy = \begin{bmatrix} -1\\4\\3 \end{bmatrix}.\end{split}\]

Things get a little more interesting with multiplication. We begin with scalar multiplication, which is between a number and a vector. Each element is multiplied by the number. In this context we call a number a scalar, since it scales all the elements equally.

Example

If \(\bfx=[1;\: 2;\: 3]\), then

\[\begin{split}3\bfx = \begin{bmatrix} 3\\6\\9 \end{bmatrix}.\end{split}\]

6.1. Linear combination

Vector addition and scalar multiplication combine to give an operation we will use repeatedly for both linear algebra and differential equations.

Definition 6.1 (Linear combination)

Given scalars \(c_1,\ldots,c_n\) and the same number of vectors \(\bfx_1,\ldots,\bfx_n\), all in \(\real^m\) or \(\complex^m\), a linear combination of them is

\[c_1 \bfx_1 + c_2 \bfx_2 + \cdots c_n \bfx_n,\]

where the \(c_j\) are called coefficients of the linear combination.

Linear combinations interact conveniently with linear functions. If \(L\) is linear, then according to the properties in the definition of linearity,

\[ L( c_1 \bfx_1 + c_2 \bfx_2 + \cdots c_n \bfx_n ) = c_1 L(\bfx_1) + c_2 L(\bfx_2) + \cdots + c_n L(\bfx_n). \]

This mundane-looking equation is the basis of a lot of important mathematics.

6.2. Linear combinations and systems

An equation about linear combination of vectors is equivalent to a linear system of equations. For example, consider the system

\[\begin{align*} x_1 - x_2 - x_3 & = 2 \\ 3x_1 - 2x_2 & = 9 \\ x_1 - 2x_2 - x_3 & = 5. \end{align*}\]

Interpreting vector equalities elementwise, this is equivalent to

(6.1)\[x_1 \threevec{1}{3}{1} + x_2 \threevec{-1}{-2}{-2} + x_3 \threevec{-1}{0}{-1} = \threevec{2}{9}{5}.\]

We can identify the three vectors on the left side as the columns of the coefficient matrix \(\bfA\), and the one on the right is \(\bfb\). I.e.,

\[x_1 \bfa_1 + x_2 \bfa_2 + x_3 \bfa_3 = \bfb,\]

where we gave names to the columns. It’s not hard to find the solution \(\bfx=[1;\:-3;\:2]\). Hence

\[\bfa_1 - 3 \bfa_2 + 2\bfa_3 = \bfb.\]

6.3. MATLAB

If two vectors have the same size, then + and - work elementwise.

[1;2;3] + [9;8;7]
ans =

    '9.7.0.1296695 (R2019b) Update 4'
ans =

    10
    10
    10

For column vectors of different sizes, these operations cause errors.

[1;2;3;4] - [1;0;1]
Matrix dimensions must agree.


As a convenience, you can add or subtract a scalar to or from a vector, and the scalar will be used with each element.

[1;2;3] - 1i
ans =

  1.000000000000000 - 1.000000000000000i
  2.000000000000000 - 1.000000000000000i
  3.000000000000000 - 1.000000000000000i

The * operator does scalar multiplication.

-1*[4;3;2;1]
ans =

    -4
    -3
    -2
    -1

So we can express the linear system in (6.1) using a linear combination of column vectors:

A = [1 -1 -1; 3 -2 0; 1 -2 -1]    % coefficient matrix
b = [2;9;5]    % right-side vector
A =

     1    -1    -1
     3    -2     0
     1    -2    -1
b =

     2
     9
     5
1*A(:,1) - 3*A(:,2) + 2*A(:,3)
ans =

     2
     9
     5