Pursuing a degree in Computer Science is much different from learning to program as a hobby.
Now, I’m forced into revisiting math.
Oh yes, my best enemy, Mathematics.
I can point fingers at everyone else all day, but it won’t solve my problems.
Let’s look at at least one practical mathematics application.
What is a matrix?
A matrix is simply a series of numbers in a rectangular form. By itself, it seems like a very useless way of representing a group of numbers. However, there is nothing in advanced mathematics that is immediately useful like matrices, as you will soon learn!
Here is an example of a matrix:
What is an augmented, coefficient matrix?
A coefficient matrix is simply a matrix whose numbers represent coefficients of variables. Consider the following:
x sub 1 through 4 can represent any number.
It’s not necessarily important to us because they are placeholders. Instead, we take the coefficient of each placeholder and place it into a matrix. The coefficients are significant because they are known. We can find simpler, equivalent coefficients to create simpler, equivalent equations for our problems.
An augmented, coefficient matrix sounds complicated but is really very simple. An augmented matrix means that it is in fact an equation. The vertical line next to the 0 represents the equals sign in the original problem. We will omit this in the future.
This is too much mathematical jargon for me, so you just be tired by now. Let’s look at a real application to make this practical.
How do you balance a chemical equation with an augmented, coefficient matrix?
Here’s a simple, unbalanced chemical equation for you:
Identify the rows and columns
In our case, we will use vectors at first to represent the chemical equation. Each column will represent a part of the chemical equation, whether it is reagent or product is of no concern to us. Each row will represent how many of each atom there is in that particular part of the chemical equation.
Let’s translate this chemical equation into a series of vectors.
Note that these two equations are equivalent. However, the second one is the most useful to us for finding a solution. It’s necessary to move the products to the left, producing a vector of zeroes on the right.
You’ll quickly realize that -1 and -3 represents that there are 1 Fe atoms and 3 Cl atoms in that part of the chemical equation. It is negative, because it is a product.
Plug in the values
Using your handy dandy calculator, enter the following matrix:
Bring to Reduced Row Echelon Form (RREF)
Use matrix operations to bring the former matrix to RREF:
Present the solution as a balanced equation
So, what the hell does this solution mean? We’ll need to do some additional processing to make this useful. Remember that this is a coefficient matrix and that the coefficients are ignorant of what they are multiplied by.
The first row means: 1×1 + 0x2 – 1×3 = 0. We want to find out what x1 is (or the coefficient for Fe). Solving for x1 means x1 = 0 – 0x2 – 1×3. Or, x1 = -1×3.
Completing this for the rest of the coefficients produces the following:
Notice that I made x3 = -2, which is the smallest number that makes the other coefficients whole numbers.
We can finally write the solution as:
Wow, that was tougher than it needed to be
Maybe for now. However, you will find that longer equations are easier to solve via this method. Here’s an example done for you:
Using Matrices for Network Flow Diagrams
Ever wanted to find out the rate of flow of traffic in an intersection? Here’s a nifty way!
Understand what’s going on here? No? Good, me neither. Wait, nope. Looks like we have a simple intersection, A, of two one way streets.
In the North direction, we have a variable going South.
In the West, we have a constant, 10, going East.
West and South lead outwards, with one a constant and the other a variable.
Write a row for every intersection with the in and the out flows separated. The in and the out will always equal one another in this type of system.
You must solve for the constants, essentially. You always want the constants on the right. After writing the resultant linear equation as a matrix, you can see that it is already in RREF. After identifying the free variables (x2) and describing the non-free variables (x1) with the free variables and the constants (x1 = 10 + x2), you have the general flow pattern of the system.
In otherwords, if we observe 30 people come through x2, then x1 must equal 40.
Like the chemistry problem, this can get a lot more complicated.
Here’s some additional examples!
Problem-Solving with Matrices in Java
This class will RREF a matrix. It is on Rosetta Code as well. This requires Apache Commons 2.2. It’s a simple install.
Under Construction, ladies and gents 🙂 I’ll be building more.
For anyone interested, here’s the LaTeX file I used to create the above images.