Mat-1.415 V3/2002 LA.mwHA 11.9.02/maaliskuu 2012Alustukset, aliakset, kirjastotrestart:with(linalg):
with(LinearAlgebra):Edellinen on vanhempi, versiosta 6 alkaen on uudempi. Pyrimme etup"a"ass"a k"aytt"am"a"an uutta, mutta joskus on mukavaa/tarpeellista soveltaa jotain vanhan kunnon linalgin funktiota.Koska uudet nimet ovat tosi pitki"a, kannattaa m"a"aritell"a aliakset:alias(rref=ReducedRowEchelonForm): alias(Diag=DiagonalMatrix):alias(ref=GaussianElimination): # "row echelon form"alias(Det=Determinant,Id=IdentityMatrix):Matriisien rakentelu ja laskutoimituksetRakenteluKaikki matriisit kannattaa ajatella muodostetuiksi ositetuista matriiseista.
Katsotaan seuraavassa muutamia esimerkkej"a:JSFH
Maple MatlabLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYmLUYjNictSSNtbkdGJDYkUSIxRicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLUkjbW9HRiQ2LVEiLEYnRjQvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHUSV0cnVlRicvJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EmMC4wZW1GJy8lJ3JzcGFjZUdRLDAuMzMzMzMzM2VtRictRjE2JFEiMkYnRjRGNy1GMTYkUSIzRidGNEY0LyUlb3BlbkdRJyZsYW5nO0YnLyUmY2xvc2VHUScmcmFuZztGJy1GODYtUSI7RidGNEY7Rj5GQUZDRkVGR0ZJRksvRk9RLDAuMjc3Nzc3OGVtRic=Mapessa ei saa unohtaa pilkkuja, kuten MatlabissaLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlb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kthdHNvdGFhbn5CLkYnRi9GMi8lK2ZvcmVncm91bmRHUShbMCwwLDBdRicvJStleGVjdXRhYmxlR0ZGRj4=1..-1 vastaa Matlabin pelkk\303\244\303\244 kaksoispistett"a (:).Indeksi -1 vastaa Matlab:n end:i"a>> [1;2;3]>> [1 2 3] % tai [1,2,3]>> [1 2;3 4]>> syms a b c>> B=[A [1;2] ;[a b c]] B = [ 1, 2, 1] [ 3, 4, 2] [ a, b, c]>> syms x>> B(1,:)=[x x x]B = [ x, x, x] [ 3, 4, 2] [ a, b, c]Matlabissa voitaisiin kirjoittaa: B(1,1:end)=[x x x]
Voit viel"a kokeilla seuraavia muuttamalla kaksoispisteet (:) puolipisteiksi (;).B[1,1..-2]:B[1..-1,2]:=<haa,hii,hoo>: B:B[2..3,[1,3]]:B[2..3,[1,3]]:=<<21,31>|<23,33>>: B:LaskutoimituksetK"ayd"a"an l"api perusoperaatiot esimerkkien avulla.A := <<1,2>|<3,4>>;
B := <<a,b>|<c,d>>;KertolaskuA . B;TranspoosiTranspose(A);Gaussin eliminaatio rivioperaatioilla (k"asin)Aloitetaan restartista.restart:with(linalg):
with(LinearAlgebra):
Esim:A := <<1,1,0,1>|<-1,1,2,-3>|<1,2,1,0>|<0,4,4,-4>|<0,1,3,-2>|<2,2,1,1>>;b:=<0,3,2,0>;Ab:=<A|b>;Ab[2,1..-1]:=Ab[2,1..-1]-Ab[1,1..-1]: Ab;Ab[4,1..-1]:=Ab[4,1..-1]-Ab[1,1..-1]: Ab;1. sarake nollattu. Siirryt"a"an 2. sarakkeeseen.Ab[3,1..-1]:=Ab[3,1..-1]-Ab[2,1..-1]: Ab;Ab[4,1..-1]:=Ab[4,1..-1]+Ab[2,1..-1]: Ab;2. sarake nollattu. Seuraava pivot on sarakkeessa 5.Ab[4,1..-1]:=Ab[4,1..-1]+(1/2)*Ab[3,1..-1]: Ab;Ratkaise nyt "k"asin"!x6:=solve(-1/2*x=5/2,x);x5 ja x4 vapaita.x5:=solve(2*x+x6=-1,x);Jne. Kaikenkaikkiaan 2 vapaata parametria,x4 ja x3. Jos haluttaisiin sarakepermutaatioita, niin n"ain:Ab[1..-1,[3,5]]:=Ab[1..-1,[5,3]]:Ab[1..-1,[4,6]]:=Ab[1..-1,[6,4]]: Ab; Gaussin eliminaatio valmiilla funktioilla, aliakset ref ja rrefrestart:with(linalg):
with(LinearAlgebra):
alias(rref=ReducedRowEchelonForm):alias(ref=GaussianElimination): # "row echelon form"A := <<1,1,0,1>|<-1,1,2,-3>|<1,2,1,0>|<0,4,4,-4>|<0,1,3,-2>|<2,2,1,1>>;b:=<0,3,2,0>:Ab:=<A|b>;
E:=ref(Ab);rref(Ab);Takaisinsijoitus ref-muodosta sek"a ,LinearSolveE;LinearSolve(E[1..-1,1..-2],E[1..-1,-1]);