Dear forum, I have written a program for the gauss algorithm, but it will run at the second call: gap> gauss:=function(A,m,n) > local i,j,k,rcharind,B; > k:=1;r:=0;charind:=[]; > repeat > for j in [1..n] do > if A[k][j]=0 then > for i in [k+1..m] do > if A[i][j]<>0 then > B:=A[i];A[i]:=A[k];A[k]:=B; > break; > fi; > od; > fi; > if A[k][j]<>0 then > r:=r+1;Add(charind,j); > A[k]:=A[k]*1/A[k][j]; > for i in [k+1,m] do > A[i]:=A[i]+A[k]*-A[i][j]; > od; > k:=k+1; > fi; > od; > until k=m; > for k in [2..r] do > for i in [1..k-1] do > A[i]:=A[i]+A[k]*-A[i][charind[k]]; > od; > od; > end; function( A, m, n ) ... end gap> A:=[ [ 1, -1, 1, 1, 1, 2 ], [ 0, 1, 2, 1, 5, 9 ], [ 0, 0, 0, 1, 2, 3 ], > [ 0, 1, 2, -2, -1, 0 ], [ 0, 0, 0, 1, 2, -3 ] ]; [ [ 1, -1, 1, 1, 1, 2 ], [ 0, 1, 2, 1, 5, 9 ], [ 0, 0, 0, 1, 2, 3 ], [ 0, 1, 2, -2, -1, 0 ], [ 0, 0, 0, 1, 2, -3 ] ] gap> gauss(A,5,6);
List Element: <list>[6] must have an assigned value at
A[i] := A[i] + A[k] * - A[i][j];
<function>( <arguments> ) called from read-eval-loop
Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
or you can return after assigning a value to continue
now the second trial:
brk> quit;
gap> gauss(A,5,6); gap> Display(A); [ [ 1, 0, 3, 0, 2, 0 ], [ 0, 1, 2, 0, 3, 0 ], [ 0, 0, 0, 1, 2, 0 ], [ 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0 ] ]
Who can explain that phenomen?
Best wishes
Kurt Ewald