Download feature - EE Times
Transcript
programmer’s toolbox BY Jack W. Crenshaw Who needs matrices? N in John’s hand, one in Mary’s. Maybe that one was too easy. Try this one: ow that we’ve completed the vector class, it’s time to move on to the matrix (plural: matrices). In the worlds of math, engineering, and physics, it’s the matrix that separates the men from the boys, the women from the girls, the heroes from the goats. If you can toss around matrices as you might a Frisbee, you’re one of the superheroes. If not, you’re on the sidelines, watching. Hint: if you say “matricee” as the singular of matrices, you’re not even in the stadium. I want to show you the C++ code that lets you toss around matrix-vector expressions, but at this point, I think it’s much more important for me to give you the moIf tivation. • • • Why do I need a matrix? What good are they? How does matrix algebra help me? 1. Between them, John, Mary, and Sue have $1.00. 2. Sue has 40 cents more than John. 3. Sue has as much money as John and Mary together. Not so obvious this time, is it? As you may remember, the trick is to write down equations that capture the information in the problem. To keep it brief, let J, M, and S represent the money each child has. Fact #1 says: J+M+S=100 you can toss around matrices as you might a Frisbee, you’re one of the superheroes. If not, you’re on the sidelines, watching. JOHN, MARY, ET AL. Remember those word problems that used to drive you crazy in high school algebra? Here’s an easy one, for old times’ sake: 1. Between them, John and Mary have $1.00 2. John has three times as much money as Mary. 3. How much money does each child have? Now, if you’ve been thinking outside the box, instead of having your eyes glaze over at the phrase “word problem,” you already know the answer. Think three quarters Jack Crenshaw is a senior software engineer at General Dynamics and the author of Math Toolkit for Real-Time Programming, from CMP Books. He holds a PhD in physics from Auburn University. E-mail him at [email protected]. (1) The next one says: S=J+40 (2) And finally: S=J+M (3) Now we need to solve for the individual values. As you may remember, the trick is to manipulate the equations so that we isolate a single variable, one at a time. For example, Equation 2 gives us a value for S. Let’s substitute it into the other two equations, to get: J+M+(J+40)=100 J+40=J+M (4) A little simplifying gives: 2J+M=60 (5) 40=M (6) Luckily, the terms in J in the last equation cancelled each other, isolating the value of M. We now know that Mary has 40 cents. Substituting that value into Equation 5 gives: www.embedded.com | embedded systems design | DECEMBER 2007 11