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
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
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.
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
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,
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
Interpreting vector equalities elementwise, this is equivalent to
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.,
where we gave names to the columns. It’s not hard to find the solution \(\bfx=[1;\:-3;\:2]\). Hence
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