delphi数值算法集光盘源代码,用于delphi7科学出版社出版.
源代码在线查看: d1r9.txt
implementation
//PROGRAM D1R9
//Driver for routine SPARSE
uses
unit2;
{$R *.DFM}
procedure ASUB(XIN:array of real;var XOUT:array of real);
var
I,N:integer;
begin
N:= 20;
XOUT[1]:=XIN[1] + 2 * XIN[2];
XOUT[N]:=-2 * XIN[N - 1] + XIN[N];
For I:=2 To N - 1 do
XOUT[I]:=-2 * XIN[I - 1] + XIN[I] + 2 * XIN[I + 1];
end;
procedure ATSUB(XIN:array of real;var XOUT:array of real);
var
I,N:integer;
begin
N:=20;
XOUT[1]:=XIN[1] - 2 * XIN[2];
XOUT[N]:=2 * XIN[N - 1] + XIN[N];
For I:=2 To N - 1 do
XOUT[I]:=2 * XIN[I - 1] + XIN[I] - 2 * XIN[I + 1];
end;
procedure TForm1.Button1Click(Sender: TObject);
var
X,B,BCMP:Array[0..20] of real;
I,J:Integer; RSQ:real;
F:TextFile;
const
s1='%10.1f'; s2='%10.6f'; N = 20;
begin
//输入已知的方程组的系数矩阵
For I:=1 To N do
begin
X[I]:= 0;
B[I]:= 1;
end;
B[1]:= 3;
B[N]:= -1;
SPARSE(B,N,X,RSQ);
//输出计算结果到文件
AssignFile(F, 'd:\delphi_shu\p1\d1r9.dat');
Rewrite(F);
Writeln(F,'Sum-squared residual: ',Format(s2,[RSQ]));
Writeln(F, '计算出的方程组的解');
For I:= 1 To 4 do
Writeln(F,Format(s2,[X[1+(I-1)*5]]),Format(s2,[X[2+(I-1)*5]]),
Format(s2,[X[3+(I-1)*5]]),Format(s2,[X[4+(I-1)*5]]),
Format(s2,[X[5+(I-1)*5]]));
Writeln(F, '将计算出的解B乘以系数矩阵,以验证计算结果正确');
ASUB(X,BCMP);
Writeln(F, '解乘以系数矩阵',' 方程组的右端向量');
For I:=1 To N do
Writeln(F,Format(s1,[BCMP[I]]),' ',Format(s1,[B[I]]));
CloseFile(F);
//屏幕显示计算结果
memo1.Lines.LoadFromFile('d:\delphi_shu\p1\d1r9.dat');
end;