# Age and wisdom

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

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.

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"

INPUT "Initial Guess: ", x

INPUT "Stopping Criterion (% Relative Error): ", EC

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 "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.