From grimoire
Solves linear systems, decomposes matrices (LU, Cholesky, QR, SVD), and computes eigenvalues using numerically stable algorithms. Useful in data science, physics, and engineering contexts.
How this skill is triggered — by the user, by Claude, or both
Slash command
/grimoire:apply-linear-algebra-methodsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Solve linear systems, decompose matrices, and compute eigenstructures using numerically stable algorithms — selecting the right decomposition for the problem structure (sparse, symmetric, overdetermined) and interpreting results in the application context.
Solve linear systems, decompose matrices, and compute eigenstructures using numerically stable algorithms — selecting the right decomposition for the problem structure (sparse, symmetric, overdetermined) and interpreting results in the application context.
Adopted by: Linear algebra is the computational foundation of NumPy/SciPy (Python), MATLAB, R, Julia, and every numerical computing library. Google's PageRank, PCA in data science, finite element analysis in engineering, quantum mechanics, and computer graphics all reduce to matrix operations. LAPACK (Linear Algebra PACKage) is the authoritative numerical library used by all major scientific software. Impact: Strang (2016) is the most widely used undergraduate linear algebra textbook globally, with MIT OpenCourseWare making it freely accessible. The eigenvalue problem — and its numerical solution via QR algorithm — underlies Google PageRank, principal component analysis, and quantum mechanics. Golub & Van Loan (2013) quantify the backward stability properties of major algorithms: unstable methods (e.g., normal equations for least squares) amplify errors quadratically vs. numerically stable methods (QR decomposition).
The correct algorithm depends on matrix properties:
Never use A⁻¹ explicitly to solve Ax=b — compute factorization and solve via back-substitution. Computing the inverse is 3× more expensive and numerically less stable.
Standard approach: LU decomposition with partial pivoting:
import numpy as np
# WRONG: x = np.linalg.inv(A) @ b (never do this)
# RIGHT:
x = np.linalg.solve(A, b) # uses LU under the hood
Check solution quality:
residual = np.linalg.norm(A @ x - b) / np.linalg.norm(b)
# Should be < 1e-10 for well-conditioned A; larger → ill-conditioned
cond_A = np.linalg.cond(A)
# Condition number > 1e8 → result may have few accurate significant digits
For Ax ≈ b with A ∈ ℝᵐˣⁿ, m > n (more data points than unknowns):
# QR decomposition approach (numerically stable):
x, residuals, rank, sv = np.linalg.lstsq(A, b, rcond=None)
# Direct QR:
Q, R = np.linalg.qr(A)
x = np.linalg.solve(R, Q.T @ b)
Never use normal equations (Aᵀx = Aᵀb, solved as x = (AᵀA)⁻¹Aᵀb) — condition number squares, amplifying errors.
For symmetric (Hermitian) matrix A = QΛQᵀ:
eigenvalues, eigenvectors = np.linalg.eigh(A) # eigh for symmetric (faster, real eigenvalues)
# eigenvalues sorted ascending; eigenvectors are columns of output
For general square matrix A = PDP⁻¹ (if diagonalizable):
eigenvalues, eigenvectors = np.linalg.eig(A)
Check: verify Av ≈ λv for each eigenpair (A @ eigenvectors[:,i] ≈ eigenvalues[i] * eigenvectors[:,i]).
SVD = the most generally applicable matrix decomposition: A = UΣVᵀ
U, sigma, Vt = np.linalg.svd(A, full_matrices=False) # economy SVD
Applications:
Always connect results back to the application:
npx claudepluginhub jeffreytse/grimoire --plugin grimoireImplements numerical methods: floating-point (IEEE 754, Kahan summation), matrix ops (LU/QR/SVD, sparse), root finding (Newton/Brent), integration (Simpson/Gaussian), FFT/NTT, crypto (SHA-256/AES-GCM). For numerical comp, signals, matrices, crypto.
Provides complete CBLAS/LAPACKE API reference for LAPACK v3.12.1 covering 1284 BLAS/LAPACK functions for numerical linear algebra in C/C++: matrix ops, solvers, eigenvalues, SVD. Use for API lookup, code generation, linking, solver selection.
Performs symbolic math in Python with SymPy: exact algebra, calculus (derivatives, integrals, limits), equation solving, symbolic matrices, ODEs, code generation (lambdify to NumPy/C/Fortran). Use for precise results over numerical approx.