Maplessa matriisioperaatioita varten ladataan paketti linalg Tarvittavat Maple-komennot:
matrix, vector, augment, addrow, mulrow, gaussjord (relevantti myös gausselim)
> with(linalg): Matriisi voidaan muodostaa matrix-komennolla vaakarivien (listojen) listana ( tai muodossa matrix(4,6,[1,-1,....,-2,1]); ) > A:=matrix([[1,-1,1,0,0,2],[1,1,2,4,1,2],[0,2,1,4,3,1],[1,-3,0,-4,-2,1]]); [ 1 -1 1 0 0 2 ] [ ] [ 1 1 2 4 1 2 ] A := [ ] [ 0 2 1 4 3 1 ] [ ] [ 1 -3 0 -4 -2 1 ] > b:=vector([0,3,2,0]); b := [ 0, 3, 2, 0 ]Komennolla augment liitetään sarakevektori matriisin perään. Näin saadaan "augmented matrix", vrt. KRE s. 345.
> Ab:=augment(A,b); [ 1 -1 1 0 0 2 0 ] [ ] [ 1 1 2 4 1 2 3 ] Ab := [ ] [ 0 2 1 4 3 1 2 ] [ ] [ 1 -3 0 -4 -2 1 0 ]Komento addrow(M,r1,r2,c) palauttaa matriisin, jossa M:n rivi r2 on korvattu vektorilla c*row(M,r1) + row(M,r2)
> Ab:=addrow(Ab,1,2,-1); # muutettava_rivi_no=2, kerroin = -1 # kerrottava ja yhteenlaskettava rivi_no=1 [ 1 -1 1 0 0 2 0 ] [ ] [ 0 2 1 4 1 0 3 ] Ab := [ ] [ 0 2 1 4 3 1 2 ] [ ] [ 1 -3 0 -4 -2 1 0 ] > Ab:=addrow(Ab,1,4,-1); # muutettava_rivi_no=4, kerroin = -1 # kerrottava ja yhteenlaskettava rivi_no=1 [ 1 -1 1 0 0 2 0 ] [ ] [ 0 2 1 4 1 0 3 ] Ab := [ ] [ 0 2 1 4 3 1 2 ] [ ] [ 0 -2 -1 -4 -2 -1 0 ]
> Ab:=addrow(Ab,2,3,-1); # muutettava_rivi_no=3, kerroin = -1 # kerrottava ja yhteenlaskettava rivi_no=2 [ 1 -1 1 0 0 2 0 ] [ ] [ 0 2 1 4 1 0 3 ] Ab := [ ] [ 0 0 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 ] [ ] [ 0 1 1/2 2 0 0 1/2 ] Ab := [ ] [ 0 0 0 0 1 0 2 ] [ ] [ 0 0 0 0 0 1 -5 ]
> Ab:=addrow(Ab,2,1,1); [ 1 0 3/2 2 0 0 21/2 ] [ ] [ 0 1 1/2 2 0 0 1/2 ] Ab := [ ] [ 0 0 0 0 1 0 2 ] [ ] [ 0 0 0 0 0 1 -5 ]Nyt on redusoitu porrasmuoto valmis. Tarkistetaan vielä
> gaussjord(augment(A,b)); [ 1 0 3/2 2 0 0 21/2 ] [ ] [ 0 1 1/2 2 0 0 1/2 ] [ ] [ 0 0 0 0 1 0 2 ] [ ] [ 0 0 0 0 0 1 -5 ]Kylla vaan!!
###################################################################### # Lopuksi permutoidaan sarakkeet niin, että "johtavat sarakkeet" # tulevat ensimmäisiksi, jolloin saadaan rakennne, jossa on # [I(4x4),P(4x2),b(4x1)] # eli: # # [4x4-yksikkömatriisi, 2 "parametrisaraketta", oikea puoli (b-sarake)] > submatrix(Ab,[1,2,3,4],[1,2,5,6,3,4,7]); [ 1 0 0 0 3/2 2 21/2 ] [ ] [ 0 1 0 0 1/2 2 1/2 ] [ ] [ 0 0 1 0 0 0 2 ] [ ] [ 0 0 0 1 0 0 -5 ]