# 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.



**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$.

# EXERCISE 1


```python
from numpy import *
from matplotlib.pyplot import *
from sympy import *
init_printing()

x=symbols("x")
A=Matrix([[x,1,2],[1,3,1],[2,1,3]])
det(A)
print(A)

results=zeros(5)
temp=A.berkowitz_minors()
temp
#x>11/8
```


```python
A[0,0]=0
A.LUdecomposition()
```




$$\left ( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\2 & -5 & 1\end{matrix}\right], \quad \left[\begin{matrix}1 & 3 & 1\\0 & 1 & 2\\0 & 0 & 11\end{matrix}\right], \quad \left [ \left [ 0, \quad 1\right ]\right ]\right )$$



# EXERCISE 2


```python
x=symbols("x")
A=Matrix([[1,x,-1],[x,35/3,1],[-1,x,2]])
det(A)
solve(det(A))
#linsolve(det(A),0)
#invertible when 3x^2+2x-11.6666666!=0
```


```python

```

4cfecc3b3a604145ab82e6b26f58066a525be58f
ipynb
Jupyter Notebook
notes/05c_linear_systems_direct_2.ipynb
samadio/P1.4_seed
3e19bc5b178061563042d8b1d0842fd1da3ed302
CC-BY-4.0
notes/05c_linear_systems_direct_2.ipynb
samadio/P1.4_seed
3e19bc5b178061563042d8b1d0842fd1da3ed302
CC-BY-4.0
notes/05c_linear_systems_direct_2.ipynb
samadio/P1.4_seed
3e19bc5b178061563042d8b1d0842fd1da3ed302
CC-BY-4.0
Qwen/Qwen-72B
1. YES
2. YES