\title{R Linear Algebra Cheatsheet}
\author{}
\date{}
\begin{document}
\maketitle
\section*{Solving Linear Equations}
To solve a system of linear equations Ax = b
:
\begin{verbatim}
Define matrix A and vector b
A = matrix(c(…), nrow=…, ncol=…)
b = c(…)
Solve for x
x = solve(A, b)
\end{verbatim}
\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)LU=lu(A)U
y = forwardsolve(L, b)
solve(U, y)
\end{verbatim}
code
\item \textbf{Cholesky Decomposition:} Used when A is a square symmetric, positive-definite matrix.
\section*{Rozwiązywanie równań liniowych}
Aby rozwiązać układ równań liniowych Ax = b:
\begin{verbatim}
Zdefiniuj macierz A i wektor b
A = matrix(c(…), nrow=…, ncol=…)
b = c(…)
Rozwiąż równanie dla x
x = solve(A, b)
\end{verbatim}
\section*{Dekompozycje macierzy}
\begin{enumerate}[label=\textbf{\arabic*.}]
\item \textbf{Dekompozycja LU:} Używana, gdy A jest macierzą kwadratową i det != 0.
\begin{verbatim}
Dekompozycja LU
A = LU
det(A) != 0 && nrow(A) == ncol(A)
1.110223e-14 == 0
library(pracma)
L = lu(A)LU=lu(A)U
y = forwardsolve(L, b)
solve(U, y)
\end{verbatim}
code
\item \textbf{Dekompozycja Cholesky'ego:} Używana, gdy A jest macierzą kwadratową symetryczną i dodatnio określoną.