# Direct methods for solving linear systems (homework)


**Exercise 1.** Let us consider the linear system $A\mathbf{x} = \mathbf{b}$ where
$$
  A = 
  \begin{bmatrix}
  \epsilon & 1 & 2\\
  1 & 3 & 1 \\
  2 & 1 & 3 \\
  \end{bmatrix}.
$$

1. Find the range of values of $\epsilon \in \mathbb{R}$ such that the matrix $A$ is symmetric and positive definite.
**Suggestion**: use the *Sylvester's criterion* which states that  a symmetric matrix $A \in \mathbb{R}^{n \times n}$ is positive definite if and only if all the main minors (The main minors of $A \in \mathbb{R}^{n \times n}$ are the determinants of the submatrices $A_p = (a_{i,j})_{1 \leq i, j \leq p}$, $p = 1, ..., n$). of $A$ are positive.
2. What factorization is more suitable for solving the linear system $A\mathbf{x}=\mathbf{b}$ for the case $\epsilon=0$? Motivate the answer.
3. Compute the Cholesky factorization $A = R^T R$ for the case $\epsilon = 2$.
4. Given $\mathbf{b} = (1,1,1)^T$, solve the linear system by using the Cholesky factorization computed at the previous point.




```python
import sympy as sp
import numpy as np

sp.init_printing()

# Exercise 1.1

n = 3
epsilon = sp.Symbol('e')

A = sp.Matrix([[epsilon, 1, 2], [1, 3, 1], [2, 1, 3]])
A
```




$$\left[\begin{matrix}e & 1 & 2\\1 & 3 & 1\\2 & 1 & 3\end{matrix}\right]$$




```python
sp.det(A)
```


```python
sp.Matrix.berkowitz_minors(A)

# So, for the matrix to be positive definite the conditions are respectively
# e > 0
# e > 1/3
# e > 11/8
# so the matrix is positive for epsilon > 11/8
```


```python
# Exercise 1.2

"""
Since the matrix has a 0 pivot in the first row when epsilon = 0, the
most appropriate way of factorizing it in this case is Cholesky
factorization.
"""
```




    '\nSince the matrix has a 0 pivot in the first row when epsilon = 0, the\nmost appropriate way of factorizing it in this case is Cholesky\nfactorization.\n'




```python
# Exercise 1.3 (LU instead of Cholesky)

L,U,_ = A.LUdecomposition()
```


```python
L
```




$$\left[\begin{matrix}1 & 0 & 0\\2 & 1 & 0\\e & \frac{3 e}{5} - \frac{1}{5} & 1\end{matrix}\right]$$




```python
U
```




$$\left[\begin{matrix}1 & 3 & 1\\0 & -5 & 1\\0 & 0 & - \frac{8 e}{5} + \frac{11}{5}\end{matrix}\right]$$




```python
# Exercise 1.4 (LU instead of Cholesky)

b = sp.Matrix([[1, 1, 1]])

sp.solve(A, b)
```

**Exercise 2.** Let us consider the following matrix $A \in \mathbb R^{3 \times 3}$ depending on the parameter $\epsilon \in \mathbb R$:
$$
A =
\begin{bmatrix}
1 & \epsilon & -1 \\
\epsilon & \frac{35}3 & 1 \\
-1 & \epsilon & 2 \\
\end{bmatrix}.
$$



1. Calculate the values of the parameter $\epsilon \in \mathbb R$ for which the matrix $A$ is invertible (non singular).

2. Calculate the Gauss factorization $LU$ of the matrix $A$ (when non singular) for a generic value of the parameter $\epsilon \in \mathbb R$.

3. Calculate the values of the parameter $\epsilon \in \mathbb R$ for which the Gauss factorization $LU$ of the matrix $A$  (when non singular) exists and is unique.

4. Set $\epsilon = \sqrt{\frac{35}3}$ and use the pivoting technique to calculate the Gauss factorization $LU$ of the matrix $A$.

5. For $\epsilon=1$, the matrix $A$ is symmetric and positive definite. Calculate the corresponding Cholesky factorization of the matrix $A$, i.e. the upper triangular matrix with positive elements on the diagonal, say $R$, for which $A = R^T R$.


```python
# Exercise 2.1

epsilon = sp.Symbol("e")
A = sp.Matrix([[1, epsilon, -1], [epsilon, 35/3, 1], [-1, epsilon, 2]])
sp.solve(sp.det(A))
```


```python

```

4f07ae46c66fb0a99fe30bc9b37d61342669dc64
ipynb
Jupyter Notebook
notes/05c_linear_systems_direct_2.ipynb
gsarti/P1.4_seed
e09dc4381c5da0c5781e185d7bce69679b8fca66
CC-BY-4.0
2018-11-08T07:53:28.000Z
2018-11-08T07:53:28.000Z
notes/05c_linear_systems_direct_2.ipynb
gsarti/P1.4_seed
e09dc4381c5da0c5781e185d7bce69679b8fca66
CC-BY-4.0
notes/05c_linear_systems_direct_2.ipynb
gsarti/P1.4_seed
e09dc4381c5da0c5781e185d7bce69679b8fca66
CC-BY-4.0
2019-01-26T11:41:55.000Z
2019-01-26T11:41:55.000Z
Qwen/Qwen-72B
1. YES
2. YES