1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#(C) Graham Ellis
#############################################################################
##
#M SolutionsMatDestructive( <mat>, <matvec> ) . . . . one solution for each
## of several equations
##
## One solution <x> of <x> * <mat> = <vec_i> or `fail' for each row vec_i
## of <matvec>
##
InstallMethod( SolutionsMatDestructive,
"generic method",
[ IsOrdinaryMatrix and IsMutable,
IsOrdinaryMatrix and IsMutable],
function( mat, matvec )
local i,ncols,sem, vno, z,x, row, sol,vec,solmat,z1,sol1,lngm;
solmat:=[];
z1 := Zero(mat[1][1]);
sol1:=ListWithIdenticalEntries(Length(mat),z1);
lngm:=Length(mat[1]);
sem := SemiEchelonMatTransformationDestructive(StructuralCopy(mat));
ncols := Length(matvec[1]);
for vec in matvec do
z := StructuralCopy(z1);
sol := StructuralCopy(sol1);
ConvertToVectorRepNC(sol);
if ncols <> lngm then
Error("SolutionMat: matrix and vector incompatible");
fi;
for i in [1..ncols] do
vno := sem.heads[i];
if vno <> 0 then
x := vec[i];
if x <> z then
AddRowVector(vec, sem.vectors[vno], -x);
AddRowVector(sol, sem.coeffs[vno], x);
fi;
fi;
od;
if IsZero(vec) then
Append(solmat,[sol]);
else
Append(solmat,[fail]);
fi;
od;
return solmat;
end);
|