|
|
|
|
||
|
DEFINITION MODULE PolyLib; (******************************************************************* Module PolyLib (Version 0.5) Copyright (c) 1986-2006 by Alex Itten and ETH Zurich. Purpose Types and procedures to form polynomials and to find their complex roots. Remarks -- Programming o Design Alex Itten 25/11/1986 o Implementation Alex Itten 25/11/1986 ETH Zurich Systems Ecology CHN E 35.1 Universitaetstrasse 16 8092 Zurich SWITZERLAND URLs: <mailto:RAMSES@env.ethz.ch> <http://www.sysecol.ethz.ch> <http://www.sysecol.ethz.ch/SimSoftware/RAMSES> Last revision of definition: 25/11/1986 AI *******************************************************************) FROM ComplexLib IMPORT Complex; CONST maxPolySize = 8; (* Max Order of polynoms *) TYPE NamenString = ARRAY[0..32] OF CHAR; Polynom = RECORD name : NamenString; curOrder : CARDINAL; koef : ARRAY[0..maxPolySize] OF Complex; END; PROCEDURE InitPolynom(VAR P:Polynom; Name: NamenString; n: CARDINAL); (* gives the polynom P the given Name and the current order n and sets all coefficents to zero *) PROCEDURE SetPolynom(VAR p: Polynom; coef: ARRAY OF Complex); (* sets the coefficients of the polynom p to the values specified by the parameter coef. If there are more than maxPolySize coefficients, the extra coefficients are ignored. If there are less than maxPolySize coeficients, then the current order of the polynom will be set to the correct value. *) PROCEDURE FormPolynom(VAR p: Polynom; roots: ARRAY OF Complex); (* This procedure forms a polynom from its given roots.If there are more than maxPolySize roots, the extra roots are ignored. If there are less than maxPolySize roots, then the current order of the polynom will be set to the correct value. *) PROCEDURE FindRoots(P:Polynom; VAR roots: ARRAY OF Complex; zInit: Complex; maxError: REAL; maxIteration : CARDINAL; VAR found: CARDINAL; VAR done: BOOLEAN); (* finds all roots of the polynom P. zInit is the initial value for the iteration. If done is TRUE, then all roots are found. The varaible found returns the number of roots, which are found. maxError defines the maximum tolerated absolute error and maxIteration the maximum number of iterations. Uses a Newton-Horner algorithm.*) END PolyLib.
|
||
|
|
|