gordon freeman hat die Formeln doch schon umgestellt.
Hier nochmal die einzelnen Schritte für die erste Gleichung...
Code:
. 1+x
. --- - 10y + z = -15 | *10²
. 10²
.
. 1+x - 10*10²y + 10²z = -15 * 10²
.
. 1+x - 1000y + 100z = -1500 | -1
.
. x - 1000y + 100z = -1500 -1 | :100
.
. 1 1
. ---x - 10y + z = -15 - ---
. 100 100
Delphi-Quellcode:
TGaussSolved = array of Extended;
TGaussLine = TGaussSolved;
TGaussMatrix = array of TGaussLine;
:
procedure TForm.ButtonClick(Sender: TObject);
var
A: TGaussMatrix;
Res: TGaussSolved;
i, j: Integer;
s:string;
begin
SetLength(A, 3, 4);
A[0][0] := 1/100; A[0][1] := -10; A[0][2] := 1; A[0][3] := -15-(1/100);
A[1][0] := 1/4; A[1][1] := -2; A[1][2] := 1; A[1][3] := 12-(1/4);
A[2][0] := 1/25; A[2][1] := -5; A[2][2] := 1; A[2][3] := 12-(1/25);
for i := 0 to High(A) do begin
s:='';
for j := 0 to High(A[i]) - 1 do
s:=s +FloatToStr(A[i, j]) + '*x(' + inttostr(j + 1) + ') + ';
Memo1.Lines.Append(s+'= c(' + inttostr(i + 1) + ')');
end;
Res := SolveLinearSystem(A, 3, 4);
for i := 0 to High(Res) do
Memo1.Lines.Append('x(' + inttostr(i+1) + ') = ' + FloatToStr(Res[i]));
end;
Code von SolveLinearSystem hier
Gruss
Thorsten