---
title: "Macierze"
lecture_number: 10
has_solutions: true
has_exercises: true
file_format: mystnb
kernelspec:
  name: sagemath
  display_name: SageMath
---

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

# Macierze

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

</script>
</div>
```

## Zadania na zajęcia

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

Dla macierzy:

:::{container} columns-3-auto

$$
A = \begin{bmatrix}
 1  & -1 & 2  \\
 -2 & 2  & -4
\end{bmatrix}
$$

$$
B = \begin{bmatrix}
 -1 & 3 & 4
\end{bmatrix}
$$

$$
C = \begin{bmatrix}
 2 & -1 & 2 \\
 2 & -1 & 2
\end{bmatrix}^T
$$

$$
D =
\begin{bmatrix}
2  & 1  \\
-2 & -1
\end{bmatrix}
$$

:::

- wypisz wszystkie pary macierzy, które można pomnożyć;
- oblicz $ A\cdot I_3,\quad B\cdot B^T,\quad B^T\cdot B,\quad D\cdot A,\quad \left(B C D A A^T D^T C^T B^T\right)^T.$

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

Warto spojrzeć na {numref}`lec-08-ex-02`, {numref}`lec-08-ex-03`.
:::

::::

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

Niech $A,B\in \MSet{7}{7}{\cc},\ \det A = -j,\ \det B = j+1  .$

Powołując się na odpowiednie własności mnożenia macierzy i wyznacznika, oblicz

```{math}
\det \left(2^{-1}\left(A^4\cdot B^3\right)^T\cdot \left(B^T\right)^{2019}\right).
```

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

Warto spojrzeć na {numref}`lec-09-ex-01`.
:::

::::

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

body_01 = DisplayMatrix(matrix([[1, 11, 111, 1111], [2, 21, 221, 2221], [3, 31, 331, 3331], [4, 41, 441, 4441]]))
content = rf"""
   {body_01}
"""
glue('sageglue_10_7', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)

body_01 = DisplayMatrix(matrix([[1, 11, 111, 1111], [2, 22, 221, 2221], [3, 31, 333, 3331], [4, 41, 441, 4444]]))
content = rf"""
   {body_01}
"""
glue('sageglue_10_8', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

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

Oblicz wyznacznik macierzy:

:::{container} columns-2-auto

1. ${[m^{n-1}]_{m=1,}^{3}}_{n=1}^{3}$

2. $\begin{bmatrix}
   14  & 5 +3\pi  & 33  \\
   -21 & -5 -4\pi & -44 \\
   -7  & 25+ 2\pi & 22
   \end{bmatrix}$

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

4. {glue:}`sageglue_10_7`

5. {glue:}`sageglue_10_8`

6. $\begin{bmatrix}
   1   & 1   & 1   & x+1 \\
   2   & x+2 & 2   & 2   \\
   3   & 3   & x+3 & 3   \\
   x+4 & 4   & 4   & 4
   \end{bmatrix} \ .$

:::

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

Warto spojrzeć na {numref}`lec-09-ex-02`, {numref}`lec-09-ex-03`.
:::

::::

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

Wyznacz rząd macierzy:

:::{container} columns-2-auto

1. $\begin{bmatrix}
2  & 3  & 4  & 5  & 6  & 7  \\
7  & 6  & 5  & 4  & 3  & 2  \\
12 & 13 & 14 & 15 & 16 & 17 \\
17 & 16 & 15 & 14 & 13 & 12
\end{bmatrix} $

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

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

:::

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

Warto spojrzeć na {numref}`lec-09-ex-04`.
:::

::::

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

Wyznacz rząd macierzy w zależności od parametru $p\in \rr$:

:::{container} columns-2-auto

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

2. $\begin{bmatrix}
1  & 1 + 2 p  & 2  & 7 p  \\
2  & 2 + p& 4  & 7 + p\\
-1 & -1 + 2 p & -2 & -4 + 5 p \\
\end{bmatrix}\ .$

:::

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

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

::::

## Zadania domowe

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

Niech

:::{container} columns-3-auto

$$
A = \left[
  \begin{array}{rrr}
   1  & 2 & 3 \\
   -2 & 0 & 4
   \end{array}
\right]
$$

$$
B = \left[
   \begin{array}{rrr}
   1 & 0 & -3
   \end{array}
\right]
$$

$$
C = \left[
  \begin{array}{rr}
   3  & 5 \\
   2  & 1 \\
   -1 & 2
   \end{array}
\right]
$$

$$
D = \left[
  \begin{array}{rr}
   1  & 0 \\
   -2 & 3
   \end{array}
\right].
$$

:::

Jeśli to możliwe, oblicz:
$I_2\cdot A,\quad
B\cdot C,\quad
B\cdot C^T,\quad
A\cdot D,\quad
D\cdot A,\quad
D\cdot(2A+C^T),\quad
B^2,\quad
B\cdot B^T,\quad
B^T\cdot B,\quad D^2 .$

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

Warto spojrzeć na {numref}`lec-08-ex-02`, {numref}`lec-08-ex-03`.
:::

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Macierze z zadania
A = matrix(QQ, [[1, 2, 3], [-2, 0, 4]])
B = matrix(QQ, [[1, 0, -3]])
C = matrix(QQ, [[3, 5], [2, 1], [-1, 2]])
D = matrix(QQ, [[1, 0], [-2, 3]])
show("A =", A)
show("B =", B)
show("C =", C)
show("D =", D)
# trzy obliczenia (z podanych w zadaniu)
show("I_2 * A =", identity_matrix(QQ, 2) * A)
show("B * C =", B * C)
show("D * (2A + C^T) =", D * (2*A + C.transpose()))
</script>
</div>
```

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

Niech $A,B\in \MSet{8}{8}{\cc}$,\ $\det A = 1-j,\ \det B = \sqrt{3}+j .$
Powołując się na
odpowiednie własności mnożenia macierzy i wyznacznika, oblicz

```{math}
\det \left(2\cdot A^4\cdot \left(B^T\right)^{7}\right).
```

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

Warto spojrzeć na {numref}`lec-09-ex-01`.
:::

::::

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

Oblicz wyznacznik macierzy:

:::{container} columns-2-auto

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

2. $\left[(i+j-2)!\right]_{4 \times 4}$

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

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

:::

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

Warto spojrzeć na {numref}`lec-09-ex-02`, {numref}`lec-09-ex-03`.
:::

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Punkt 2. — macierz [(i+j-2)!] dla i,j = 1..4
M = matrix(4, 4, lambda i, j: factorial(i + j))
show("Macierz [(i+j-2)!]_{4x4}:", M)
show("Wyznacznik:", M.det())
</script>
</div>
```

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

Wyznacz rząd macierzy:

:::{container} columns-2-auto

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

2. $\begin{bmatrix}
1 & 2  & -1 & 2  & 5  & 7  \\
5 & 10 & -5 & -6 & 25 & 0  \\
8 & 16 & -8 & 7  & 3  & 21 \\
1 & 2  & -1 & -4 & 11 & -5 \\
1 & 2  & -1 & -1 & 8  & -4
\end{bmatrix}$

3. $\begin{bmatrix}
1  & 2  & 2  & -2 & 9  \\
5  & 10 & -6 & 6  & 13 \\
8  & 16 & 7  & -7 & 27 \\
-4 & -8 & 3  & -3 & -5
\end{bmatrix}$

4. $\begin{bmatrix}
2  & -1 & 1   & 2  & 7  & 0  \\
10 & -5 & -11 & -6 & 19 & -8 \\
16 & -8 & -1  & 7  & 10 & 14 \\
2  & -1 & -5  & -4 & 7  & -6 \\
2  & -1 & -2  & -1 & 7  & -3
\end{bmatrix}.$

:::

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

Warto spojrzeć na {numref}`lec-09-ex-04`.
:::

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Punkt 2. — rząd macierzy
M = matrix(QQ, [[1, 2, -1, 2, 5, 7], [5, 10, -5, -6, 25, 0], [8, 16, -8, 7, 3, 21], [1, 2, -1, -4, 11, -5], [1, 2, -1, -1, 8, -4]])
show("Macierz:", M)
show("Rząd macierzy:", M.rank())
</script>
</div>
```

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

Wyznacz rząd macierzy w zależności o parametru $p\in \rr$:

:::{container} columns-2-auto

1. $\begin{bmatrix}
p   & p^2 & p^3 \\
p-1 & (p-1)^2 & (p-1)^3 \\
p+1 & (p+1)^2 & (p+1)^3 \\
\end{bmatrix}$

2. $\begin{bmatrix}
1  & 1 + 2 p  & 2  & 7 p  \\
2  & 2 + p& 4  & 7 + p\\
-1 & -1 + 2 p & -2 & -4 + 5 p \\
\end{bmatrix} .$

:::

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

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

::::

```{raw} html
<div class="sagecell-widget sagecell-exercise">
<script type="text/x-sage">
# Punkt 1. — rząd macierzy w zależności od parametru p
var('p')
M = matrix(SR, [[p, p^2, p^3], [p-1, (p-1)^2, (p-1)^3], [p+1, (p+1)^2, (p+1)^3]])
show("Macierz:", M)
show("Wyznacznik (rozłożony):", M.det().factor())
show("Dla p równego " + ", ".join(str(val) for val, _ in M.det().roots()) + " rząd równy 3")
# analiza rzędu dla przykładowych wartości p
for val, _ in M.det().roots():
    show("p = " + str(val) + " rząd równy " + str(M.subs(p=val).rank()))
</script>
</div>
```
