Computermathematik2_7

387 days ago by PatrickHammer

Übungsblatt_7
SS 2010/11


BEISPIEL 20
Gegeben sei der R^n und eine Basis {v1 , . . . , vk } eines k-dimensionalen Unterraums U ⊂ R^n . Schreiben Sie einen Algorithmus der eine Basis zu dem orthogonalen Komplement U ⊥ findet. Man führe den Algorithmus vor für den Fall n = 6 und U ist der Unterraum aufgespannt von (1, 2, 3, 1, 2, 0)^T und (1, 3, 0, 4, 1, 2)^T.
def orthogonal_complement_base(M): ret=[]; m=len(M[0]); M.echelonize() Type=M.parent().base() I=MatrixSpace(Type,m,m).identity_matrix() for i in range(m): A=list(matrix(Type,copy(M).gram_schmidt()[0]))+ret if matrix(Type,A+[I[i]]).rank()>matrix(QQ,A).rank(): imatrix=matrix(Type,A+[I[i]]).gram_schmidt()[0] newRank=i+M.rank()+1; for j in range(newRank): if(matrix(Type,A+[imatrix[j]]).rank()>=newRank): ret.append(imatrix[j]); return matrix(Type,ret) orthogonal_complement_base(matrix(QQ,[[1,2,3,1,2,0],[1,3,0,4,1,2]])) 
       
[ 33/35  -9/70  -9/70  -1/10  -1/10  -1/35]
[     0  43/66  -2/11  -4/11 -13/66  -5/33]
[     0      0  23/86   3/86 -18/43   6/43]
[     0      0      0  16/69  -8/69 -28/69]
[ 33/35  -9/70  -9/70  -1/10  -1/10  -1/35]
[     0  43/66  -2/11  -4/11 -13/66  -5/33]
[     0      0  23/86   3/86 -18/43   6/43]
[     0      0      0  16/69  -8/69 -28/69]

BEISPIEL 21
Mit Hilfe des Gaußschen Eliminationsverfahrens, schreibe man einen Algorithmus der eine Basis für den Kern einer linearen Abbildung A : R^n → R^m findet. Man demonstriere den Algorithmus anhand des Beispiels A: (x1,x2,x3,x4)^T -> ((1,2,3,-2),(,1,1,-2,0),(-1,-2,2,1))*(x1,x2,x3,x4)^T
def kernel(M): M=matrix([list(row)+[0] for row in list(M)]).echelon_form() return [list(r)[0:len(list(r))-1] for r in M] print kernel(matrix(QQ[[1,2,3,-2],[1,1,-2,0],[-1,-2,2,1]])) 
       
[[1, 0, 0, 3/5], [0, 1, 0, -1], [0, 0, 1, -1/5]]
[[1, 0, 0, 3/5], [0, 1, 0, -1], [0, 0, 1, -1/5]]

BEISPIEL 22
Man berechne die Determinante von der quadratischen Matrix A in dem man Sie auf Zeilenstufenform bringt (mit dem Gaußschen Eliminationsverfahren) und danach die Diagonalelemente aufmultipliziert.
#first gauss i've ever made for python def historic_gauss(li): #works for matrix and 2D list li=list(li) #outputs matrix wasPivotX=[] pivot=0 while pivot<min(len(li[0]),len(li)): #diagonal till boundary line=0 Y=-1 #case that it stays -1 cannot occur cause of the while check for i in range(len(li[0])): if li[pivot][i]!=0 and i not in wasPivotX: Y=i break pivotvalue=li[pivot][Y] while line<len(li): if line!=pivot and pivotvalue!=0: value=li[line][Y] x=-value/pivotvalue for i in range(len(li[line])): li[line][i]+=x*li[pivot][i] line+=1 pivot+=1 wasPivotX.append(Y) return matrix(li) def det_historic(A): A=list(historic_gauss(A)) sums=[] for x in A: sums+=[sum(x)] z=1 for i in range(len(sums)): z=z*sums[i] return z