The Beginner's Page
Translating Equations
Richard Mansfield
Assistant Editor
Computers are excellent teachers. They have infinite patience; provide instant pass-fail corrections of your efforts; permit you to work at your own speed on topics of your choice; and they don't (as yet) become sarcastic when you blunder.
Many people, myself included, decided long ago that math was not their forté. This decision is usually made at age fifteen or thereabout and follows a series of mishaps in the educational system. Algebra is often the final blow.
Computers cure this math phobia rather quickly. The machine does all of the tiresome calculations for you. You are free to float above and observe relationships, discover patterns, even construct visual analogs where you can watch the numbers transform on the screen.
Algebraic Equations, BASIC Assignments
After you get over the initial surprise that, in BASIC, A = A + 1 makes perfect sense — you will find that the meaning of variable becomes quite clear. A variable is simply a "name" written on a "box." You might have a box in your house marked "BILLS." Each month you pay all the bills and the box is empty (BILLS = 0). Then, when each bill comes in, you put it in the box (BILLS = BILLS + 1). This is not an algebraic equation, it is an assignment of a certain number (BILLS + 1) to the variable BILLS.
In algebra, an equation is expected to balance: whatever is on the left side of the equals sign is presumed to be equal to the right side. In BASIC, the variable on the left side is being defined by whatever is on the right side. In earlier versions of BASIC, you had to type: LET BILLS = BILLS + 1 to show that you were assigning a new value to BILLS, not stating an equality. One other thing: computers allow you to use meaningful, easily recognized variable names such as BILLS, or INTEREST, or DOLLARS. This, too, can be an advantage over the traditional single-letter variable names of algebra.
In any case, much useful math becomes clear after you work a while on your computer. For example, let's put this on our computer (to see how easy it really is):
F = D(1 + I/C)C*Y or FINALAMOUNT = DOLLARS(1 + INTEREST/COMPOUNDING)COMPOUNDING * YEARS
This formula will let you know how much money you'll end up with after making an investment. It can also tell you how much your house will be worth if it is going up in value a certain amount each year or show the effects of inflation. It's a handy formula, but to the "non-mathematical" it looks forbidding. On the computer, it's a snap. Just use INPUT statements to ask for each of the variables and then, (in line 100), duplicate the formula using BASIC symbols:
10 PRINT "WHAT IS THE ORIGINAL AMOUNT IN VESTED"; 20 INPUT DOLLARS 30 PRINT "HOW MANY YEARS BEFORE YOU CASH IN THE INVESTMENT"; 40 INPUT YEARS 50 PRINT "WHAT IS THE ANNUAL INTEREST RATE" 60 INPUT ITEREST 70 PRINT "HOW MANY TIMES PER YEAR IS IT COMPOUNDED"; 80 INPUT COMPOUNDING 90 ITEREST = ITEREST/COMPOUNDING/100 : REM MAKE ITEREST INTO A DECIMAL FRACTION 100 FINALAMOUNT = DOLLARS * (1 + ITEREST) ↑ (COMPOUNDING * YEARS) 110 PRINT "AT THE END OF "; YEARS; "YEARS YOU WILL HAVE $"; FINALAMOUNT
Notice that we spell it iterest to avoid using one of BASIC's special, reserved words INT. It is also necessary to enclose compounding multiplied by years in parentheses to show that this is to be calculated before the other part is raised to a power. The order in which calculations are performed is, of course, quite important and you should familiarize yourself with what your computer's manual instructs on this subject. When in doubt, use parentheses — they will always cause whatever is within them to be figured first.
The Universal Rounding Engine
Programs can often be refined, customized, and made to perform new functions with surprisingly little effort. This same program could include a function to round off the finalamount to the nearest penny by adding this line:
105 FINALAMOUNT = INT(FINALAMOUNT * 100 + .5)/100
What would this Universal Rounding Engine do if you changed the two 100's to 1000's...or 10's? We can also easily adjust the program to predict how much your house will be worth in ten years, given a rise in value of, say, six percent per year. The math stays the same, all we need to do is change the prompts (the questions the computer asks). Line 10 should read: "HOW MUCH IS YOUR HOUSE WORTH NOW?" Line 30: "HOW MANY YEARS DO YOU WANT TO PROJECT?" Line 50: "HOW MUCH IS IT INCREASING IN VALUE EACH YEAR?" Line 70: COMPOUNDING = 1. In line 110, change "YOU WILL HAVE" to "YOUR HOUSE WILL BE WORTH."
To work with inflation projections, make the following replacements:
10 "WHAT IS THE COST OF THE ITEM TODAY"; 50 "WHAT IS THE ANNUAL INFLATION RATE"; 70 COMPOUNDING = 1 110 [change YOU WILL HAVE to: IT WILL COST]
When creating such useful variations to simple programs, you are, at the same time, learning new things about mathematical relationships. It's fun and therefore painless. As an experiment with the Inflation version of this program, try adding: 5 THISYEAR = 1982 so the computer will know what year it is. Then, using the information gathered in line 30, have the computer give its answer (in line 110) in the form: BY THE YEAR 1985 IT WILL COST $(whatever).
All of this is worlds away from that algebra class where some of us mistakenly decided that mathematics, when it wasn't impossibly obscure, was tedious. By pushing and shaping programs, you can see and feel numbers, their interactions, their beauty.