RootMinMax for the HP-42S

By Namir Shammas

RootMinMax is a program that finds the roots or the optimum points of a function. The program uses a straightforward version of Newton's algorithm to find the root of a function or it's first derivative.

To find the root, and,

To find a minima or maxima. The program uses the following approximation to calculate the first and second derivatives:

where

- To start the program execute XEQ "RTMIN"
- The program prompts you for the name of the function in Alpha mode.
- To find the root, execute XEQ B and respond to the prompts for the guess, maximum number of iterations, and tolerance. The program will iterate and display the root, function value at the root, and the number of iterations.
- To find the minimum or maximum, execute XEQ C and respond to the prompts for the guess, maximum number of iterations, and tolerance. The program will iterate and display the min/max value, function value, slope value, and second derivative at the located value, and the number of iterations. When the second derivative is positive, the point is a minimum. By contrast, when the second derivative is positive, the point is a maximum.
- To select a new function execute XEQ A and enter the new function name.

The label AA implements the following sample function:

f(x) = exp(x) - 3 * x^2

Given f(x) find the following:

- The root new x = 5.
- The minima/maxima near x = 4

FX NAME?

AA

RUN

XEQ B

ROOT GUESS?

5.00000 RUN

MAX ITER?

55.00000 RUN

TOLR?

1E-7 RUN

R01= 5.00000

R01= 4.40206

R01= 3.99213

R01= 3.78989

R01= 3.73813

R01= 3.73332

R01= 3.73309

R01= 3.73308

R01= 3.73308

ROOT=3.73308

RUN

FX=3.57079E-7

RUN

ITER=9.00000

RUN

XEQ C

MIN MAX?

4.00000 RUN

MAX ITER?

55.00000 RUN

TOLR?

1E-7 RUN

R01= 4.00000

R01= 3.37006

R01= 2.98586

R01= 2.84870

R01= 2.83296

R01= 2.83277

MIN%MAX=2.83277

RUN

FX=-7.08129

RUN

SLOPE=-4.98498E-7

RUN

2ND DERIV=10.99454

RUN

ITERS=6.00000

RUN

R00 = Function name

R01 = x

R02 = h

R03 = f(x)

R04 = f(x+h)

R05 = f(x-h)

R06 = Max Iters

R07 = Iters

R08 = Tolerance

Flag 00 is used and is cleared when the program ends.

Binary files for emulators:

Raw binary: RootMinMax.raw Binary for HP-42X: RootMinMax.42x (HP-48) RootMinMax49.42x (HP-49)

Generated by 42s2html - 27 April 2005, 22:49