Age and wisdom

Posted on March 18, 2008 by Steve

REM Rootfinder Program
REM Finds Roots using Newton-Raphson method of equation
REM f(x) = 9.34 - 21.97x + 16.3x^2 - 3.704x^3

CLS
PRINT "Use Rootfinder to locate roots of equation"
PRINT "f(x) = 9.34 - 21.97x + 16.3x^2 - 3.704x^3"
PRINT
INPUT "Initial Guess: ", x
INPUT "Stopping Criterion (% Relative Error): ", EC
PRINT

ITER = 0
ET = 1 + EC
DEF FNG (x) = x - (9.34 - 21.97 * x + 16.3 * x ^ 2 - 3.704 * x ^ 3) / (-21.97 + 32.6 * x - 11.112 * x ^ 2)

WHILE (ET > EC) AND (I < 100)
ITER = ITER + 1
Y = FNG(x)
IF (Y <> 0) THEN ET = ABS((Y - x) / Y) * 100
PRINT "Iteration: "; ITER, "Estimate: " Y, "Error: "; ET
x = Y
WEND

PRINT
PRINT "Function value at last iteration:"
PRINT "x = "; x; ", f(x) = "; 9.34 - 21.97 * x + 16.3 * x ^ 2 - 3.704 * x ^ 3

This was a homework assignment for my Numerical Methods class dated 8 April 1993. I found the dot-matrix printout while sorting through papers in the basement. The professor wasn't too impressed; he gave me a score of 50/75. He didn't catch the undeclared variable I in the WHILE condition, but circled "IF (Y <> 0)" and wrote "Can you explain what is being checked here?" Seems clear to me, though an ELSE statement would have been a nice touch. He also scribbled "Try both stopping criteria?" and, after checking my result of 0.9535033 in 7 iterations, asked "largest root?" (it wasn't).

One reason I held on to a bunch of school papers was so I could test myself to see if I would gradually get stupider after completing my formal education. I am happy to report that there has not been a precipitous decline. In the copy of the PSAT test that I saved from high school, I couldn't find a single problem in the math section that was hard enough to merit being worked out. Meanwhile, I recently solved my 100th problem on Project Euler, and hope to knock off a few more before dementia sets in.
« Prev itemNext item »

Comments

Posted by Tony | March 19, 2008 | 08:50:38

Steve,

You're way ahead of me, not only in your Project Euler achievements, but also in not having experienced a precipitous decline in your mathematical ability. I am, however, way ahead of you in that god help me if I find a single paper from college, much less high school, still sitting around my house :)

Cheers,
T.
------------------

Posted by Steve | March 19, 2008 | 18:10:22

Yes, I suppose you have me beat there. Even with aggressive culling, the papers that insist on their future usefulness stack up faster than they can be disposed of. An advantage of digital media then, that files take up less space and tend to dissolve into oblivion without any help.
------------------

Leave comment

You must be logged in as a member to add comment to this blog