Matrix and vector: working out the cost of a purchase from several suppliers
In the textbook: Ch. 7 Matrixalgebra
Many business calculations repeat the same step: multiply price by quantity and add it all up. That is how you get the bill for a purchase, the wage by the hour, the raw material for an order. While there are few numbers, a pen is enough. This article is about the notation that helps when there are many: the vector and the matrix.
Imagine a bakery that buys flour and butter. Every week it decides which of two suppliers to order from. One has cheaper flour, the other cheaper butter, and the price list does not tell you at once who is cheaper: it depends on how much of each the bakery takes.
Flour and butter are counted in units, ME (from German Mengeneinheit, one unit is 100 g). Prices per unit, in €:
| Price per unit in € | flour | butter |
|---|---|---|
| Supplier A | 2 | 8 |
| Supplier B | 3 | 6 |
The purchase: 30 units of flour and 10 units of butter.
Which supplier is cheaper, and by how much?
Here you can find the answer without any new words: four multiplications and two additions. But a real bakery has about ten raw materials and five suppliers, and then it is fifty multiplications. In such a sum it is easy to take the price of butter instead of flour or to miss one item.
The vector and the matrix give every number a fixed place, and then each price meets its own quantity by itself. The article gets there step by step:
- The purchase becomes a vector, a list of numbers in which every number has its place.
- The prices of the two suppliers become a matrix.
- A single multiplication of the matrix by the vector answers who is cheaper.
In the exam this opens the chapter on matrix algebra. On average that chapter gives two tasks out of twenty.
The vector: a list of numbers, each in its place
Two numbers describe the purchase: 30 units of flour and 10 units of butter. If we agree that flour always comes first and butter second, the labels can be dropped, and the purchase becomes a column of numbers:
Such an ordered list of numbers is called a vector (German: Vektor). Its numbers are called components: is the first component (flour), the second (butter). A vector has as many components as there are numbers in the brackets, and this count is called the length of the vector: has length 2. Vectors are named with small letters.
What a component means is fixed by its place, not by its size. The same numbers in another order make a different vector:
On the right are 10 units of flour and 30 units of butter, a completely different purchase. So two vectors are equal only if they have the same length and the same number stands in every place.
Supplier A's prices are a vector too: 2 € for flour and 8 € for butter, in the same order. It is convenient to write it as a row, so that in the product the row of prices meets the column of quantities:
So a vector has two ways of being written:
- column vector: the numbers one below the other, like the purchase ;
- row vector: the numbers side by side, like the prices .
The numbers may be the same, but the rules tell the two apart: in the product that works out the cost of the purchase below, the row of prices stands on the left and the column of quantities on the right. How to turn one into the other is shown below, in the section on transposing.
Sum of vectors and a multiple of a vector
Today the bakery bought , yesterday : 15 units of flour and 5 units of butter. How much over both days? Flour is added to flour and butter to butter, that is, the components in the same places:
If the purchase for a holiday is three times the usual one, every component is multiplied by 3:
This gives two rules with one reason: every place holds its own good.
- Vectors of the same length are added place by place: first component to first, second to second.
- A vector is multiplied by an ordinary number by multiplying every component.
In matrix algebra an ordinary number is called a scalar. A scalar is a single number, not a list of numbers like a vector: is a scalar, is a vector. The word makes it clear at once where a calculation has one number and where it has a list.
Vectors of different lengths are not added: the extra component has no partner, and the sum would mean nothing. A column and a row are not added either, even of the same length: they are different ways of writing, and the sum rule needs the same one.
The scalar product: what a purchase costs
Start with supplier A. Flour: 2 € per unit, 30 units, €. Butter: €. Together €. Written with vectors, the prices stand as a row, the quantities as a column, and each price meets its own quantity:
This is exactly how the scalar product (German: Skalarprodukt) of a row and a column of the same length is defined: first component times first, second times second, add all the products. The name comes from the result: two vectors give one number, a scalar, not a new vector. The rule adds nothing to the calculation of the purchase; it is that calculation, written once for any prices and quantities. The same calculation shows its properties:
- the result is a single number: the money for the whole purchase, not per good;
- the lengths must match: every price needs its quantity;
- the pairs can be added in any order, as long as each price and its quantity share a place.
A workshop pays three workers 20, 30 and 10 € an hour; in one week they worked 8, 5 and 3 hours. The wage bill:
and , both with 3 components, the workers in the same order.
, , .
€ for the week.
Why does the first worker's rate meet exactly the first worker's hours? Because both numbers stand in the first place, and the place means the worker.
Another day: the bakery buys 20 units of flour and 15 units of butter at supplier A's prices. The flour costs €. The butter costs €, the whole purchase €.
Trap: stopping at the first product, or not adding. In a hurry it is easy to write 40 (flour only) or leave the pair . Those are the costs per good, but the question is about the whole purchase. Check: the scalar product gives one number, with as many terms as the vector has components.
Your turn1 of 4
The prices of three raw materials are € per unit, the purchase is units in the same order. What does the purchase cost?
Transposing a vector: the column becomes a row
Above we wrote the prices as a row straight away. Vectors are usually stored as columns, though, prices included: . For the scalar product the column is laid down as a row, so that a row meets a column. This step is called transposing (German: transponieren) and is written with a superscript :
The components and their order stay as they were: the column is only laid down as a row. A row transposed once more becomes a column again, so .
Now the price of the purchase is written briefly:
Here:
- : the number of goods;
- : the price of good ;
- : the quantity of good .
For our purchase €. Since the two factors of each pair can be swapped, : 'prices times quantities' and 'quantities times prices' give the same number. Exam statements almost always write the scalar product of two columns and as .
Trap: flipping while transposing. Sometimes the column is laid into the row from right to left, . Then the flour price takes the butter's place, and gives instead of 140. Check: the top component of the column becomes the left component of the row.
Your turn2 of 4
Given are the column vectors and . Which statement is true?
The matrix: several vectors in one table
Now the second supplier. A's price list is the vector , B's the vector . Put them one below the other, label the rows with the suppliers and the columns with the goods:
Such a table of numbers in round brackets is called a matrix (German: Matrix) and named with a capital letter:
It is read in two ways:
- a row holds one supplier's prices for all goods: the row 'supplier A', , is that supplier's price list;
- a column holds the prices of one good at all suppliers: the column 'flour', , compares flour at A and at B.
The size of a matrix is written “rows × columns”: has two rows and two columns, it is a matrix. If a matrix has as many rows as columns, it is called square.
The number where a row and a column cross is called an element of the matrix. The first index is the row number, the second the column number:
- : row 2 'supplier B', column 1 'flour', the highlighted cell in the figure of prices at the start of this section;
- : row 1 'supplier A', column 2 'butter'.
In general the element of a matrix in row and column is written .
Trap: swapping the indices. and stand in different places. The row always comes first, then the column, as in the size “rows × columns”. In the exam it helps to say it: “: second row, first column”.
Sum and multiple work as for vectors:
- two matrices of the same size are added element by element, the number in place plus the number in the same place;
- a number multiplies every element.
Example: plus a matrix of the same size, and times 5:
gives the prices of a pack of 5 units. Matrices of different sizes are not added: some elements would have no partner.
Matrix times vector: row times column for every row
Now let us answer the whole question from the start. Purchase from A: row A times the purchase, €. Purchase from B: row B times the same purchase, €. Both bills came from the same action, once per row. This action is called multiplying a matrix by a vector:
Component of the result is the scalar product of row of the matrix with the vector.
- Why the row: a row holds one supplier's price list, and a bill comes from one price list.
- Why not the column: the column 'flour' holds the prices of different suppliers, and multiplying it by the purchase would mean adding flour at A's price to butter at B's price.
Step by step, one component of the result per step:
2 · 30 + 8 · 10 = 140
The row times the column : €. This is the first component of the result.
The same reasoning says when the product exists. A row has one price per good, the vector one quantity per good, so the length of a row of the matrix must equal the length of the vector. The result has as many components as the matrix has rows: one bill per supplier. A matrix ( rows and columns) times a vector of length gives a vector of length .
A loaf of bread needs 5 ME of flour and 1 ME of butter, a pie 3 ME of flour and 2 ME of butter. The rows are labelled with raw materials, the columns with products: . Order: 20 loaves and 10 pies, .
ME: flour per loaf times the number of loaves plus flour per pie times the number of pies.
ME. Together .
Why does the result have two components, although there are also two products? Because it has as many components as rows, that is, raw materials; the products 'disappear' inside the sums.
The order reversed. The same , an order of 10 loaves and 20 pies. Flour: ME. How much butter is needed?
Trap: a column instead of a row. The first column of , , is just as much in view, and it is easy to multiply it by the order: . This sum mixes flour per loaf times loaves with butter per loaf times pies and counts nothing; the 110 equals the flour answer above only by coincidence, and the order is still wrong. Check by the labels: one sum holds one raw material and all the products.
Your turn3 of 4
The matrix gives the use of materials A and B (rows) for products 1, 2, 3 (columns). Order . How much material is needed, ?
Transposing a matrix: rows become columns
The matrix from the bread-and-pie example in the section above is labelled this way: rows raw materials, columns products. Sometimes the same table has to be read by product: the row 'bread' holding everything a loaf needs. For that the rows are made into columns. On the left , on the right the same matrix after transposing:
- Rows into columns: the first row of , , became the first column of , the second row the second column.
- Places of the elements: no number is lost or changed, only their places change. The element in row and column of stands in in row and column : butter for bread sits in at place and in at place , in the row 'bread' and the column 'butter'.
For a non-square matrix the size changes too: becomes .
- Transposing twice gives back the original matrix: .
- A vector is a matrix too: a column vector of length is an matrix, a row vector of length is a matrix. That is why transposing turns a column into a row.
Look at the matrix : the same 3 stands top right and bottom left, so it does not change when transposed. Such a square matrix, , is called symmetric: its numbers are mirrored across the main diagonal, the line from top left to bottom right. is not symmetric: but . Symmetric matrices come up in exam tasks on quadratic forms, that is, on expressions of the form : a polynomial of squares and pairwise products of the variables. How to write them with a matrix is shown in “Matrix multiplication: why row times column”.
Trap: forgetting that the size changes too. In statements about sizes it is easy to take for a matrix of the same size as . Check: has as many rows as has columns.
Your turn4 of 4
. Which statement is true?
At a glance: vector, matrix and row times column
The topic in a minute
- Vector: an ordered list of numbers, every place has its meaning; . Vectors are added place by place, a number multiplies every component. Trap: a column and a row are not added.
- Scalar product: , one number, for example the price of a purchase. Trap: forgetting to add, or taking only the first term.
- Transposing a vector: the column is laid down as a row, the order stays; . Trap: reversing the order.
- Matrix: size 'rows × columns', the element stands in row and column . Trap: mixing up and .
- Matrix times vector: component is row times the vector; the row length equals the length of the vector, the result has as many components as the matrix has rows. Trap: multiplying a column instead of a row.
- Transposing a matrix: row becomes column , the size becomes . Trap: assuming the size stays the same.
If the matrix is multiplied not by one vector but by another matrix, that is, by several vectors at once, the rule 'row times column' repeats for each column. This is the next article: 'Matrix multiplication: why row times column'.
Was this article helpful?