Computermathematik2_1

439 days ago by PatrickHammer

Übungsblatt_1
WS 2010/11


BEISPIEL 1ab
def gauss(A,a=0,b=0): p=min([p for p in [a,..,A.nrows()-1] if A[p][b]!=0]) #pivot !=0 A.swap_rows(a,p); A.rescale_row(a,1/A[a][b]) #<-transpose and rescale, add other row: [A.add_multiple_of_row(c,a,-A[c][b]/A[a][b]) for c in [0,..,A.nrows()-1] if c!=a] return gauss(A,a+1,b+1) if a+1<A.nrows() else A @interact def main(A=matrix(QQ,[[1,3,-2,1],[2,6,1,4],[-1,2,3,-4]])): pretty_print(gauss(A)) main() 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrr} 1 & 0 & 0 & \frac{96}{25} \\ 0 & 1 & 0 & -\frac{17}{25} \\ 0 & 0 & 1 & \frac{2}{5} \end{array}\right)

Click to the left again to hide and once more to show the dynamic interactive window


BEISPIEL 1c
def invert(A): if A.is_invertible(): #add identity and use gauss E=matrix([list(A[x])+[N(x==y) for y in [0,..,A.nrows()-1]] for x in [0,..,A.nrows()-1]]) return matrix([list(x[E.nrows():E.ncols()]) for x in gauss(E)]) @interact def main(A=matrix(QQ,[[1,3,-2,1],[2,6,1,4],[-1,2,3,-4]])): pretty_print(invert(A)) main() 
       

Click to the left again to hide and once more to show the dynamic interactive window


BEISPIEL 2
var('j') def laplace(A,i=0,j=0): if A.ncols()==1: return A[0][0] return sum([(-1)^(i+j)*A[i][j]*laplace( matrix([[A[x if x<i else x+1][y if y<j else y+1] for x in [0,..,A.nrows()-2]] for y in [0,..,A.ncols()-2]]) ) for i in [0,..,A.ncols()-1]]) @interact def main(A=matrix([[1,2,3],[2,3,1],[1,3,2]])): print "determinant: ",laplace(A) main() 
       
determinant: 6

Click to the left again to hide and once more to show the dynamic interactive window


BEISPIEL 3
var('a') @interact def main(A=matrix([[2,1,2,1],[3,a,1,3],[4,1,1-a,a+4]])): result=gauss(A) pretty_print(A); print("\nnot solveable for:\n") pretty_print(list(set([str(solve(1/result[i][A.ncols()-1]==0,a)).replace("\n","") for i in [0,..,A.nrows()-1]]))) main() 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrr} 1 & 0 & 0 & \frac{{\left(\frac{2}{2 \, a - 3} + 1\right)} {\left(a + \frac{3}{2 \, a - 3} + 2\right)}}{a + \frac{4}{2 \, a - 3} + 3} - \frac{3}{2 \, {\left(2 \, a - 3\right)}} + \frac{1}{2} \\ 0 & 1 & 0 & \frac{3}{2 \, a - 3} - \frac{4 \, {\left(a + \frac{3}{2 \, a - 3} + 2\right)}}{{\left(2 \, a - 3\right)} {\left(a + \frac{4}{2 \, a - 3} + 3\right)}} \\ 0 & 0 & 1 & -\frac{a + \frac{3}{2 \, a - 3} + 2}{a + \frac{4}{2 \, a - 3} + 3} \end{array}\right) not solveable for: \newcommand{\Bold}[1]{\mathbf{#1}}\left[\hbox{[a == (-5/2)]}\right]

Click to the left again to hide and once more to show the dynamic interactive window