📄 mathtypesdemo.txt
字号:
{
@abstract(EBK&NVS Pascal-Delphi Math Library: Test application)
@author(Nikolai V. Shokhirev <nikolai@shokhirev.com> <nikolai@u.arizona.edu>)
@author(Eugene B. Krissinel <keb@ebi.ac.uk> <krissinel@fh.huji.ac.il>)
@created(09.09.1991)
@lastmod(04.04.2002)
This is a temporary publication (reduced variant), will be updated later
check: http://www.shokhirev.com/nikolai/programs/samplecode.html
㎞ikolai V. Shokhirev, 2001-2002
}
procedure MathTypesDemo;
var
Vp, Vc: VcPtr;
Mp: MtPtr;
K, L, i, j: IntType;
s: string;
procedure MatTimesVec(var A: Vector; const B: Matrix; const C: Vector; N, M: IntType);
// A must be var because Vector is the array of RealType
// Vector access: A[i] or C[j]
// Matrix is the atrray of pointers and can be always declared as const
// Matrix access: B[i]^[j] because B[i]^ is a Vector
// see declarations in the units MathTypes and ComplexType
var
i, j: IntType;
s: RealType;
begin
for i := 1 to N do
begin
s := 0.0;
for j := 1 to M do
s := s + B[i]^[j]*C[j];
A[i] := s;
end;
end;
procedure InitMatVec(const A: VcPtr; const B: MtPtr; N, M: IntType);
// Both A and B are pointers and should be declared as const
// Vector access: A^[i]
// Matrix access: B^[i]^[j]
var
i, j: IntType;
begin
for i := 1 to N do
for j := 1 to M do
B^[i]^[j] := i*j;
for j := 1 to M do
A^[j] := j;
end;
begin
K := 2;
L := 3;
GetMatrixMemory(Mp, K, L);
GetVectorMemory(Vp, K);
GetVectorMemory(Vc, L);
InitMatVec(Vc, Mp, K, L);
Memo3.Clear;
Memo3.Lines.Add('Mp:');
for i := 1 to K do
begin
s := '';
for j := 1 to L do
s := s +' [ '+ FloatToStr(Mp^[i]^[j])+' ] ';
Memo3.Lines.Add(s);
end;
Memo3.Lines.Add('-----------------------------------------------');
Memo3.Lines.Add('Vc:');
s := '';
for j := 1 to L do
s := s +' [ '+ FloatToStr(Vc^[j])+' ] ';
Memo3.Lines.Add(s);
Memo3.Lines.Add('-----------------------------------------------');
{ Vp^ is Vector, Mp^ is Matrix }
MatTimesVec(Vp^, Mp^, Vc^, K, L);
Memo3.Lines.Add('Vp:');
s := '';
for i := 1 to K do
s := s + ' [ '+ FloatToStr(Vp^[i])+' ] ';
Memo3.Lines.Add(s);
FreeVectorMemory(Vp, K);
FreeVectorMemory(Vc, L);
FreeMatrixMemory(Mp, K, L);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -