Einzelnen Beitrag anzeigen

swarley

Registriert seit: 17. Aug 2011
6 Beiträge
 
#4

AW: Übergabe einer Matrix an Unterprogramm

  Alt 24. Aug 2011, 17:45
so ich habe meinen algorithmus jetzt optimiert. und mein unterprogramm enthält folgenden Quelltext:
Delphi-Quellcode:
procedure Inverse(a,zeilen,spaltengauss:Integer;var matgauss:TMatrixgauss);
var i,j,k : Integer;
begin
  if a < zeilen-1 then
  begin
      for i := a to spaltengauss - 1 do
       begin
         matgauss[a,i]:=matgauss[a,i]/matgauss[a,a];
       end;
      for j := a+1 to zeilen - 1 do
        begin
          for k := a to spaltengauss - 1 do
            begin
              matgauss[j,k]:=matgauss[j,k]-matgauss[j,a]*matgauss[a,k];
            end;
        end;
    Inverse(a+1,zeilen,spaltengauss,matgauss);

    for j := a-1 downto 0 do
    matgauss[j,a]:=matgauss[j,a]-matgauss[j,a]*matgauss[a,a];
  end;
  for i := zeilen-1 to spaltengauss-1 do
    begin
       matgauss[zeilen-1,i]:=matgauss[zeilen-1,i]/matgauss[zeilen-1,zeilen-1];
        for j := a-1 downto 0 do
         matgauss[j,a]:=matgauss[j,a]-matgauss[j,a]*matgauss[a,a];
    end;
end;
mit der typdeklaration:
TMatrixgauss = array[0..5,0..10]of Double; in meiner ButtonInverse.onClick procedure erstelle ich die matrix matgauss, die vor der übergabe, wie folgt aussieht:
|8 4 5 1 0 0|
|4 7 3 0 1 0| =: matgauss
|7 3 2 0 0 1|

Ich habe mehrmals überprüft, dass auch wirklich diese matrix in "matgauss" steckt, daher verstehe ich nicht wieso ich nach meinem prozeduraufruf Inverse(0,zeilen,spaltengauss,matgauss); , wenn ich eine 3 x 3 matrix eingebe, in meinem Stringgrid folgendes Ergebnis erhalte(zeilen hat den wert 3, spaltengauss 6)
|1 0 0 1 0 0|
|0 1 0 0 1 0|
|0 0 1 0 0 1|


anstatt:
|1 0 0 -0.05 -0.08 0.25|
|0 1 0 -0.14 0.20 0.04|
|0 0 1 0.40 -0.04 -0.43|

(gut das ist wegen den gebrochenen Zahlen jetzt ein doofes Beispiel, aber darum geht es ja nicht)
Kann mir jemand erklären, wieso mein algorithmus im "vorderen Teil" der Matrix arbeitet und im "hinteren" nicht?
  Mit Zitat antworten Zitat