The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information.... |
Home MathPack Vector How to use TVector | |||
See also: Installation Hints | |||
Using TVector |
|||
In order to use TVector (or TIntVector, which handles integer vectors) the user has first to create one or several vectors (instances of class TVector, or TIntVector) by selecting it from the component palette or calling the method Create. If a vector is not needed anymore, it should be removed from the memory by calling the methods Destroy or (preferably) Free. The single elements of a vector are represented by the property Elem. Most of the vector operations are available via methods. The following example shows the dynamic creation of two vectors Vec1 and Vec2 and several simple manipulations of them:
const VecLeng = 40; { size of the vectors } var Vec1 : TVector; Vec2 : TVector; dp : double; i : integer; begin Vec1 := TVector.Create (nil); { create vector 1 } Vec1.NrOfElems := VecLeng; Vec2 := TVector.Create (nil); { create vector 2 } Vec2.NrOfElems := VecLeng; for i:=1 to vecLeng do { fill Vec1 with random numbers } Vec1.Elem[i]:= random; Vec2.Fill (3.3); { fill Vec2 with constant elements } dp := Vec1.DotProduct (Vec2); { calculate the dot product } Vec1.Free; { destroy the vectors } Vec2.Free; end;
|