---
title: "Jeszcze raz macierze"
lecture_number: 13
has_solutions: true
has_exercises: true
file_format: mystnb
kernelspec:
  name: sagemath
  display_name: SageMath
---

```{include} ../_includes/sagecell-loader.md
```

# Jeszcze raz macierze

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">

</script>
</div>
```

## Zadania na zajęcia

```{code-cell} sage
:tags: [remove-input]
from myst_nb import glue
from IPython.display import Math

body_01 = DisplayMatrix(matrix([[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, -1, 1], [1, 1, 1, 0]]))
content = rf"""
   {body_01}
"""
glue('sageglue_13_0', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)

body_01 = DisplayMatrix(matrix([[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, -1, 1], [1, 1, 1, 0]]).transpose())
content = rf"""
   {body_01}
"""
glue('sageglue_13_1', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

::::{exercise}
:label: prob-13-ex-01
:class: [exercise]

Jeśli to możliwe, wyznacz
macierz odwrotną do macierzy:

:::{container} columns-3-auto

1. $\begin{bmatrix}
   3 & 4 & -6 \\
   4 & 3 & -6 \\
   4 & 4 & -7
   \end{bmatrix}$

2. $\begin{bmatrix}
   1 & 2  & -1 \\
   3 & -2 & 0  \\
   4 & 0  & -1
   \end{bmatrix}$

3. {glue:}`sageglue_13_0`

4. {glue:}`sageglue_13_1` .

:::

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-01`, {numref}`lec-11-ex-02`.
:::

::::

::::{exercise}
:label: prob-13-ex-02
:class: [exercise]

Znajdź jądra macierzy z poprzedniego zadania (należy zgłosić jako jedno rozwiązanie dla wszystkich macierzy).

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-04`, {numref}`lec-13-ex-04`.
:::

::::

```{code-cell} sage
:tags: [remove-input]
from myst_nb import glue
from IPython.display import Math

body_01 = DisplayMatrix(matrix([[1, 2, -1], [2, 1, 1], [-1, 1, 3]]) * matrix([[1, 0, 0, 1, 1], [0, 1, 0, -1, 2], [0, 0, 0, 0, 0]]))
content = rf"""
   {body_01}
"""
glue('sageglue_13_14', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)

body_01 = DisplayMatrix((matrix([[1, 2, -1], [2, 1, 1], [-1, 1, 3]]) * matrix([[1, 0, 0, 1, 1], [0, 1, 0, -1, 2], [0, 0, 0, 0, 0]])).transpose())
content = rf"""
   {body_01}
"""
glue('sageglue_13_15', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

::::{exercise}
:label: prob-13-ex-03
:class: [exercise]

Znajdź jądro macierzy:

:::{container} columns-2-auto

1. {glue:}`sageglue_13_14`
2. {glue:}`sageglue_13_15` .

:::

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-04`, {numref}`lec-13-ex-04`.
:::

::::

::::{exercise}
:label: prob-13-ex-04
:class: [exercise]

Rozwiąż równanie macierzowe:

:::{container} columns-2-auto

1. $\begin{bmatrix}
   1 & -1 \\
   1 & 2
   \end{bmatrix}
   \cdot X
   +
   \begin{bmatrix}
   -1 & 2  \\
   1  & -1
   \end{bmatrix} =
   \begin{bmatrix}
   2 & -4 \\
   4 & 2
   \end{bmatrix}
   $

2. $\begin{bmatrix}
   1 & 2 \\
   2 & 3
   \end{bmatrix}
   \cdot X \cdot
   \begin{bmatrix}
   0 & 1 \\  -1 & -5
   \end{bmatrix} =
   \begin{bmatrix}
   2  & 2 \\
   -1 & 0
   \end{bmatrix}.
   $

:::

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-03`.
:::

::::

::::{exercise}
:label: prob-13-ex-05
:class: [exercise]

Niech
$X= \begin{bmatrix}
  4 \\  1  \\   2
\end{bmatrix}$
oraz
$A=\begin{bmatrix}
   5  & 0 & -6 \\
   -2 & 2 & 4  \\
   3  & 0 & -4
\end{bmatrix}?$

Czy $X$ jest wektorem własnym macierzy $A^n$ dla $n\in\nn$?

Jeśli tak, to podaj odpowiadającą wartość własną.

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-05`.
:::

::::

::::{exercise}
:label: prob-13-ex-06
:class: [exercise]

Dla podanej macierzy:

- znajdź wartości własne
- odpowiedz, czy jest ona nieosobliwa?
- znajdź podprzestrzenie własne
- dla każdej wartości własnej podaj przykładowy wektor własny
- znajdź jądro.

:::{container} columns-3-auto

1. $\begin{bmatrix}
   0  & -2 & 3 \\
   -2 & 0  & 3 \\
   -2 & -2 & 5
   \end{bmatrix}$

2. $\begin{bmatrix}
   3 & -5 & -3 \\
   1 & -2 & -1 \\
   1 & -1 & -1
   \end{bmatrix}$

3. $\begin{bmatrix}
   2 & -4 & -4 \\
   2 & -4 & -2 \\
   0 & 0  & -2
   \end{bmatrix} .$

:::

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-05`.
:::

::::

```{code-cell} sage
:tags: [remove-input]
from myst_nb import glue
from IPython.display import Math

A7 = matrix([[0,-2,3],[-2,0,3],[-2,-2,5]])
A8 = matrix([[3,-5,-3],[1,-2,-1],[1,-1,-1]])
A9 = matrix([[2,-4,-4],[2,-4,-2],[0,0,-2]])
```

## Zadania domowe

::::{exercise}
:label: prob-13-ex-07
:class: [exercise]

Wyznacz macierz odwrotną do podanej lub udowodnij, że macierz odwrotna nie istnieje.

:::{container} columns-3-auto

1. $  \begin{bmatrix}
   j   & 3\\
   1+j & 4-3j
   \end{bmatrix}$

2. $\begin{bmatrix}
   1 & 2  & -1 \\
   3 & -2 & 0  \\
   2 & -3 & 1
   \end{bmatrix}$

3. $  \begin{bmatrix}
   1 & 2  & -1 \\
   1 & 3  & -3 \\
   0 & -2 & 5
   \end{bmatrix}$

4. $  \begin{bmatrix}
   3 & 2 & -3 \\
   2 & 3 & -3 \\
   2 & 2 & -2 \\
   \end{bmatrix}$

5. $  \begin{bmatrix}
   -7  & 10 & 4 & -8  \\
   -12 & 19 & 8 & -16 \\
   -6  & 6  & 3 & -4  \\
   -12 & 18 & 8 & -15
   \end{bmatrix} .$

:::

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-01`, {numref}`lec-11-ex-02`.
:::

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Punkt 1. (macierz zespolona)
j = I
A = matrix(CC, [[j, 3], [1+j, 4-3*j]])
show("Macierz A:", A)
show("Wyznacznik:", A.det())
show("Macierz odwrotna:", A.inverse())
</script>
</div>
```

::::{exercise}
:label: prob-13-ex-08
:class: [exercise]

Znajdź jądra macierzy z poprzedniego zadania oraz macierzy:

:::{container} columns-3-auto

1. $  \begin{bmatrix}
   1  & 1  & 2  & 1  & -2 \\
   1  & 2  & 2  & 2  & 0  \\
   3  & -1 & 6  & -1 & 1  \\
   -1 & 2  & -2 & 2  & -3
   \end{bmatrix}$

2. $  \begin{bmatrix}
   1  & -3 & 1 & 2 & 3 \\
   1  & -3 & 2 & 4 & 6 \\
   -2 & 6  & 0 & 0 & 0 \\
   1  & -3 & 3 & 6 & 9
   \end{bmatrix}$

3. $  \begin{bmatrix}
   4  & 2  & 2  & 3  \\
   1  & -1 & -2 & 1  \\
   8  & 4  & 4  & 6  \\
   -3 & 3  & 6  & -3 \\
   12 & 6  & 6  & 9
   \end{bmatrix} .$

:::

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-04`, {numref}`lec-13-ex-04`.
:::

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Punkt 1.
M = matrix(QQ, [[1, 1, 2, 1, -2], [1, 2, 2, 2, 0], [3, -1, 6, -1, 1], [-1, 2, -2, 2, -3]])
show("Macierz M:", M)
show("Jądro macierzy (ker M):", M.right_kernel())
show("Baza jądra macierzy:", M.right_kernel().basis())
</script>
</div>
```

::::{exercise}
:label: prob-13-ex-09
:class: [exercise]

Rozwiąż równanie macierzowe.

1. $X \cdot
   \begin{bmatrix}
   1  & -1 & 0 \\
   1  & 2  & 0 \\
   -2 & 1  & 1
   \end{bmatrix}
   +
   \begin{bmatrix}
   1 & 0 & 1 \\
   2 & 1 & 2 \\
   1 & 2 & 1
   \end{bmatrix} =
   \begin{bmatrix}
   2 & -4 & 1 \\
   0 & 4  & 4 \\
   4 & 2  & 1
   \end{bmatrix}$

2. $ \begin{bmatrix}
   1 & 2 \\
   2 & 3
   \end{bmatrix}
   \cdot X \cdot
   \begin{bmatrix}
   0  & 1 & 1  \\
   -1 & 1 & 3  \\
   1  & 0 & -1
   \end{bmatrix} =
   \begin{bmatrix}
   2  & 2 \\
   3  & 5 \\
   -1 & 0
   \end{bmatrix}^T .$

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-03`.
:::

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Punkt 1.
B = matrix(QQ, [[1, -1, 0], [1, 2, 0], [-2, 1, 1]])
C = matrix(QQ, [[1, 0, 1], [2, 1, 2], [1, 2, 1]])
D = matrix(QQ, [[2, -4, 1], [0, 4, 4], [4, 2, 1]])
X = (D - C) * B.inverse()  # z X*B + C = D wynika X = (D - C)*B^(-1)
show("X = (D - C) * B^(-1):", X)
show("Sprawdzenie X*B + C:", X*B + C)
</script>
</div>
```

::::{exercise}
:label: prob-13-ex-10
:class: [exercise]

Dla podanej macierzy:

- znajdź wartości własne
- odpowiedz, czy jest ona nieosobliwa?
- znajdź podprzestrzenie własne
- dla każdej wartości własnej podaj przykładowy wektor własny
- znajdź jądro.

:::{container} columns-3-auto

1. $ \begin{bmatrix}
   1  & 1 \\
   -1 & 3 \\
   \end{bmatrix}$

2. $ \begin{bmatrix}
   j  & 3 \\
   -3 & j \\
   \end{bmatrix}$

3. $\begin{bmatrix}
   1 & 0  & 0 \\
   4 & -2 & 2 \\
   8 & -6 & 5
   \end{bmatrix}$

4. $\begin{bmatrix}
   2  & 0  & 2  \\
   1  & -3 & -2 \\
   -1 & 5  & 4
   \end{bmatrix}$

5. $\begin{bmatrix}
   3  & 4  & 0 \\
   -1 & -1 & 0 \\
   -2 & -4 & 0
   \end{bmatrix}$

6. $\begin{bmatrix}
   1 & 2 & -1 \\
   3 & 4 & -3 \\
   6 & 8 & -6
   \end{bmatrix} $

7. $\begin{bmatrix}
   -1 & 1  & -1 \\
   1  & -1 & 1  \\
   -1 & 1  & -1
   \end{bmatrix}$

8. $\begin{bmatrix}
   2  & 0  & 2  \\
   1  & -3 & -2 \\
   -1 & 5  & 4
   \end{bmatrix}$

9. $\begin{bmatrix}
   3  & 4  & 0 \\
   -1 & -1 & 0 \\
   -2 & -4 & 0
   \end{bmatrix} .$

:::

:::{note}
:class: [see-lecture]

Warto spojrzeć na {numref}`lec-11-ex-05`.
:::

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Punkt 3.
A = matrix(QQ, [[1, 0, 0], [4, -2, 2], [8, -6, 5]])
show("Macierz A:", A)
ew = A.eigenvalues()
show("Wartości własne:", ew)
show("Nieosobliwa (det != 0):", A.det() != 0)
for lam, E in A.eigenspaces_right():
    show("Przykładowa baza podprzestrzeni własnej dla λ = " + str(lam) + ": " + str(E.basis()))
show("Przykładowa baza jądra (ker A):", A.right_kernel().basis())
</script>
</div>
```
