turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Blogs
- :
- JMP Blog
- :
- JMP, Three Ways

Article Options

- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content

Oct 6, 2008 10:06 AM
(473 views)

JMP, Three Ways

*This blog post was written by a blogger who is no longer at SAS*

My friends and co-workers know me as quite the little francophone. I travel to France as often as I can. I'm currently working on a master's degree on the subject at North Carolina State University. And I hoard every French newspaper and magazine that I get my hands on.

*Le Figaro* is a daily paper that adds a supplement, *Le Figaro Magazine* to its Saturday edition. There you find art news, columnists, and my favorite: games.

I'm consistently amazed at how the French make games simply out of things we consider dramatically un-fun. For example, one the games in the magazine relates to a letter from Blaise Pascal to his brother, where you have to (a) complete the letter with 16 given words; (b) correct 16 spelling or language errors; and (c) find 15 anomalies, anachronisms, or historical impossibilities.

One of the number games jumped out at me (pun intended). Here's the game I'm going to solve using JMP, in its original form.

[*Find the value of a ball of each color, knowing that the total of the balls on a line is always equal to 12]*

There are at least three ways to solve this-- probably more, if I thought about these things longer than it took me to eat a Happy Meal™ at Chez McDo's.

A very brute-force approach is to loop through all the possible colors (red = x, brown = y, black = z. blue = w) recognizing that they can't be less than zero nor more than 12. Here's a JMP script that does that : Four For loops that cycle each value from 0 to 12 in steps of 0.5. When it hits a result, it writes the result to the log.

For( x = 1, x <= 12, x+=0.5,

For( y = 1, y <= 12, y+=0.5,

For( z = 1, z <= 12, z+=0.5,

For( w = 1, w <= 12, w+=0.5,

If( 2*z + 2*w == 12,

If( z + 2*y + w == 12,

If( 3*y + 2*x == 12,

If( z + y + 4*w == 12,

If( z + w + 4*x == 12,

Show(x, y, z, w);

)

)

)

)

)

)

)

)

)

The results ? red = 1.5, brown = 3, black = 5. blue = 1

The next way is to recognize this as a least-squares problem. The value attached to the balls are the coefficients of a linear model, with the balls themselves serving as the data. So, I can make a JMP Data Table that holds the five rows and information on the four colored balls. To wit:

And using JMP's Fit Model window, I can get least-squares estimates on the balls. I'm using a no-intercept model because I know that the linear model should go through the origin.

Like that ("Bam!," I say to myself), I get the results and the answer to the puzzle.

If you took Algebra II in the past 40 years, you studied these things called matrices. Turns out they're actually useful. And if you don't recognize the puzzle in its least-squares sense, there's always this mathematical way of looking at it. Don't tell anyone, but they're actually the same approach: The math you see below is what's going on behind the scenes in JMP.

If you express the puzzle set-up using matrices (five rows representing the five rows of the puzzle), you can have the table itself represented like this (call it **A**)

[0 0 2 2

0 2 1 1

**A** = 2 3 0 0

0 1 1 4

4 0 1 1]

and the fact that these five conditions all sum to 12, represented as

[12

12

**C** = 12

12

12]

with a final matrix **b** representing the unknowns : the value of the balls.

[x

y

**b** = z

w]

To solve this, we simply have to start with

**Ab** = **C**

and get **b** alone on the left side of the equation. Typically, we'd do the simple thing of multiplying both sides by

**A**^{-1}, like this:

**A**^{-1}**Ab** = **A**^{-1}**C**

But dontcha know there's a problem. Since the puzzle has four variables and five rows, its matrix representation isn't square. So we can't just use an ordinary inverse. We can multiply A by its transpose to get a square matrix, although this still isn't invertible. Luckily, JMP has the *Moore-Penrose Generalized Inverse* function (which sounds better in italics, don't you think?). Using it, I can write a simple JMP script to assign the matrices and solve the problem:

A = [ 0 0 2 2, 0 2 1 1, 2 3 0 0, 0 1 1 4, 4 0 1 1];

C = [12, 12, 12, 12, 12];

ginverse(A`*A)*A`*C;

giving the result (with rounding error, I suppose in the delicate inversion process)

[1.5, 3, 5.00000000000001, 0.999999999999994]

The same answer. And if the rounding errors give you the heeby-jeebys, you can use JMP's Solve function instead.

A = [ 0 0 2 2, 0 2 1 1, 2 3 0 0, 0 1 1 4, 4 0 1 1];

C = [12, 12, 12, 12, 12];

solve((A`*A),A`*C);

1 Comment

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

Article Tags

- Tags:
- JMP - General