Saturday, January 10, 2015

How to solve simple linear equations

It may come as a surprise to some people, but in high school this guy was not good at math at all. The point is that while I'm pretty good in designing algorithms, my calculations are always a bit off. Nowadays that's not much of a problem: you just grab a calculator or (even better) a computer, but the school system in those days was focused on doing it by hand. It took ages to calculate and plot a graph manually, which in my case was already completely clouded by tiny calculation errors. On top of that, it was too time consuming to make only one graph, let alone a whole series of them, so I couldn't get a feel of the dynamics involved.

Fortunately, that all changed when the computer came in. And then I started to understand all those things that had eluded me for years. Like solving linear equations.

There are several methods to solve them. One involves eliminating terms by applying the same operation at both sides of the equation. When I was a youngster, that only resulted in more complex equations than the ones I started with. Sometimes it didn't even resemble the original equation. The other one is switching terms from one side of the equation to the other side, while changing the sign. That one is already much better and the foundation of the method I will be presenting here.

You only need to fill in a simple table and then do some additions. If you manage to do that, you're left with one single division - and that's it. Let's take the following equation:
2x + 2 - 76 = -12x + 10
The table is a no-brainer. Make two columns and name the first one "+x" and the other one "-n". Got that? Note that even if you don't get the signs right, it's not a problem. Now, fill in the numbers associated with "x" in the left column and all others in the right column. If a number is on the right part of a subtraction, add a minus sign, e.g. "12 - 4x", will result in "12" in the right column and "-4" in the left column.

Once you hit the "equals" sign, subtotal both columns. Now write two new labels, "-x" in the left column and "+n" in the right column. Then continue until you're done. So now we've got something like this:

Now negate the number in the top right column and the bottom left column and add the subtotals in both columns:
(2 + 12)x = 74 + 10 =>
14x = 84
I promised you, you would be left with one single division. I didn't lie, here it is:
x = 84/14 =>
x = 6
That's it! It's so simple even a computer can do it. And that's exactly what I did in just 40 lines of Forth code - and that includes the entire parser:

Sure, you always risk making some errors while adding or dividing, but apart from that it's pretty bulletproof. So if your kid is eluded by linear equations, give it a try! Just make sure he (or she) understands that equal signs ("+ +" or "- -") make up a positive number, while unequal signs ("+ -" or "- +") result in a negative number.

But I'm sure he (or she) will manage that - since I mastered that one too forty years ago! ;-)

No comments: