POLYNOMIAL SOLVER for Sinclair ZX-80
by Paul Duckett
from Your Computer, June/July 1981

HERE IS a program which uses Newton's approximation to solve polynomials
within the arithmetic limits of the ZX-80. Line 1 should be input with a
space as the first character after REM, and the reverse video Z then
inserted by the command Poke 16427,191.

The program solves equations of the form

   n        n-1
a x  + a   x    + ... + a x + a  = 0.
 n      n-1              1     0

where n is less than 15 and each coefficient may be positive, negative or
zero.

Inputs are self-explanatory. The value inserted for Guess is not vital -
any value will find a real root in the machine's range if there is one -
but if there is more than one root within the range, the Guess should be
nearest to the root which you wish to find more exactly.

In line 10, A(1) to A(P+1) contain the coefficients of x**0 to x**p in the
function whose roots are being found. In line 13, A(P+2) to A(2*P+1)
contain the coefficients of X**0 TO X**P-1 in the derivative or slope of
the function whose roots are being found.

Line 30 to 33 find the value of the function and its slope for the current
approximation to the root. Line 35 to 37 try a new value for this
approximation if the slope is 0. If the slope is not 0, line 38 calculates
a closer approximation to the root.

When the new approximation is the same as the last one, line 39, the
program computes the values of the function, V and W, for the two adjacent
integers above and below the exact root - lines 56 to 64, with one or two
passes of lines 26 to 34. These values are then used in line 66 to produce
one decimal place of the root by linear interpolation.

There is a two-stage check for arithmetic overload before it occurs. Line 42
checks that the current approximation can be raised to the highest power in
the function, and if it can be, lines 43 to 48 check that each power of x
can be multiplied by its two coefficients before the attempt is made.

If overload would occur, the current approximation is moved 1 in the
correct direction, line 53, and that new approximation checked for
arithmetic overload. If overload would still occur the program stops at
line 74.

The use of Q in lines 19, 26 and 27 stops a fruitless search for non-real
roots. Line 65 prevents a spurious solution being "found" where the slope
of a function not intersecting the x axis is very great at a "solution"
tried by the program.

Although the linear interpolation may give errors of up to 1 for the higher
powers, solutions found by the program are accurate for smaller powers.
Integer roots are found exactly. Occasional difficulty with functions
barely cutting the x axis can usually be remedied by entering a less-wild
Guess.

[The program uses line 1 as a look up table. The published program listing
includes character '&' multiple times within this REM but this is not a
character supported by the ZX-80. The characters needed for that line are:
	REM ZD>)?:$$
the codes being:
	191,41,23,17,15,14,13,13,12,12,12,12,12
]