Thursday, July 22, 2010

Solving Balance Puzzles with Matrices

I grew up on puzzles and games. A typical Christmas or birthday present was a puzzle book, and our family spent a lot of quality time together when the Games magazine came in the mail. Being the math nerd that I am, I would sometimes use trial and error for the puzzles, but anything I could convert into equations to solve was a bonus. So, in a way, I was introduced to linear algebra long before I took the class in undergraduate school.

These puzzles are from Games magazine, and I hope they forgive me for forgetting the specific issue for a complete citation. They provide a nice visual from which systems of equations can be developed. These systems tend to be underdetermined; however, there are added restrictions on the solutions--they must be integers within a certain range. Thus, these underdetermined systems have a finite number of solutions instead of infinite, specifically because equations are over a range of integers, not over the reals.

Think of these puzzles like building a mobile, where the objects on each side must balance so that the horizontal bars stay horizontal under the following rules.
  • each shape represents a unique positive weight
  • each weight is an integer N such that 0 < N < 100
  • the right and left sides of each horizontal beam must balance
  • a piece hanging directly below the fulcrum does not affect the balance between the left and right arms
  • the size of the pieces has no relation to weight
  • these are exercises in balancing number values and do not take into account the distance from the fulcrum
Example 1: For the mobile at the top of the page, the total weight is 36. I have labelled each weight with a variable name, A, B and C. The total weight is 36:

A + 2B + 2C = 36.

The left arm must balance the right arm:

A + 2B = 2C or A + 2B - 2C = 0.

We create an augmented matrix for this system and row reduce:


While using a matrix was not necessary for this simple problem, it will be useful for the larger systems below. So, C = 9, B is a free variable, and the general solution is

(A, B, C) = (18 - 2B, B, 9)

with some restrictions on B. Since 0 < A < 100,

0 < 18 - 2B < 100,
-18 < -2B < 82, and
9 > B > -41.

Since B > 0, we find 0 < B < 9, and thus, there are 8 possible answers, one each for B = 1, 2, 3, 4, 5, 6, 7 and 8.

Questions: First, solve the puzzles below, then consider these questions.
  1. What would it take to create one of these puzzles? Can you create a puzzle that has a unique solution?
  2. How would it change if we did consider distance from the fulcrum? Would it still be a linear system? If so, create a simple puzzle where distance is considered.
  3. What determines how many equations are required? For instance, in Puzzle 1 below how many equations are described?  Don't forget that each horizontal bar needs to balance, not just the top one.
Puzzle 1. The total weight is 80. Only one shape weighs more than 9 and the cube is 1 unit heavier than the octahedron.

Puzzle 2. The total weight is 54. The three arms are equal in weight.

Puzzle 3. The total weight is 180. The three arms are equal in weight.
---------------------------------------------
A later post - December 31, 2011

I found a link with more balance puzzles.  These are different looking, but the idea is the same.  In this case you need to take the distance each weight is offset from the balance point into account.  For example, a weight of 2 units that is 1 unit from the fulcrum will balance a weight of 1 unit that is 2 units from the fulcrum.  Can you use linear algebra to solve these puzzles?  If so, how?

Here is another page of balance puzzles.http://battleships.free.fr/balance_i.pdf

Wednesday, July 21, 2010

Gould Index - Matrix Application to Geography

Figure 1:
Map of 7 towns connected by 9 roads
The Gould Index has a nice visual that students enjoy, but it also is used to answer a question (important for applications) and can lead to discussions of the PageRank function used by Google.  Much of this post is adapted from a paper by Patrick Carlson, one of my linear algebra students.  He was interested in networks, and did a great job of understanding and explaining the general nature of the mathematics behind the Gould Index.

Example 1:  Consider a graph that respresents a set of towns (the vertices) and the travel routes between those towns (the edges) like in Figure 1.  Historical geographers were interested in which town would become the trade center for this region.  Now, you are saying to yourself that this is obvious in this picture, but let's see if some mathematics can come to the same result we do.  If so, then let's apply it to a less obvious graph.

Figure 2:  Adjacency matrix for Figure 1
First, make the adjacency matrix for the graph (Figure 2).  Place a 1 in position (U, V) when U and V have a travel route between them and a 0 in the (W, T) position when there is no direct travel route between W and T.  We will also place a 1 in each diagonal position, such as (Q, Q) as if there was a loop there, since clearly if you are in Town Q you can obviously get to Town Q.  Notice that this matrix is symmetric, which will make some of the mathematics work but is also a way of checking to make sure you created the matrix correctly.

Now, here's the math.  Find the eigenvalues of this matrix and find the largest one in absolute value.  We get eigenvalues (2, 0, 4, -1, 0, 2, 0).  The third one, 4, has the largest absolute value.  Now, find the eigenvector associated with the eigenvalue of 4: 
(0.3162, 0.3162, 0.3162, 0.3162, 0.6325, 0.3162, 0.3162).  Normalize this vector by dividing by the sum of the entries, 2.5297, to get

(Q, R, S, T, U, V, W) =
(0.125, 0.125, 0.125, 0.125, 0.25, 1.25, 1.25).

These are the Gould indices of each of the vertices, which describes how strongly each vertex is connected to the other vertices.  As we knew, U is the most strongly connected with a Gould Index of 0.25, and the others are equally connected because of the symmetry of the graph.

Figure 3:  Another graph
Example 2:  What if we looked at a graph that more realistically represents a set of towns, which may have rivers, mountains or other geographical features preventing travel routes between towns, as in the graph in Figure 3.  In this case, would G be the trade center because it is directly connected to the most towns, or would it be C because between C and every other town is at most one town?  Create the adjacency matrix (with ones along the diagonal), and find the eigenvalues which are
(4.01, -1.37, 1.71, 1, -0.37, -0.56, 2.58, 1, 1).  The first is the largest and the eigenvector associated with it is
(0.2941, 0.4097, 0.5023, 0.3249, 0.3026, 0.1359, 0.4770, 0.1583, 0.1583) and the sum of the entries is 2.7631.  Normalize by dividing by the sum of the entries to get the Gould indices:

(A, B, C, D, E, F, G, H, I) =
(0.1064, 0.1482, 0.1818, 0.1176, 0.1095, 0.0492, 0.1726, 0.0573, 0.0573).

Of course, we can see which Gould index will be largest before normalizing, but there are other applications for which normalized values of the eigenvector will have meaning, so it doesn't hurt to get used to normalizing.  We see that C has the largest Gould Index with 0.18, but G comes in a close second with 0.17.  In this calculation, more value is given to vertices that are closer to others along paths of length more than 1 than to vertices that connect with a path of length 1 to more vertices.  Note that I and H have the same smallest index, as expected.

What is going on?  Although we have some empirical evidence that the Gould index does what is expected, what is the theory behind it?  A version of the Perron-Frebonius Theorem says that if a matrix is nonnegative and primitive, then there will be a real eigenvector that dominates the others in absolute value, it will have multiplicity 1, and the eigenvector associated with it will be real and positive [C].  The adjacency matrices above are nonnegative since all the entries are 0 or 1, and for the two above I checked that they are primitive; in Example 1, the square of the matrix was positive, and in Example 2, it took the fourth power of the matrix before getting a positive matrix.  We don't use the adjacency A, per se, but instead we use B = A + I when we put 1s in the diagonal.  Try a bipartite graph and see that the powers of A will never be positive, and thus A is not primitive in that case, but B = A + I will be.

Straffin discusses the how of the Gould index in more detail, and discusses its connection to finding the dominant team in a round robin tournament and measuring the importance in nodes in a communications network.  He has a significant list of references to examples of this method along with references to other uses of linear algebra and graphs in geography.  This method is a beginning for the mathematics behind the algorithm used in PageRank used by Google; however, the adjacency matrix (with 1s on the diagonal) is not primitive and is too large to find the eigenvalues and eigenvectors directly.  But that is a discussion for another day.

Questions:  When this model is applied to historical travel routes, the trade center predicted by the model does not always match the trade center that develops.  Non-geographical issues may be involved here, such as politics and wealth, but it is clear that the model does not take into account the time of travel.  Maybe there is a train between two towns for quick access, but two others are only accessible on foot through a mountain pass.  Can we change the results for Example 2 above by considering a weighted graph instead?  If so, should we weight with time of travel or the reciprocal of time of travel?  How would the diagonal elements be weighted?

The nth power of an adjacency graph gives the number of paths of length n between vertices x and y in the (x, y) position.  Could this be used in someway to predict the trade center?

In Gould's article is a study of the travel routes of Uganda in 1921 and 1935, and Straffin's paper has references to other studies.  Can you reproduce these results?

References:

[C] Hal Caswell, Matrix Popoulation Models, Sinauer, 1989.

[G] P. R. Gould, "On the geographical interpretation of eigenvectors,"  Transactions of the Institute of British Geographers, No. 42 (Dec., 1967), pp. 53-86.

[S] Phillip D. Straffin, "Linear Algebra in Geography: Eigenvectors of Networks," Mathematics Magazine, Vol. 53, No. 5 (Nov., 1980), pp. 269-276.

Tuesday, July 20, 2010

Solving Number Puzzles with Matrices

The Discovery Education Classroom Resources has some great classroom tools. One of my favorites is Puzzle Master. It allows you to create custom puzzles like word searches or cryptograms. I used the Number Blocks puzzle creator for a linear algebra project on overdetermined and underdetermined systems of equations.

An example of a number block puzzle created using Puzzle Master is given above. The numbers to the right an bottom are the sums of various rows, colums and diagonals of the 3-by-3 grid of numbers. The main diagonal sums to 14; the off diagonal sums to 17. The sum of each row is to the right, and the sum of the columns is at the bottom. In this example, there are 6 unknowns and 8 equations, and so this is an overdetermined but consistent system. Puzzle Master will not create a puzzle that does not have a solution.



Questions:  We can create a system of equations for this number puzzle as shown above. There are a lot of questions that can be asked about these number puzzles and the systems that can solve them.
  • Given an n-by-n grid of numbers, how many equations are needed to solve the puzzle?
  • What determines how many unknows there are?
  • Given an n-by-n grid of numbers, how many unknowns must there be for the system to be overdetermined? Underdetermined? Square?
  • Are there equations in the system below that can be removed so that the system is not overdetermined but has an equivalent solution? If so, how many and which equations can be removed.
  • If a number puzzle is underdetermined, how can a solution be found?
  • Is it possible for a number puzzle to have exactly two different solutions? Exactly five different solutions? Explain.
  • Is it possible for a number puzzle to have infinitely many solutions? Describe a puzzle for which this would be true, and explain how to describe the infinitely many solutions.
  • Puzzle Master won't create a puzzle with no solution, but can you create a puzzle that has no solution and is overdetermined? Underdetermined? Square?
  • Create a puzzle using Puzzle Master that would have infinitely many solutions. Can you make a conjecture on how Puzzle Master chose the solution that it gives?