system.copy 引用数组 pascal
system.copy gives reference to array pascal
我正在编写应该使用 Cramer 规则求解矩阵方程的程序,我有这样的函数:
function solveKramers(AMatr: Matrix; BMatr: Vector): vector;
var
detA: real;
solvingMatrix: Matrix;
i, j: Integer;
begin
detA := getDet(AMatr);
if (not (detA = 0) or not (Length(AMatr) = Length(BMatr))) then begin
SetLength(Result, Length(BMatr));
for i := 0 to High(BMatr) do begin
solvingMatrix := system.copy(AMatr);
for j := 0 to High(solvingMatrix) do begin
solvingMatrix[j, i] := BMatr[j];
end;
Result[i] := getDet(solvingMatrix) / detA;
end;
Exit;
end;
end;
我创建了 matrix = array of vector
和 vector = array of real
当我尝试使用它时,solvingMatrix := system.copy(AMatr);
创建了对 AMatr 的引用,而不是创建该矩阵的副本。
好吧,我不知道这个东西是如何工作的,但我通过单独复制每一行来解决它(奇怪的是我在 getDet 函数中做了类似的事情,但它工作正常)
我添加的代码如下所示:
for j := 0 to High(AMatr) do begin
solvingMatrix[j] := system.copy(AMatr[j]);
end;
我正在编写应该使用 Cramer 规则求解矩阵方程的程序,我有这样的函数:
function solveKramers(AMatr: Matrix; BMatr: Vector): vector;
var
detA: real;
solvingMatrix: Matrix;
i, j: Integer;
begin
detA := getDet(AMatr);
if (not (detA = 0) or not (Length(AMatr) = Length(BMatr))) then begin
SetLength(Result, Length(BMatr));
for i := 0 to High(BMatr) do begin
solvingMatrix := system.copy(AMatr);
for j := 0 to High(solvingMatrix) do begin
solvingMatrix[j, i] := BMatr[j];
end;
Result[i] := getDet(solvingMatrix) / detA;
end;
Exit;
end;
end;
我创建了 matrix = array of vector
和 vector = array of real
当我尝试使用它时,solvingMatrix := system.copy(AMatr);
创建了对 AMatr 的引用,而不是创建该矩阵的副本。
好吧,我不知道这个东西是如何工作的,但我通过单独复制每一行来解决它(奇怪的是我在 getDet 函数中做了类似的事情,但它工作正常)
我添加的代码如下所示:
for j := 0 to High(AMatr) do begin
solvingMatrix[j] := system.copy(AMatr[j]);
end;