Matrici: Operazioni Base
Cheatsheet Content
### Definizione e Notazione Una matrice è una tabella rettangolare di numeri, simboli o espressioni, disposti in righe e colonne. - Una matrice $A$ di dimensione $m \times n$ ha $m$ righe e $n$ colonne. - Ogni elemento della matrice è indicato con $a_{ij}$, dove $i$ è l'indice di riga e $j$ è l'indice di colonna. **Esempio:** Una matrice $A$ $2 \times 3$: $$ A = \begin{pmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \end{pmatrix} $$ ### Tipi Speciali di Matrici #### Matrice Quadrata Una matrice con lo stesso numero di righe e colonne ($m=n$). **Esempio:** $$ B = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} $$ #### Matrice Identità Una matrice quadrata con 1 sulla diagonale principale e 0 altrove. È indicata con $I$. **Esempio:** $$ I_2 = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} $$ #### Matrice Nulla Una matrice con tutti gli elementi uguali a 0. **Esempio:** $$ O_{2 \times 2} = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix} $$ #### Matrice Trasposta La trasposta di una matrice $A$ (indicata $A^T$) si ottiene scambiando le righe con le colonne. Se $A = (a_{ij})$, allora $A^T = (a_{ji})$. **Esempio:** Se $A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}$, allora $A^T = \begin{pmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{pmatrix}$. #### Matrice Simmetrica Una matrice quadrata $A$ è simmetrica se $A = A^T$. Cioè, $a_{ij} = a_{ji}$ per tutti gli $i, j$. **Esempio:** $$ S = \begin{pmatrix} 1 & 2 & 3 \\ 2 & 4 & 5 \\ 3 & 5 & 6 \end{pmatrix} $$ #### Matrice Antisimmmetrica Una matrice quadrata $A$ è antisimmetrica se $A = -A^T$. Cioè, $a_{ij} = -a_{ji}$ per tutti gli $i, j$. Gli elementi sulla diagonale principale devono essere zero. **Esempio:** $$ K = \begin{pmatrix} 0 & 2 & -3 \\ -2 & 0 & 1 \\ 3 & -1 & 0 \end{pmatrix} $$ #### Matrice Diagonale Una matrice quadrata in cui tutti gli elementi al di fuori della diagonale principale sono zero. **Esempio:** $$ D = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \end{pmatrix} $$ #### Matrice Scalare Una matrice diagonale in cui tutti gli elementi sulla diagonale principale sono uguali. **Esempio:** $$ S = \begin{pmatrix} 5 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 5 \end{pmatrix} $$ #### Matrice Triangolare Superiore Una matrice quadrata in cui tutti gli elementi al di sotto della diagonale principale sono zero. **Esempio:** $$ U = \begin{pmatrix} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \end{pmatrix} $$ #### Matrice Triangolare Inferiore Una matrice quadrata in cui tutti gli elementi al di sopra della diagonale principale sono zero. **Esempio:** $$ L = \begin{pmatrix} 1 & 0 & 0 \\ 2 & 3 & 0 \\ 4 & 5 & 6 \end{pmatrix} $$ #### Matrice Idempotente Una matrice quadrata $A$ è idempotente se $A^2 = A$. **Esempio:** Sia $A = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}$. $$ A^2 = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} = \begin{pmatrix} 1 \cdot 1 + 0 \cdot 0 & 1 \cdot 0 + 0 \cdot 0 \\ 0 \cdot 1 + 0 \cdot 0 & 0 \cdot 0 + 0 \cdot 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} = A $$ #### Matrice Nilpotente Una matrice quadrata $A$ è nilpotente se esiste un intero positivo $k$ tale che $A^k = O$ (matrice nulla). Il più piccolo $k$ è l'indice di nilpotenza. **Esempio:** Sia $A = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}$. $$ A^2 = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} = \begin{pmatrix} 0 \cdot 0 + 1 \cdot 0 & 0 \cdot 1 + 1 \cdot 0 \\ 0 \cdot 0 + 0 \cdot 0 & 0 \cdot 1 + 0 \cdot 0 \end{pmatrix} = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix} = O $$ Quindi $A$ è nilpotente di indice 2. #### Matrice Involutoria Una matrice quadrata $A$ è involutoria se $A^2 = I$ (matrice identità). **Esempio:** Sia $A = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}$. $$ A^2 = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} = \begin{pmatrix} 1 \cdot 1 + 0 \cdot 0 & 1 \cdot 0 + 0 \cdot (-1) \\ 0 \cdot 1 + (-1) \cdot 0 & 0 \cdot 0 + (-1) \cdot (-1) \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I $$ #### Matrice Ortogonale Una matrice quadrata $A$ è ortogonale se $A A^T = A^T A = I$. Questo implica che $A^{-1} = A^T$. **Esempio:** Sia $A = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}$. $$ A^T = \begin{pmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{pmatrix} $$ $$ A A^T = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix} \begin{pmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{pmatrix} $$ $$ = \begin{pmatrix} \cos^2\theta + \sin^2\theta & \cos\theta\sin\theta - \sin\theta\cos\theta \\ \sin\theta\cos\theta - \cos\theta\sin\theta & \sin^2\theta + \cos^2\theta \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I $$ #### Matrice Unitaria (per numeri complessi) Una matrice quadrata $A$ con elementi complessi è unitaria se $A A^* = A^* A = I$, dove $A^*$ è la trasposta coniugata (o aggiunto hermitiano). **Esempio:** (Solo per completezza, non entreremo nel dettaglio degli esempi complessi) $$ A = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & i \\ i & 1 \end{pmatrix} $$ ### Operazioni tra Matrici #### 1. Somma di Matrici Per sommare due matrici $A$ e $B$, devono avere la stessa dimensione. Si sommano gli elementi corrispondenti. Se $A = (a_{ij})$ e $B = (b_{ij})$, allora $(A+B)_{ij} = a_{ij} + b_{ij}$. **Esempio:** Siano $A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$ e $B = \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}$. $$ A+B = \begin{pmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{pmatrix} = \begin{pmatrix} 6 & 8 \\ 10 & 12 \end{pmatrix} $$ #### 2. Sottrazione di Matrici Simile alla somma, le matrici devono avere la stessa dimensione. Si sottraggono gli elementi corrispondenti. Se $A = (a_{ij})$ e $B = (b_{ij})$, allora $(A-B)_{ij} = a_{ij} - b_{ij}$. **Esempio:** Siano $A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$ e $B = \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}$. $$ A-B = \begin{pmatrix} 1-5 & 2-6 \\ 3-7 & 4-8 \end{pmatrix} = \begin{pmatrix} -4 & -4 \\ -4 & -4 \end{pmatrix} $$ #### 3. Moltiplicazione per uno Scalare Per moltiplicare una matrice $A$ per uno scalare $c$, si moltiplica ogni elemento della matrice per $c$. Se $A = (a_{ij})$, allora $(cA)_{ij} = c \cdot a_{ij}$. **Esempio:** Sia $A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$ e $c=2$. $$ 2A = \begin{pmatrix} 2 \cdot 1 & 2 \cdot 2 \\ 2 \cdot 3 & 2 \cdot 4 \end{pmatrix} = \begin{pmatrix} 2 & 4 \\ 6 & 8 \end{pmatrix} $$ #### 4. Prodotto tra Matrici Il prodotto tra due matrici $A$ e $B$ ($AB$) è definito solo se il numero di colonne di $A$ è uguale al numero di righe di $B$. Se $A$ è una matrice $m \times p$ e $B$ è una matrice $p \times n$, allora il loro prodotto $C = AB$ sarà una matrice $m \times n$. L'elemento $c_{ij}$ della matrice prodotto $C$ si calcola moltiplicando gli elementi della $i$-esima riga di $A$ per gli elementi della $j$-esima colonna di $B$ e sommandoli. $c_{ij} = (i \text{-esima riga di } A) \cdot (j \text{-esima colonna di } B)$ $c_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \dots + a_{ip}b_{pj}$ **Esempio:** Siano $A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$ ($2 \times 2$) e $B = \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}$ ($2 \times 2$). Il prodotto $C = AB$ sarà una matrice $2 \times 2$. Per $c_{11}$: (prima riga di A) $\cdot$ (prima colonna di B) $c_{11} = (1 \cdot 5) + (2 \cdot 7) = 5 + 14 = 19$ Per $c_{12}$: (prima riga di A) $\cdot$ (seconda colonna di B) $c_{12} = (1 \cdot 6) + (2 \cdot 8) = 6 + 16 = 22$ Per $c_{21}$: (seconda riga di A) $\cdot$ (prima colonna di B) $c_{21} = (3 \cdot 5) + (4 \cdot 7) = 15 + 28 = 43$ Per $c_{22}$: (seconda riga di A) $\cdot$ (seconda colonna di B) $c_{22} = (3 \cdot 6) + (4 \cdot 8) = 18 + 32 = 50$ Quindi, $C = AB = \begin{pmatrix} 19 & 22 \\ 43 & 50 \end{pmatrix}$. **Attenzione:** Il prodotto di matrici non è commutativo, cioè $AB \neq BA$ in generale. ### Determinante Il determinante è un valore scalare associato a una matrice quadrata. È fondamentale per calcolare l'inversa di una matrice. #### Matrice $2 \times 2$ Se $A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}$, allora $\det(A) = ad - bc$. **Esempio:** Sia $A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$. $\det(A) = (1 \cdot 4) - (2 \cdot 3) = 4 - 6 = -2$. #### Matrice $3 \times 3$ (Regola di Sarrus) Se $A = \begin{pmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{pmatrix}$, allora: $\det(A) = a_{11}(a_{22}a_{33} - a_{23}a_{32}) - a_{12}(a_{21}a_{33} - a_{23}a_{31}) + a_{13}(a_{21}a_{32} - a_{22}a_{31})$. Un modo semplice per ricordarlo è la Regola di Sarrus: $$ \begin{vmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{vmatrix} = (a_{11}a_{22}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{21}a_{32}) - (a_{13}a_{22}a_{31} + a_{11}a_{23}a_{32} + a_{12}a_{21}a_{33}) $$ **Esempio:** Sia $A = \begin{pmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{pmatrix}$. $\det(A) = (1 \cdot 1 \cdot 0 + 2 \cdot 4 \cdot 5 + 3 \cdot 0 \cdot 6) - (3 \cdot 1 \cdot 5 + 1 \cdot 4 \cdot 6 + 2 \cdot 0 \cdot 0)$ $\det(A) = (0 + 40 + 0) - (15 + 24 + 0)$ $\det(A) = 40 - 39 = 1$. ### Matrice Inversa Una matrice quadrata $A$ ha un'inversa $A^{-1}$ se e solo se $\det(A) \neq 0$. L'inversa soddisfa la proprietà $AA^{-1} = A^{-1}A = I$ (matrice identità). #### Matrice $2 \times 2$ Se $A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}$ e $\det(A) \neq 0$, allora: $$ A^{-1} = \frac{1}{\det(A)} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix} $$ **Esempio:** Sia $A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$. Abbiamo calcolato $\det(A) = -2$. $$ A^{-1} = \frac{1}{-2} \begin{pmatrix} 4 & -2 \\ -3 & 1 \end{pmatrix} = \begin{pmatrix} -2 & 1 \\ 3/2 & -1/2 \end{pmatrix} $$ **Verifica (facoltativa, per capire meglio):** $$ A A^{-1} = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \begin{pmatrix} -2 & 1 \\ 3/2 & -1/2 \end{pmatrix} = \begin{pmatrix} (1)(-2)+(2)(3/2) & (1)(1)+(2)(-1/2) \\ (3)(-2)+(4)(3/2) & (3)(1)+(4)(-1/2) \end{pmatrix} $$ $$ = \begin{pmatrix} -2+3 & 1-1 \\ -6+6 & 3-2 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I $$