Скачиваний:
40
Добавлен:
01.05.2014
Размер:
8.06 Кб
Скачать

AP Library adapted for Delphi AP Library adapted for Delphi The document describes an AP library adapted for Delphi. The AP library for Delphi contains a basic set of mathematical functions and collection classes needed to run the programs from the ALGLIB website.

Compatibility This library should be compatible with all Object Pascal compilators starting with version supplied with Borland Delphi 4.0 (Note: if you have found any incompatibility, please let me know. Don't forget to write compiler version and type of error). This sources hadn't been tested under Kylix, I will appreciate any information about the results if someone will carry out such a test.

Structure and Use The library includes the only module ap.pas. To use the library, you should include this file to the project.

AP library description Constants

Functions

Arrays

Complex numbers operations

Constants MachineEpsilon

The constant represents the accuracy of machine operations, that is the minimum number for 1+machineepsilon≠1 in the given bit grid. The constant may be taken "oversized", that is real accuracy can be even higher.

MaxRealNumber

The constant represents the highest value of the positive real number, which could be represented on this machine. The constant may be taken "oversized", that is real boundary can be even higher.

MinRealNumber

The constant represents the lowest value of positive real number, which could be represented on this machine. The constant may be taken "oversized", that is real boundary can be even lower.

Functions function AbsReal(X : Extended):Extended;

Returns absolute value of a real number. This function is equivalent to the standard Abs function.

function AbsInt (I : Integer):Integer;

Returns absolute value of an integer. This function is equivalent to the standard Abs function.

function RandomReal():Extended;

Returns a random real number from half-interval [0,1).

function RandomInteger(I : Integer):Integer;

Returns a random integer between 0 and I-1.

function Sign(X:Extended):Integer;

Returns:

+1, if X>0

-1, if X<0

0, if X=0.

function DynamicArrayCopy(const A: TInteger1DArray):TInteger1DArray;overload;

function DynamicArrayCopy(const A: TReal1DArray):TReal1DArray;overload;

function DynamicArrayCopy(const A: TComplex1DArray):TComplex1DArray;overload;

function DynamicArrayCopy(const A: TBoolean1DArray):TBoolean1DArray;overload;

function DynamicArrayCopy(const A: TInteger2DArray):TInteger2DArray;overload;

function DynamicArrayCopy(const A: TReal2DArray):TReal2DArray;overload;

function DynamicArrayCopy(const A: TComplex2DArray):TComplex2DArray;overload;

function DynamicArrayCopy(const A: TBoolean2DArray):TBoolean2DArray;overload;

This function set is used to to make copies of one- and two-dimensional arrays.

Arrays The following types of dynamic arrays are defined in standard AP library:

type TInteger1DArray = array of LongInt; TReal1DArray = array of Double; TComplex1DArray = array of Complex; TBoolean1DArray = array of Boolean; TInteger2DArray = array of array of LongInt; TReal2DArray = array of array of Double; TComplex2DArray = array of array of Complex; TBoolean2DArray = array of array of Boolean; Complex numbers operations As there is no operator overloading in Object Pascal (and it is often subjected to criticism from C++ adepts), operations with complex numbers could not be implemented as easy as with built-in data type. Therefore Complex data type is defined in a library. It is a record with two real number fields x and y, and all the operations are performed with the use of special functions implementing addition, multiplication, subtraction and division. An input can be complex or real, and output is complex. These functions are listed below.

function C_Add(const Z1 : Complex; const Z2 : Complex):Complex;

function C_AddR(const Z1 : Complex; const R : Double):Complex;

Calculate Z1+Z2 or Z1+R.

function C_Sub(const Z1 : Complex; const Z2 : Complex):Complex;

function C_SubR(const Z1 : Complex; const R : Double):Complex;

function C_RSub(const R : Double; const Z1 : Complex):Complex;

Calculate Z1-Z2, Z1-R or R-Z1.

function C_Mul(const Z1 : Complex; const Z2 : Complex):Complex;

function C_MulR(const Z1 : Complex; const R : Double):Complex;

Calculate Z1*Z2 or Z1*R.

function C_Div(const Z1 : Complex; const Z2 : Complex):Complex;

function C_DivR(const Z1 : Complex; const R : Double):Complex;

function C_RDiv(const R : Double; const Z2 : Complex):Complex;

Calculate Z1/Z2, Z1/R or R/Z2.

function C_Equal(const Z1 : Complex; const Z2 : Complex):Boolean;

function C_EqualR(const Z1 : Complex; const R : Double):Boolean;

function C_NotEqual(const Z1 : Complex; const Z2 : Complex):Boolean;

function C_NotEqualR(const Z1 : Complex; const R : Double):Boolean;

Compare Z1 and Z2 or Z1 and R.

function C_Complex(const X : Double):Complex;

Converts a real number into equal complex number.

function C_Opposite(const Z : Complex):Complex;

Returns -Z.

function AbsComplex(const Z : Complex):Double;

Returns the modulus of complex number z. Modulus calculation is performed using so called "safe" algorithm, that could never cause overflow when calculating intermediate results.

function Conj(const Z : Complex):Complex;

Returns complex conjugate to z.

function CSqr(const Z : Complex):Complex;

Returns the square of z.

Соседние файлы в папке libs