Difference between revisions of "Linear algebra"

From Bitnami MediaWiki
Jump to navigation Jump to search
 
(50 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
& = a^2+2ab+b^2 \\
 
& = a^2+2ab+b^2 \\
 
\end{align}</math>
 
\end{align}</math>
 +
 +
MATLAB commands for Strang:
 +
* [L, U, P] = lu(A)
 +
* [Q, R] = qr(A)
 +
* [S, E] = eig(A)
  
 
===Basics===
 
===Basics===
Line 22: Line 27:
 
The dot product is actually a special case of the inner product (i.e., the inner product not restricted to vectors in <math>\R^3</math>)  
 
The dot product is actually a special case of the inner product (i.e., the inner product not restricted to vectors in <math>\R^3</math>)  
 
:::<math>\langle x, y\rangle \equiv x\cdot y\equiv x^Ty = \sum_i x_i y_i</math>
 
:::<math>\langle x, y\rangle \equiv x\cdot y\equiv x^Ty = \sum_i x_i y_i</math>
 +
* The '''outer product''' <math>|A\wedge B| = |A||B|\;|\sin\theta| </math>
 
The mapping from a vector space <math>\mathcal{V}</math> to <math>\R</math> has the following properties:
 
The mapping from a vector space <math>\mathcal{V}</math> to <math>\R</math> has the following properties:
 
# Nonnegativity and identity mapping: if <math>x\neq 0</math>, then <math>\langle x,x\rangle \gt 0</math> and <math>\langle 0,x \rangle = \langle x,0 \rangle = \langle 0,0 \rangle = 0 </math>
 
# Nonnegativity and identity mapping: if <math>x\neq 0</math>, then <math>\langle x,x\rangle \gt 0</math> and <math>\langle 0,x \rangle = \langle x,0 \rangle = \langle 0,0 \rangle = 0 </math>
Line 50: Line 56:
 
* A '''scaled''' vector : <math>x_s = \sqrt{n-1}\frac{x_c}{||x_c||} </math>
 
* A '''scaled''' vector : <math>x_s = \sqrt{n-1}\frac{x_c}{||x_c||} </math>
 
* A '''centered and scaled''' (aka "standardized") vector: <math> x_{cs} = \sqrt{n-1}\frac{x_c}{||x_c||}</math>
 
* A '''centered and scaled''' (aka "standardized") vector: <math> x_{cs} = \sqrt{n-1}\frac{x_c}{||x_c||}</math>
−
*
+
* The '''standard deviation''' is the multiplicative inverse of the scaling factor: <math>s_x = \frac{||x_c||}{\sqrt{n-1}}</math>
 +
* The square of the standard deviation is the '''variance''': <math>V(x) = s_x^2 = \frac{||x_c||^2}{n-1} </math>
 +
; Covariances and Correlations Between Vectors
 +
* For n-vectors x and y, their '''covariance''' is <math>\text{Cov}(x,y) = \dfrac{\langle x-\bar{x}, y -\bar{y}\rangle}{n-1} </math> where
 +
** <math>\text{Cov}(x+y,y) = \text{Cov}(x,y) + V(y)\quad</math> and
 +
** <math>\text{Cov}(x+a,y) = \text{Cov}(x,y) </math>
 +
 
 +
===Matrices===
 +
* The vector space generated by the columns of the <math>n\times m</math> matrix <math>A</math> is of order <math>n</math> and dimension <math>m</math> or less and is called the '''column space''' or range of <math>A</math>, denoted <math>\mathcal{V}(A)</math> or <math>\text{span}(A)</math>
 +
* The '''row space''' is the vector space of order <math>m</math> generated by the rows of <math>A</math>
 +
* Diagonals and other elements
 +
** '''diagonal''': composed of elements <math>a_{ii}</math> (aka ''principal diagonal elements'')
 +
** '''co-diagonals''': elements <math>a_{i, i+c_k}</math>
 +
** '''skew diagonals''': for <math>m</math> columns, the <math>a_{i,m+1-i}</math> elements
 +
** '''skew symmetric''': a matrix <math>A</math> such that <math>a_{ij} = -a_{ji}</math>. (Diagonal entries are 0.) Also means <math>-A = A^T</math>
 +
** '''Hermitian/self-adjoint''': <math>a_{ij} = \bar{a}_{ji}</math>, where <math>\bar{a}_{ji}</math> is the conjugate of complex <math>a</math>
 +
* The <math>\text{diag}(\cdot)</math> operator is a mapping from <math>\R^n\mapsto \R^{n\times n}:</math> and returns a a diagonal matrix with elements of the vector along the diagonal
 +
:::<math> \text{diag}((d_1,d_2,\dots,d_n)) =
 +
\begin{bmatrix}
 +
\,\,d_1 & \,0 & \cdots &  0\,\\
 +
\,\,0 & d_2 & \cdots & 0\,\\
 +
\,\,\vdots & & \ddots & \,\\
 +
\, \,0 & 0 & \cdots & d_n\,\\
 +
\end{bmatrix} </math>
 +
* The <math>\text{vecdiag}(\cdot)</math> function forms a vector from a matrix's principal diagonal elements. This is a mapping <math>\R^{n\times m}\mapsto \R^{\min(n,m)}</math>
 +
:::<math>\text{vecdiag}(A) = (a_{11}, \dots, a_{kk})</math>
 +
* Transposes: <math>(A+B)^T = A^T + B^T</math>
 +
 
 +
====Vector Spaces of Matrices====
 +
* Vector space of <math>n\times m</math> matrices is any set closed with respect to scalar multiplication, matrix addition (for conformable matrices), and has an additive identity. E.g., <math>\R^{n\times m}</math> is a vector space.
 +
* The vector space of <math>n\times n</math> symmetric matrices is a subspace of the vector space <math>\R^{n\times n}</math>. It has <math>n(n+1)/2</math> matrices in the basis
 +
* The sum of diagonal entries of a square matrix is the '''trace''': <math>\text{tr}(A) = \sum_i a_{ii} = \text{tr}(A^T)</math>
 +
* The '''determinant''' has a few important properties:
 +
::1) <math>\begin{align}|A| = \begin{vmatrix} a & b\\c & d \end{vmatrix}=ad-bc.\end{align}</math>
 +
::2) It is zero iff the matrix is singular and not invertible
 +
::3) It depends linearly on the first row of the matrix
 +
::4) <math>\text{det}(A+B) \neq \text{det}(A) + \text{det}(B) </math>
 +
::5) det(I) is one; determinant of any matrix with a zero row is 0.
 +
* The determinants of the <math>(n-1)\times (n-1)</math> submatrices of an <math>n\times n</math> matrix are its '''minors''': <math>|A\__{(i)(j)}|</math>. The sign for the minor of <math>a_{ij}</math> is <math>(-1)^{i+j}</math>. The '''cofactor''' is defined as the minor times its sign (a scalar): <math>a_{(ij)}=(-1)^{i+j}\,|A\__{(i)(j)}|</math>
 +
* The adjugate of a matrix is <math>\text{adj}(A) = (a_{(ji)})</math> and is a matrix of the cofactors of <math>A^T</math>
 +
* Matrix multiplication: for <math>A</math>, an <math>n\times m</math> matrix, and <math>B</math>, an <math>m\times  p</math> matrix:
 +
:::<math>AB=C</math> where each <math>c_{ij} = \sum_k a_{ik}b_{kj}</math>
 +
:::<math>\R^{n\times m} \times \R^{m\times p} \mapsto \R^{n\times p}</math>
 +
* If <math>AB</math> exists, then <math>B^TA^T = (AB)^T</math>
 +
* If <math>A</math> is <math>n\times m</math>: <math> I_nA = AI_m = A </math>
 +
* Permutation matrices swap rows and columns.
 +
:<math>P_\pi
 +
=
 +
\begin{bmatrix}
 +
\mathbf{e}_{\pi(1)} \\
 +
\mathbf{e}_{\pi(2)} \\
 +
\mathbf{e}_{\pi(3)} \\
 +
\mathbf{e}_{\pi(4)} \\
 +
\mathbf{e}_{\pi(5)}
 +
\end{bmatrix}
 +
=
 +
\begin{bmatrix}
 +
\mathbf{e}_{1} \\
 +
\mathbf{e}_{4} \\
 +
\mathbf{e}_{2} \\
 +
\mathbf{e}_{5} \\
 +
\mathbf{e}_{3}
 +
\end{bmatrix}
 +
=
 +
\begin{bmatrix}
 +
1 & 0 & 0 & 0 & 0 \\
 +
0 & 0 & 0 & 1 & 0 \\
 +
0 & 1 & 0 & 0 & 0 \\
 +
0 & 0 & 0 & 0 & 1 \\
 +
0 & 0 & 1 & 0 & 0
 +
\end{bmatrix}.
 +
</math>
 +
* Permuting both rows and columns often yields something like this, where <math>E_{\pi_1}</math> is a row permutation matrix and <math> E_{\pi_2}</math> permutes the columns
 +
::: <math>B=E_{\pi_1}A E_{\pi_2}</math>
 +
* Outer product, bilinear form, quadratic form: <math>xy^T, x^TAy, x^TAx</math>
 +
* '''Definiteness''': defined by sign of quadratic form
 +
** Nonnegative definite: <math>x^TAx\geq 0; \quad A\succeq 0.</math>
 +
** Positive definite: <math> x^TAx\gt 0; \quad A\succ 0. </math>
 +
 
 +
===Derivatives and Integrals===
 +
 
 +
 
 +
===Transformations and Factorizations===
 +
 
 +
 
 +
===Solution of Linear Systems===
 +
 
 +
 
 +
===Evaluation of Eigenvalues and Eigenvectors===
 +
 
 +
 
 +
===Special Matrices, Modeling and Data Analysis===
 +
 
 +
===Applications in Statistics===

Latest revision as of 03:56, 26 July 2021

Some Notes on Linear Algebra

[math]\displaystyle{ \begin{align} f(x) & = (a+b)^2 \\ & = a^2+2ab+b^2 \\ \end{align} }[/math]

MATLAB commands for Strang:

  • [L, U, P] = lu(A)
  • [Q, R] = qr(A)
  • [S, E] = eig(A)

Basics[edit]

  • Unit vector:
[math]\displaystyle{ e_i = (0,\dots,0,1,0,\dots,0) }[/math]
Order relations

Several ways to rank order vectors but no complete ordering works (vectors are only partially ordered). If for all corresponding elements [math]\displaystyle{ x_i }[/math] and [math]\displaystyle{ y_i }[/math] belonging to vectors [math]\displaystyle{ x, y }[/math], then: [math]\displaystyle{ x\gt y }[/math]

  • Partial ordering: if [math]\displaystyle{ x_i\geq y_i }[/math] then [math]\displaystyle{ x }[/math] is greater than or equal to [math]\displaystyle{ y }[/math]
  • W is a subset of V and operations in the 2 objects are the same: [math]\displaystyle{ \mathcal{W}\subseteq\mathcal{V} }[/math]
  • Intersection of 2 vector spaces of same order is a vector space; however, the union of 2 vector spaces is not necessarily a vector space (e.g., [math]\displaystyle{ v_1 + v_2 }[/math] may not be in [math]\displaystyle{ \mathcal{V}_1\cup\mathcal{V}_2) }[/math].
  • "Spaces of vectors" = a set of vectors of the same order together with the addition operator
  • For [math]\displaystyle{ \mathcal{V}_1, \mathcal{V}_2 }[/math] are disjoint vector spaces, their sum is the direct sum: [math]\displaystyle{ \mathcal{V}=\mathcal{V}_1\oplus\mathcal{V}_2 }[/math].
Cones
  • Set of vectors that contains all positive scalar multiples of any vector in the set is a cone
  • Set of vectors [math]\displaystyle{ V }[/math] is a convex cone if [math]\displaystyle{ \forall v_1, v_2 \in V }[/math] and [math]\displaystyle{ \forall a, b\geq 0 \implies av_1 + bv_2 \in V }[/math]
Inner Products

The dot product is actually a special case of the inner product (i.e., the inner product not restricted to vectors in [math]\displaystyle{ \R^3 }[/math])

[math]\displaystyle{ \langle x, y\rangle \equiv x\cdot y\equiv x^Ty = \sum_i x_i y_i }[/math]
  • The outer product [math]\displaystyle{ |A\wedge B| = |A||B|\;|\sin\theta| }[/math]

The mapping from a vector space [math]\displaystyle{ \mathcal{V} }[/math] to [math]\displaystyle{ \R }[/math] has the following properties:

  1. Nonnegativity and identity mapping: if [math]\displaystyle{ x\neq 0 }[/math], then [math]\displaystyle{ \langle x,x\rangle \gt 0 }[/math] and [math]\displaystyle{ \langle 0,x \rangle = \langle x,0 \rangle = \langle 0,0 \rangle = 0 }[/math]
  2. Commutativity: [math]\displaystyle{ \langle x,y\rangle = \langle y,x\rangle }[/math]
  3. Factoring of scalar multiplication in dot products: [math]\displaystyle{ \langle ax, y\rangle = a\langle x,y\rangle }[/math] for real [math]\displaystyle{ a }[/math]
  4. Relation of vector addition to dot product addition: [math]\displaystyle{ \langle x+y,z \rangle = \langle x,z\rangle + \langle x,z\rangle }[/math]
The Cauchy-Schwarz Inequality
[math]\displaystyle{ \langle x,y\rangle \leq \langle x,x\rangle^{\frac{1}{2}} \langle y,y\rangle^{\frac{1}{2}} }[/math]

Norms[edit]

A function [math]\displaystyle{ \parallel\cdot\parallel }[/math] from a set of objects [math]\displaystyle{ S }[/math] to [math]\displaystyle{ \R }[/math] satisfying 3 conditions

  1. Nonnegativity and identity mapping: [math]\displaystyle{ x\neq 0 \implies \parallel x\parallel \gt 0 }[/math] and [math]\displaystyle{ \parallel 0 \parallel = 0 }[/math]
  2. Relation of scalar multiplication to real multiplication: [math]\displaystyle{ \parallel ax\parallel = |a|\parallel x\parallel }[/math] for real [math]\displaystyle{ a }[/math]
  3. Triangle inequality: [math]\displaystyle{ \parallel x+y\parallel\; \leq\; \parallel x\parallel + \parallel y\parallel }[/math]

General case: [math]\displaystyle{ || x||_p = \left (\displaystyle\sum_i |x_i|^p\right ) ^{\frac{1}{p}} }[/math]

  • Manhattan: [math]\displaystyle{ ||x||_1 = \sum_i|x_i| }[/math]
  • Euclidean: [math]\displaystyle{ || x||_2 = \sqrt{\sum_i x_i^2} = \sqrt{\langle x,x\rangle} }[/math]
  • Chebyshev: [math]\displaystyle{ || x||_\infty = \max_i|x_i| }[/math] (take limit of the [math]\displaystyle{ L_p\; }[/math]/Minkowski norm)
  • Magnitude of the norm falls as [math]\displaystyle{ p }[/math] increases because you're taking a bigger root (1/p). More formally, [math]\displaystyle{ ||x||_p }[/math] is a non-increasing function of [math]\displaystyle{ p }[/math]
  • For any inner product space, a ([math]\displaystyle{ L_2 }[/math]) norm is induced by the inner product: [math]\displaystyle{ ||x|| = \sqrt{\langle x,x\rangle} }[/math]
  • Induced norm for the sum of two vectors: [math]\displaystyle{ ||x+y||^2 = ||x||^2 + ||y||^2 + 2\langle x,y\rangle }[/math]
  • Normalized vector: [math]\displaystyle{ \tilde{x} = \frac{1}{||x||}x }[/math]

Standard Deviation, Variance and Scaled Vectors[edit]

  • A centered vector is just one with the mean subtracted off: [math]\displaystyle{ x_c = x - \bar{x} }[/math]
  • A scaled vector : [math]\displaystyle{ x_s = \sqrt{n-1}\frac{x_c}{||x_c||} }[/math]
  • A centered and scaled (aka "standardized") vector: [math]\displaystyle{ x_{cs} = \sqrt{n-1}\frac{x_c}{||x_c||} }[/math]
  • The standard deviation is the multiplicative inverse of the scaling factor: [math]\displaystyle{ s_x = \frac{||x_c||}{\sqrt{n-1}} }[/math]
  • The square of the standard deviation is the variance: [math]\displaystyle{ V(x) = s_x^2 = \frac{||x_c||^2}{n-1} }[/math]
Covariances and Correlations Between Vectors
  • For n-vectors x and y, their covariance is [math]\displaystyle{ \text{Cov}(x,y) = \dfrac{\langle x-\bar{x}, y -\bar{y}\rangle}{n-1} }[/math] where
    • [math]\displaystyle{ \text{Cov}(x+y,y) = \text{Cov}(x,y) + V(y)\quad }[/math] and
    • [math]\displaystyle{ \text{Cov}(x+a,y) = \text{Cov}(x,y) }[/math]

Matrices[edit]

  • The vector space generated by the columns of the [math]\displaystyle{ n\times m }[/math] matrix [math]\displaystyle{ A }[/math] is of order [math]\displaystyle{ n }[/math] and dimension [math]\displaystyle{ m }[/math] or less and is called the column space or range of [math]\displaystyle{ A }[/math], denoted [math]\displaystyle{ \mathcal{V}(A) }[/math] or [math]\displaystyle{ \text{span}(A) }[/math]
  • The row space is the vector space of order [math]\displaystyle{ m }[/math] generated by the rows of [math]\displaystyle{ A }[/math]
  • Diagonals and other elements
    • diagonal: composed of elements [math]\displaystyle{ a_{ii} }[/math] (aka principal diagonal elements)
    • co-diagonals: elements [math]\displaystyle{ a_{i, i+c_k} }[/math]
    • skew diagonals: for [math]\displaystyle{ m }[/math] columns, the [math]\displaystyle{ a_{i,m+1-i} }[/math] elements
    • skew symmetric: a matrix [math]\displaystyle{ A }[/math] such that [math]\displaystyle{ a_{ij} = -a_{ji} }[/math]. (Diagonal entries are 0.) Also means [math]\displaystyle{ -A = A^T }[/math]
    • Hermitian/self-adjoint: [math]\displaystyle{ a_{ij} = \bar{a}_{ji} }[/math], where [math]\displaystyle{ \bar{a}_{ji} }[/math] is the conjugate of complex [math]\displaystyle{ a }[/math]
  • The [math]\displaystyle{ \text{diag}(\cdot) }[/math] operator is a mapping from [math]\displaystyle{ \R^n\mapsto \R^{n\times n}: }[/math] and returns a a diagonal matrix with elements of the vector along the diagonal
[math]\displaystyle{ \text{diag}((d_1,d_2,\dots,d_n)) = \begin{bmatrix} \,\,d_1 & \,0 & \cdots & 0\,\\ \,\,0 & d_2 & \cdots & 0\,\\ \,\,\vdots & & \ddots & \,\\ \, \,0 & 0 & \cdots & d_n\,\\ \end{bmatrix} }[/math]
  • The [math]\displaystyle{ \text{vecdiag}(\cdot) }[/math] function forms a vector from a matrix's principal diagonal elements. This is a mapping [math]\displaystyle{ \R^{n\times m}\mapsto \R^{\min(n,m)} }[/math]
[math]\displaystyle{ \text{vecdiag}(A) = (a_{11}, \dots, a_{kk}) }[/math]
  • Transposes: [math]\displaystyle{ (A+B)^T = A^T + B^T }[/math]

Vector Spaces of Matrices[edit]

  • Vector space of [math]\displaystyle{ n\times m }[/math] matrices is any set closed with respect to scalar multiplication, matrix addition (for conformable matrices), and has an additive identity. E.g., [math]\displaystyle{ \R^{n\times m} }[/math] is a vector space.
  • The vector space of [math]\displaystyle{ n\times n }[/math] symmetric matrices is a subspace of the vector space [math]\displaystyle{ \R^{n\times n} }[/math]. It has [math]\displaystyle{ n(n+1)/2 }[/math] matrices in the basis
  • The sum of diagonal entries of a square matrix is the trace: [math]\displaystyle{ \text{tr}(A) = \sum_i a_{ii} = \text{tr}(A^T) }[/math]
  • The determinant has a few important properties:
1) [math]\displaystyle{ \begin{align}|A| = \begin{vmatrix} a & b\\c & d \end{vmatrix}=ad-bc.\end{align} }[/math]
2) It is zero iff the matrix is singular and not invertible
3) It depends linearly on the first row of the matrix
4) [math]\displaystyle{ \text{det}(A+B) \neq \text{det}(A) + \text{det}(B) }[/math]
5) det(I) is one; determinant of any matrix with a zero row is 0.
  • The determinants of the [math]\displaystyle{ (n-1)\times (n-1) }[/math] submatrices of an [math]\displaystyle{ n\times n }[/math] matrix are its minors: [math]\displaystyle{ |A\__{(i)(j)}| }[/math]. The sign for the minor of [math]\displaystyle{ a_{ij} }[/math] is [math]\displaystyle{ (-1)^{i+j} }[/math]. The cofactor is defined as the minor times its sign (a scalar): [math]\displaystyle{ a_{(ij)}=(-1)^{i+j}\,|A\__{(i)(j)}| }[/math]
  • The adjugate of a matrix is [math]\displaystyle{ \text{adj}(A) = (a_{(ji)}) }[/math] and is a matrix of the cofactors of [math]\displaystyle{ A^T }[/math]
  • Matrix multiplication: for [math]\displaystyle{ A }[/math], an [math]\displaystyle{ n\times m }[/math] matrix, and [math]\displaystyle{ B }[/math], an [math]\displaystyle{ m\times p }[/math] matrix:
[math]\displaystyle{ AB=C }[/math] where each [math]\displaystyle{ c_{ij} = \sum_k a_{ik}b_{kj} }[/math]
[math]\displaystyle{ \R^{n\times m} \times \R^{m\times p} \mapsto \R^{n\times p} }[/math]
  • If [math]\displaystyle{ AB }[/math] exists, then [math]\displaystyle{ B^TA^T = (AB)^T }[/math]
  • If [math]\displaystyle{ A }[/math] is [math]\displaystyle{ n\times m }[/math]: [math]\displaystyle{ I_nA = AI_m = A }[/math]
  • Permutation matrices swap rows and columns.
[math]\displaystyle{ P_\pi = \begin{bmatrix} \mathbf{e}_{\pi(1)} \\ \mathbf{e}_{\pi(2)} \\ \mathbf{e}_{\pi(3)} \\ \mathbf{e}_{\pi(4)} \\ \mathbf{e}_{\pi(5)} \end{bmatrix} = \begin{bmatrix} \mathbf{e}_{1} \\ \mathbf{e}_{4} \\ \mathbf{e}_{2} \\ \mathbf{e}_{5} \\ \mathbf{e}_{3} \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 & 0 \end{bmatrix}. }[/math]
  • Permuting both rows and columns often yields something like this, where [math]\displaystyle{ E_{\pi_1} }[/math] is a row permutation matrix and [math]\displaystyle{ E_{\pi_2} }[/math] permutes the columns
[math]\displaystyle{ B=E_{\pi_1}A E_{\pi_2} }[/math]
  • Outer product, bilinear form, quadratic form: [math]\displaystyle{ xy^T, x^TAy, x^TAx }[/math]
  • Definiteness: defined by sign of quadratic form
    • Nonnegative definite: [math]\displaystyle{ x^TAx\geq 0; \quad A\succeq 0. }[/math]
    • Positive definite: [math]\displaystyle{ x^TAx\gt 0; \quad A\succ 0. }[/math]

Derivatives and Integrals[edit]

Transformations and Factorizations[edit]

Solution of Linear Systems[edit]

Evaluation of Eigenvalues and Eigenvectors[edit]

Special Matrices, Modeling and Data Analysis[edit]

Applications in Statistics[edit]