LU Decomposition Method Algorithm Decomposition phase The LU Decomposition (Doolittle) method has the following properties: The U matrix is identical to the upper triangular matrix resulting from the Gaussian Elimination; The elements at the bottom below the main diagonal of the matrix L are the multipliers used during the Gaussian Elimination, that is, Li*j is the multiplier that eliminated Ai*j. It is common practice to store the multipliers at the bottom of the coefficient matrix, replacing the coefficients as they are eliminated (Li*j replacing Ai*j) The diagonal elements of L do not need to be stored, as their values are understood to be unitary. The final form of the coefficient matrix would be the mixture of L and U: The initial part of the LU Decomposition Method algorithm is identified with Gaussian Elimination, except that each λ multiplier is now stored in the lower triangular portion of matrix A: 1)solve the system of linear equations followed by the Lu decomposition algorithm a) show what the solution vector is answer import numpy as np def LUdecomp(a): n = len(a) for k in range(0,n-1): for i in range(k+1,n): if a[i,k] != 0.0: lam = a [i,k]/a[k,k] a[i,k+1:n] = a[i,k+1:n] - lam*a[k,k+1:n] a[i,k] = lam return a def LUsolve(a,b): n = len(a) for k in range(1,n): b[k] = b[k] - np.dot(a[k,0:k],b[0:k]) b[n-1] = b[n-1]/a[n-1,n-1] for k in range(n-2,-1,-1): b[k] = (b[k] - np.dot(a[k,k+1:n],b[k+1:n]))/a[k,k] return b z = np.array([[3.50, 2.77, -0.76, 1.80], [-1.80, 2.68, 3.44, -0.09], [0.27, 5.07, 6.90, 1.61], [1.71, 5.45, 2.68, 1.71]]) k = np.array([[7.31, 5.45, 2.68, 1.71]]) z=LUdecomp(z)x=LUsolve(z,k[0]) In [ ]: print('x = \n', x) b)Through code modifications (counters?) compute how many multiplications are performed to find the solution vector
python
Linear Equation System
LU Decomposition Method
Decomposition phase The LU Decomposition (Doolittle) method has the following properties:
The U matrix is identical to the upper triangular matrix resulting from the Gaussian Elimination;
The elements at the bottom below the main diagonal of the matrix L are the multipliers used during the Gaussian Elimination, that is, Li*j is the multiplier that eliminated Ai*j.
It is common practice to store the multipliers at the bottom of the coefficient matrix, replacing the coefficients as they are eliminated (Li*j replacing Ai*j) The diagonal elements of L do not need to be stored, as their values are understood to be unitary. The final form of the coefficient matrix would be the mixture of L and U:
The initial part of the LU Decomposition Method algorithm is identified with Gaussian Elimination, except that each λ multiplier is now stored in the lower triangular portion of matrix A:
1)solve the system of linear equations followed by the Lu decomposition algorithm
a) show what the solution
answer
import numpy as np
def LUdecomp(a):
n = len(a)
for k in range(0,n-1):
for i in range(k+1,n):
if a[i,k] != 0.0:
lam = a [i,k]/a[k,k]
a[i,k+1:n] = a[i,k+1:n] - lam*a[k,k+1:n]
a[i,k] = lam
return a
def LUsolve(a,b):
n = len(a)
for k in range(1,n):
b[k] = b[k] - np.dot(a[k,0:k],b[0:k])
b[n-1] = b[n-1]/a[n-1,n-1]
for k in range(n-2,-1,-1):
b[k] = (b[k] - np.dot(a[k,k+1:n],b[k+1:n]))/a[k,k]
return b
z = np.array([[3.50, 2.77, -0.76, 1.80],
[-1.80, 2.68, 3.44, -0.09],
[0.27, 5.07, 6.90, 1.61],
[1.71, 5.45, 2.68, 1.71]])
k = np.array([[7.31, 5.45, 2.68, 1.71]])
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images