ChEn-3170: Computational Methods in Chemical Engineering Spring 2020 UMass Lowell; Prof. V. F. de Almeida 12Feb20
$ \newcommand{\Amtrx}{\boldsymbol{\mathsf{A}}} \newcommand{\Bmtrx}{\boldsymbol{\mathsf{B}}} \newcommand{\Cmtrx}{\boldsymbol{\mathsf{C}}} \newcommand{\Mmtrx}{\boldsymbol{\mathsf{M}}} \newcommand{\Imtrx}{\boldsymbol{\mathsf{I}}} \newcommand{\Pmtrx}{\boldsymbol{\mathsf{P}}} \newcommand{\Lmtrx}{\boldsymbol{\mathsf{L}}} \newcommand{\Umtrx}{\boldsymbol{\mathsf{U}}} \newcommand{\xvec}{\boldsymbol{\mathsf{x}}} \newcommand{\yvec}{\boldsymbol{\mathsf{y}}} \newcommand{\zvec}{\boldsymbol{\mathsf{z}}} \newcommand{\avec}{\boldsymbol{\mathsf{a}}} \newcommand{\bvec}{\boldsymbol{\mathsf{b}}} \newcommand{\cvec}{\boldsymbol{\mathsf{c}}} \newcommand{\rvec}{\boldsymbol{\mathsf{r}}} \newcommand{\norm}[1]{\bigl\lVert{#1}\bigr\rVert} \DeclareMathOperator{\rank}{rank} \DeclareMathOperator{\abs}{abs} $
your name
¶Context | Points |
---|---|
Precision of the answer | 80% |
Answer Markdown readability | 10% |
Code readability | 10% |
Python
function.NumPy
(provide your own test).Python
function.NumPy
(provide your own test).Python
function and test against a given matrix.NumPy
.'''1.1) Forward solve function'''
'''1.1) Test L x = b'''
'''1.2) Compare solutions'''
||x_vec - y_vec|| = 5.330084e-12
as a matrix $\Amtrx$ (need internet connection) and extract from it a lower triangular matrix of the same dimensions, show the image, and solve for a right side vector $\bvec$ with all ones as elements (i.e. $b_i = 1\ \forall \ i=1,\ldots,m$), using your forward solve function. Compute the difference of your solution to the solution using numpy.linalg.solve()
function and show the norm of the difference.
'''1.3) A matrix and its L part'''
'''1.3) Solve L y = b for b equal to a vector of ones'''
||x_vec - y_vec|| = 1.950040e-13
'''2.1) Backward solve function'''
'''2.1) Example U x = b'''
'''2.2) Compare solutions'''
||x_vec - y_vec|| = 2.009718e-14
'''2.3) A matrix and its U part'''
'''2.3) Solve U y = b for b equal to a vector of ones'''
||x_vec - y_vec|| = 2.304705e-13
where the multipliers $m_{i,k}$ are given by $m_{i,k} = \frac{A^{(k)}_{i,k}}{A^{(k)}_{k,k}}$. When $k = m-1$, $A^{(m)}_{i,j}$, is upper triangular, that is, $U_{i,j} = A^{(m)}_{i,j}$ . The lower triangular matrix is obtained using the multipliers $m_{i,k}$, that is $L_{i,j} = m_{i,j} \ \forall \ i>j$, $L_{i,i}=1$, and $L_{i,j}=0 \ \forall \ i<j$.
'''3.1) LU factorization function'''
'''3.1) Compute LU factors of A 120x120'''
max(abs((A - LU)) = 3.57492e-14
'''3.2 Compute: min(diag(U)), rank(A), det(A) using the LU factors'''
min(abs(diag(U)) = 1.25385e-03 my rank(A) = 120 np.linalg rank(A) = 120 my det(A) = -1.09249e-148 np.linalg det(A) = -1.09249e-148
'''3.3 Solve A x = b for b equal to a vector of ones '''
||x_vec - x_vec_gold|| = 3.26881e-10