finite-horizon-lqr
An analytical skill for solving finite-horizon LQR control problems within dynamic programming contexts.
Install
mkdir -p .claude/skills/finite-horizon-lqr && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1409" && unzip -o skill.zip -d .claude/skills/finite-horizon-lqr && rm skill.zipInstalls to .claude/skills/finite-horizon-lqr
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.
Solving finite-horizon LQR via dynamic programming for MPC.Key capabilities
- →Formulate finite-horizon cost minimization problems
- →Perform backward Riccati recursion for optimal gain calculation
- →Execute forward simulation for state trajectory prediction
- →Compute optimal control sequences for MPC applications
How it works
The skill solves the finite-horizon LQR problem by performing a backward pass to compute optimal gain matrices followed by a forward pass to determine control inputs.
Inputs & outputs
When to use finite-horizon-lqr
- →Calculating optimal control sequences
- →Implementing MPC controller logic
- →Dynamic programming for robotics control
About this skill
Finite-Horizon LQR for MPC
Problem Formulation
Minimize cost over horizon N:
J = Σ(k=0 to N-1) [x'Qx + u'Ru] + x_N' P x_N
Backward Riccati Recursion
Initialize: P_N = Q (or LQR solution for stability)
For k = N-1 down to 0:
K_k = inv(R + B'P_{k+1}B) @ B'P_{k+1}A
P_k = Q + A'P_{k+1}(A - B @ K_k)
Forward Simulation
Starting from x_0:
u_k = -K_k @ x_k
x_{k+1} = A @ x_k + B @ u_k
Python Implementation
def finite_horizon_lqr(A, B, Q, R, N, x0):
nx, nu = A.shape[0], B.shape[1]
K = np.zeros((nu, nx, N))
P = Q.copy()
# Backward pass
for k in range(N-1, -1, -1):
K[:,:,k] = np.linalg.solve(R + B.T @ P @ B, B.T @ P @ A)
P = Q + A.T @ P @ (A - B @ K[:,:,k])
# Return first control
return -K[:,:,0] @ x0
MPC Application
At each timestep:
- Measure current state x
- Solve finite-horizon LQR from x
- Apply first control u_0
- Repeat next timestep
When not to use it
- →Infinite-horizon control problems
- →Non-linear system dynamics without linearization
Limitations
- →Assumes linear system dynamics
- →Requires defined horizon N
How it compares
This method automates the dynamic programming recursion process, replacing manual derivation and iterative calculation of control gains.
Compared to similar skills
finite-horizon-lqr side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| finite-horizon-lqr (this skill) | 3 | 6mo | No flags | Advanced |
| quant-analyst | 103 | 2mo | No flags | Advanced |
| umap-learn | 6 | 2mo | Review | Intermediate |
| embedding-strategies | 8 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by benchflow-ai
View all by benchflow-ai →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.
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.
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.
building-automl-pipelines
jeremylongshore
Build automated machine learning pipelines, including feature engineering, model selection, and performance evaluation.
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.
matchms
davila7
Mass spectrometry analysis. Process mzML/MGF/MSP, spectral similarity (cosine, modified cosine), metadata harmonization, compound ID, for metabolomics and MS data processing.