create latex lecture slides from this cheatsheet with colorful highligthing and proper…
- User
create latex lecture slides from this cheatsheet with colorful highligthing and proper math typesetting, alongside code:
\documentclass{article} \usepackage{amsmath} \usepackage{amssymb} \usepackage{enumitem}
\title{R Linear Algebra Cheatsheet} \author{} \date{}
\begin{document} \maketitle
\section*{Matrix Decompositions} \begin{enumerate}[label=\textbf{\arabic*.}] \item \textbf{LU Decomposition:} Used when A is a square matrix and det != 0. \begin{verbatim}
LU decomposition A = LU det(A) != 0 && nrow(A) == ncol(A) 1.110223e-14 == 0 library(pracma) L = lu(A)U
y = forwardsolve(L, b) solve(U, y) \end{verbatim}
\item \textbf{Cholesky Decomposition:} Used when A is a square symmetric, positive-definite matrix. \begin{verbatim}
Cholesky decomposition A = Lt(L) nrow(A) == ncol(A) && all(A == t(A)) && all(eigen(A)$values > 0) C = chol(A) C # gornotrojkątna tC = t(C) # dolnotrojkatna
y = forwardsolve(tC, b) x = backsolve(C, y) \end{verbatim}
\item \textbf{QR Decomposition:} Used for full-rank matrices, rectangular and square. \begin{verbatim}
QR decomposition qr(A)$rank == ncol(A) A = QR QR = qr(A)
simpler, but doesn't demonstrate our understanding = solve.qr(QR, b) Q = qr.Q(QR) R = qr.R(QR)
x = backsolve(R, t(Q) %*% b) \end{verbatim}
\item \textbf{Singular Value Decomposition (SVD):} Used for general matrix decompositions, e.g. not full-rank rectangular matrices. \begin{verbatim}
SVD A = UEV* a_svd = svd(A)
a_diag = diag(1/a_svdv %% a_diag %% t(a_svd$u) %*% b \end{verbatim} \end{enumerate}
- Assistant