AP

apply-linear-algebra-methods

Provides numerically stable algorithms for linear algebra tasks including matrix decomposition and eigenvalue problems.

Install

mkdir -p .claude/skills/apply-linear-algebra-methods && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16953" && unzip -o skill.zip -d .claude/skills/apply-linear-algebra-methods && rm skill.zip

Installs to .claude/skills/apply-linear-algebra-methods

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Use when solving systems of linear equations, decomposing matrices, analyzing transformations, or working with eigenvalues and eigenvectors in applied mathematics, data science, physics, or engineering contexts.
211 chars✓ has a “when” trigger
Advanced

Key capabilities

  • Identify problem structure before choosing an algorithm
  • Solve square systems of linear equations using LU decomposition
  • Solve overdetermined systems using QR decomposition for least squares
  • Compute eigendecomposition for symmetric and general matrices
  • Apply Singular Value Decomposition (SVD) for various applications
  • Interpret results in the context of the application

How it works

The skill guides the selection of numerically stable algorithms based on matrix properties, then applies Python's NumPy library to perform linear algebra operations.

Inputs & outputs

You give it
A matrix A and a vector b for Ax=b
You get back
Solution vector x, eigenvalues, eigenvectors, or SVD components

When to use apply-linear-algebra-methods

  • Solve linear equation systems
  • Decompose matrices
  • Compute eigenvalues
  • Perform numerical stability analysis

About this skill

Apply Linear Algebra Methods

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.

Why This Is Best Practice

Why best: Numerically stable decompositions (LU, QR, Cholesky, SVD) avoid the error amplification of naive approaches (explicit inversion, normal equations), and matching the algorithm to matrix structure (symmetric, sparse, overdetermined) is faster and more accurate than a one-size-fits-all method. 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).

Steps

1. Identify the problem structure before choosing an algorithm

The correct algorithm depends on matrix properties:

  • Is A square and non-singular? → Gaussian elimination with partial pivoting (LU decomposition)
  • Is A symmetric positive definite? → Cholesky decomposition (2× faster than LU; used in Kalman filter, covariance matrices)
  • Is A overdetermined (more equations than unknowns)? → Least squares via QR decomposition (NOT normal equations)
  • Do you need eigenvalues? → QR algorithm (symmetric: use symmetric QR; general: use Schur decomposition)
  • Is A sparse? → Sparse direct methods (UMFPACK, SuperLU) or iterative (Conjugate Gradient for SPD, GMRES for general)

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.

2. Solve Ax = b (square system)

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

3. Solve overdetermined system (least squares)

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.

4. Compute eigendecomposition

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]).

5. Apply Singular Value Decomposition (SVD)

SVD = the most generally applicable matrix decomposition: A = UΣVᵀ

U, sigma, Vt = np.linalg.svd(A, full_matrices=False)  # economy SVD

Applications:

  • PCA: principal components = columns of V; variance explained = σᵢ² / Σσⱼ²
  • Low-rank approximation: truncate to k singular values (image compression, latent semantic indexing)
  • Pseudoinverse: A⁺ = VΣ⁺Uᵀ (scipy.linalg.pinv uses this)
  • Rank determination: rank = number of singular values above threshold (σ > max(m,n) × σ_max × ε_machine)

6. Interpret results in context

Always connect results back to the application:

  • Eigenvalues of covariance matrix: variance explained per principal component
  • Condition number: sensitivity of solution to perturbations (rule of thumb: condition number ~10^k → lose k digits of accuracy)
  • Residual norm: fit quality of least squares solution
  • Singular values near zero: near-rank-deficiency; solution is not unique or is poorly determined

Common Mistakes

  • Using np.linalg.inv(A) to solve Ax=b: Explicit matrix inversion is slower and less accurate than solve(). Reserve it for when the inverse itself is the output.
  • Using np.linalg.eig instead of eigh for symmetric matrices: eig on symmetric matrices may return complex eigenvalues due to numerical noise; eigh guarantees real eigenvalues and is faster.
  • Ignoring the condition number: A condition number of 10¹² means 12 digits of input precision produce 0 accurate digits in the output. Check cond(A) before trusting results.

When NOT to Use

  • Systems too large for dense methods: for n > ~10,000, use sparse or iterative solvers (scipy.sparse.linalg) — dense methods scale as O(n³) and run out of memory.

When not to use it

  • When systems are too large for dense methods (n > ~10,000)
  • When explicit matrix inversion is used to solve Ax=b
  • When np.linalg.eig is used instead of eigh for symmetric matrices

Limitations

  • Dense methods scale as O(n³) and run out of memory for large systems
  • Explicit matrix inversion is slower and less accurate than solve()
  • Condition number > 1e8 means the result may have few accurate significant digits

How it compares

This skill provides a structured approach to selecting and applying appropriate linear algebra methods, emphasizing numerical stability and contextual interpretation over generic computations.

Compared to similar skills

apply-linear-algebra-methods side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
apply-linear-algebra-methods (this skill)01moNo flagsAdvanced
quant-analyst1033moNo flagsAdvanced
umap-learn62moReviewIntermediate
embedding-strategies83moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

quant-analyst

zenobi-us

Expert quantitative analyst specializing in financial modeling, algorithmic trading, and risk analytics. Masters statistical methods, derivatives pricing, and high-frequency trading with focus on mathematical rigor, performance optimization, and profitable strategy development.

103355

umap-learn

K-Dense-AI

UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D/3D visualization, clustering preprocessing (HDBSCAN), supervised/parametric UMAP, for high-dimensional data.

6100

embedding-strategies

wshobson

Select and optimize embedding models for semantic search and RAG applications. Use when choosing embedding models, implementing chunking strategies, or optimizing embedding quality for specific domains.

890

building-automl-pipelines

jeremylongshore

Build automated machine learning pipelines, including feature engineering, model selection, and performance evaluation.

688

model-compare

rawwerks

Compare 3D CAD models using boolean operations (IoU, Dice, precision/recall). Use when evaluating generated models against gold references, diffing CAD revisions, or computing similarity metrics for ML training. Triggers on: model diff, compare models, IoU, intersection over union, model similarity, CAD comparison, STEP diff, 3D evaluation, gold reference, generated model, precision recall 3D.

783

matchms

davila7

Mass spectrometry analysis. Process mzML/MGF/MSP, spectral similarity (cosine, modified cosine), metadata harmonization, compound ID, for metabolomics and MS data processing.

674

Search skills

Search the agent skills registry