[NumAn] Les 4

1887 days ago by Toon.Baeyens

M = random_matrix(RDF, 4, 4) 
       
       

                                
                            

                                
P, L, U = M.LU() P, L, U 
       

                                
                            

                                
P^-1*L*U - M 
       

                                
                            

                                
Q, R = M.QR() Q, R 
       

                                
                            

                                
Q*R - M 
       

                                
                            

                                
Q * Q.transpose() 
       

                                
                            

                                
M * x = b Q*R *x = b R*x = Q.transpose() * b 
       
Traceback (click to the left of this block for traceback)
...
SyntaxError: can't assign to operator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_21.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("TSAqIHggID0gYgpRKlIgKnggID0gYgpSKnggPSBRLnRyYW5zcG9zZSgpICogYg=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/var/sage/tmpAUpvtc/___code___.py", line 2
    M * x  = b
SyntaxError: can't assign to operator
P = M*M.transpose() L = (P).cholesky() L 
       

                                
                            

                                
L*L.transpose() - P 
       

                                
                            

                                

LU decompositie in sage

M = random_matrix(RDF, 4, 4) b = random_vector(RDF, 4) 
       
LUmatrix = list(map(list, M)) for k in range(len(LUmatrix) - 1): for i in range(k+1, len(LUmatrix)): LUmatrix[i][k] /= LUmatrix[k][k] for j in range(k+1, len(LUmatrix)): for i in range(k+1, len(LUmatrix)): LUmatrix[i][j] -= LUmatrix[i][k] * LUmatrix[k][j] 
       
x = list(b) for k in range(1, len(x)): for j in range(k): x[k] -= LUmatrix[k][j] * x[j] for k in range(len(x) - 1, -1, -1): for j in range(k+1, len(x)): x[k] -= LUmatrix[k][j] * x[j] x[k] /= LUmatrix[k][k] 
       
M.solve_right(b)