# Solutions

## Question 1

> `1`. Obtain the determinant and the inverses of the following matrices:

> `1`. $A = \begin{pmatrix} 1 / 5 & 1\\1 & 1\end{pmatrix}$


```python
import sympy as sym

A = sym.Matrix([[sym.S(1) / 5, 1], [1, 1]])
A.det()
```




$\displaystyle - \frac{4}{5}$




```python
A.inv()
```




$\displaystyle \left[\begin{matrix}- \frac{5}{4} & \frac{5}{4}\\\frac{5}{4} & - \frac{1}{4}\end{matrix}\right]$



> `2`. $B = \begin{pmatrix} 1 / 5 & 1 & 5\\3 & 1 & 6 \\ 1 & 2 & 1\end{pmatrix}$


```python
B = sym.Matrix([[sym.S(1) / 5, 1, 5], [3, 1, 6], [1, 2, 1]])
B.det()
```




$\displaystyle \frac{129}{5}$




```python
B.inv()
```




$\displaystyle \left[\begin{matrix}- \frac{55}{129} & \frac{15}{43} & \frac{5}{129}\\\frac{5}{43} & - \frac{8}{43} & \frac{23}{43}\\\frac{25}{129} & \frac{1}{43} & - \frac{14}{129}\end{matrix}\right]$



> `3`. $C = \begin{pmatrix} 1 / 5 & 5 & 5\\3 & 1 & 7 \\ a & b & c\end{pmatrix}$


```python
a, b, c = sym.Symbol("a"), sym.Symbol("b"), sym.Symbol("c")
C = sym.Matrix([[sym.S(1) / 5, 5, 5], [3, 1, 7], [a, b, c]])
C.det()
```




$\displaystyle 30 a + \frac{68 b}{5} - \frac{74 c}{5}$




```python
C.inv()
```




$\displaystyle \left[\begin{matrix}\frac{- 35 b + 5 c}{150 a + 68 b - 74 c} & \frac{25 b - 25 c}{150 a + 68 b - 74 c} & - \frac{444}{25 \left(- \frac{444 a}{25} - \frac{5032 b}{625} + \frac{5476 c}{625}\right)}\\\frac{35 a - 15 c}{150 a + 68 b - 74 c} & \frac{- 25 a + c}{150 a + 68 b - 74 c} & - \frac{5032}{125 \left(- \frac{444 a}{5} - \frac{5032 b}{125} + \frac{5476 c}{125}\right)}\\\frac{- 5 a + 15 b}{150 a + 68 b - 74 c} & \frac{25 a - b}{150 a + 68 b - 74 c} & - \frac{74}{25 \left(6 a + \frac{68 b}{25} - \frac{74 c}{25}\right)}\end{matrix}\right]$



## Question 2

> `2`. Compute the following:

> `1`. $500\begin{pmatrix} 1 / 5 & 1\\1 & 1\end{pmatrix}$


```python
A = 500 * sym.Matrix([[sym.S(1) / 5, 1], [1, 1]])
A
```




$\displaystyle \left[\begin{matrix}100 & 500\\500 & 500\end{matrix}\right]$



> `2`. $\pi \begin{pmatrix} 1 / \pi & 2\pi\\3/\pi & 1\end{pmatrix}$


```python
B = sym.pi * sym.Matrix([[1 / sym.pi, 2 * sym.pi], [3 / sym.pi, 1]])
B
```




$\displaystyle \left[\begin{matrix}1 & 2 \pi^{2}\\3 & \pi\end{matrix}\right]$



> `3`. $500\begin{pmatrix} 1 / 5 & 1\\1 & 1\end{pmatrix} + \pi \begin{pmatrix} 1 / \pi & 2\pi\\3/\pi & 1\end{pmatrix}$


```python
A + B
```




$\displaystyle \left[\begin{matrix}101 & 2 \pi^{2} + 500\\503 & \pi + 500\end{matrix}\right]$



> `4`. $500\begin{pmatrix} 1 / 5 & 1\\1 & 1\end{pmatrix}\begin{pmatrix} 1 / \pi & 2\pi\\3/\pi & 1\end{pmatrix}$


```python
C = sym.Matrix([[1 / sym.pi, 2 * sym.pi], [3 / sym.pi, 1]])
A @ C
```




$\displaystyle \left[\begin{matrix}\frac{1600}{\pi} & 500 + 200 \pi\\\frac{2000}{\pi} & 500 + 1000 \pi\end{matrix}\right]$



## Question 3

> `3`. The matrix $A$ is given by $A=\begin{pmatrix}a & 4 & 2\\ 1 & a & 0\\ 1 & 2 & 1\end{pmatrix}$.

> `1`. Find the determinant of $A$


```python
A = sym.Matrix([[a, 4, 2], [1, a, 0], [1, 2, 1]])
determinant = A.det()
determinant
```




$\displaystyle a^{2} - 2 a$



> `2`. Hence find the values of $a$ for which $A$ is singular.

$A$ is singular when the determinant is $0$ so we solve that equation:


```python
sym.solveset(determinant, a)
```




$\displaystyle \left\{0, 2\right\}$



> `3`. State, giving a brief reason in each case, whether the simultaneous equations
>
> $$
  \begin{array}{l}
          a x + 4y + 2z= 3a\\
          x + a y  = 1\\
          x + 2y + z = 3\\
  \end{array}
  $$

> have any solutions when:
> `1`. $a = 3$;

When $a$ is 3 the determinant is none zero, and so the matrix that represents
that linear system can be inverted.

> `2`. $a = 2$

When $a$ is 2 the determinant is zero and so the matrix that represents
that linear system cannot be inverted.

## Question 4

> `4`. The matrix $D$ is given by $D = \begin{pmatrix} a & 2 & 0\\ 3 & 1 & 2\\ 0 & -1 & 1\end{pmatrix}$ where $a\ne 2$.
> `1`. Find $D^{-1}$.


```python
D = sym.Matrix([[a, 2, 0], [3, 1, 2], [0, -1, 1]])
D_inverse = D.inv()
D_inverse
```




$\displaystyle \left[\begin{matrix}- \frac{9}{18 - 9 a} & \frac{6}{18 - 9 a} & - \frac{12}{18 - 9 a}\\\frac{3}{6 - 3 a} & - \frac{a}{6 - 3 a} & \frac{2 a}{6 - 3 a}\\- \frac{3}{3 a - 6} & \frac{a}{3 a - 6} & \frac{a - 6}{3 a - 6}\end{matrix}\right]$



> `2`. Hence of otherwise, solve the equations:
>
> $$
    \begin{array}{l}
        a x + 2y = 3\\
        3x + y + 2z = 4\\
        - y + z = 1\\
    \end{array}
    $$

This corresponds to calculating: $D^{-1} \begin{pmatrix}3\\4\\1\end{pmatrix}$


```python
b = sym.Matrix([[3], [4], [1]])
D_inverse @ b
```




$\displaystyle \left[\begin{matrix}- \frac{15}{18 - 9 a}\\- \frac{2 a}{6 - 3 a} + \frac{9}{6 - 3 a}\\\frac{4 a}{3 a - 6} + \frac{a - 6}{3 a - 6} - \frac{9}{3 a - 6}\end{matrix}\right]$



9c669d12a9f5f6183fbc8880c4e372860a52d0d7
ipynb
Jupyter Notebook
book/tools-for-mathematics/04-matrices/solutions/.main.md.bcp.ipynb
11michalis11/pfm
c91b1eda70d7cde3fbe065db4667f84853947850
MIT
2020-09-24T21:02:41.000Z
2020-10-14T08:37:21.000Z
book/tools-for-mathematics/04-matrices/solutions/.main.md.bcp.ipynb
11michalis11/pfm
c91b1eda70d7cde3fbe065db4667f84853947850
MIT
2020-09-21T15:54:23.000Z
2021-12-19T23:26:15.000Z
book/tools-for-mathematics/04-matrices/solutions/.main.md.bcp.ipynb
11michalis11/pfm
c91b1eda70d7cde3fbe065db4667f84853947850
MIT
2020-10-02T09:21:27.000Z
2021-07-08T14:46:27.000Z
Qwen/Qwen-72B
1. YES
2. YES