Doppelpost! Python-Programm, LR-Zerlegung |
| 13.12.2023, 23:22 | Abd95 | Auf diesen Beitrag antworten » |
| Python-Programm, LR-Zerlegung 1) Implementieren Sie in einem Python-Programm eine LR-Zerlegung mit Spaltenpivotsuche und Zeilenvertauschung.Benutzen Sie diese Implementierung, um zu einer gegebenen regulären Matrix A die Inverse A^−1 zu berechnen. 2) Testen Sie Ihr Programm anhand der folgenden Matrix A = ( 0 -4 10 15/2 -2 6 3 10 2 -6 7 -11/2 -2 10 -12 0 ) in dem Sie es die Inverse sowie das Produkt A^−1 A berechnen und ausgeben lassen. Meine Ideen: import numpy as np from scipy.linalg import lu_factor, lu_solve # Function to perform LU decomposition and calculate the inverse of a matrix def lu_decomposition_inverse(matrix): # Perform LU decomposition with partial pivoting lu, piv = lu_factor(matrix) # The number of rows of the matrix n = matrix.shape[0] # The inverse matrix inverse_matrix = np.zeros_like(matrix) # Solve the equation Ax = I for each column of the identity matrix to find the inverse for i in range(n): # Create the i-th column of the identity matrix identity_column = np.zeros(n) identity_column[i] = 1 # Solve the linear system using the LU decomposition and update the inverse matrix inverse_matrix[:, i] = lu_solve((lu, piv), identity_column) return inverse_matrix # Define the matrix A from the task A = np.array([[0, -4, 10, -15/2], [-2, 6, 3, 10], [2, -6, 7, -11/2], [-2, 10, -12, 0]], dtype='float64') # Calculate the inverse of A A_inv = lu_decomposition_inverse(A) # Display the results A_inv |
||
| 14.12.2023, 10:24 | HAL 9000 | Auf diesen Beitrag antworten » |
Das gibt jetzt aber langsam die gelbe Karte (das nächste mal Rot) für Crosspostings ohne Querverlinkung, ist nämlich bei dir schon Wiederholungsfall: https://www.onlinemathe.de/forum/Python-Programm |
||
|
|
Verwandte Themen
| Die Beliebtesten » |
|
| Die Größten » |
|
| Die Neuesten » |
|
