Finite Horizon Lqr

Solving finite-horizon LQR via dynamic programming for MPC.

49 stars 5 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add UCSB-NLP-Chang/Skill-Usage --skill finite-horizon-lqr
Manual install
git clone --depth 1 https://github.com/UCSB-NLP-Chang/Skill-Usage.git /tmp/Skill-Usage
mkdir -p ~/.claude/skills
cp -r /tmp/Skill-Usage/tasks/r2r-mpc-control/environment/skills/finite-horizon-lqr ~/.claude/skills/finite-horizon-lqr

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# 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:
```python
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:
```python
u_k = -K_k @ x_k
x_{k+1} = A @ x_k + B @ u_k
```

## Python Implementation

```python
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:
1. Measure current state x
2. Solve finite-horizon LQR from x
3. Apply first control u_0
4. Repeat next timestep
Read the full skill on GitHub

Details

Skill name
finite-horizon-lqr
Path
tasks/r2r-mpc-control/environment/skills/finite-horizon-lqr/SKILL.md
Repo updated
8 April 2026

FAQ

What does the Finite Horizon Lqr skill do?

Solving finite-horizon LQR via dynamic programming for MPC.

How do I install the Finite Horizon Lqr skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add UCSB-NLP-Chang/Skill-Usage --skill finite-horizon-lqr. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Finite Horizon Lqr popular?

It lives in UCSB-NLP-Chang/Skill-Usage, which has 49 GitHub stars and 5 forks.

Related skills

Pubchem Database

49

UCSB-NLP-Chang/Skill-Usage

Query PubChem via PUG-REST API/PubChemPy (110M+ compounds). Search by name/CID/SMILES, retrieve properties, similarity/substructure searches, bioactivity, for cheminformatics.

Databases

Pymatgen

49

UCSB-NLP-Chang/Skill-Usage

Materials science toolkit. Crystal structures (CIF, POSCAR), phase diagrams, band structure, DOS, Materials Project integration, format conversion, for computational materials science.

Research & Science

Rdkit

49

UCSB-NLP-Chang/Skill-Usage

Cheminformatics toolkit for fine-grained molecular control. SMILES/SDF parsing, descriptors (MW, LogP, TPSA), fingerprints, substructure search, 2D/3D generation, similarity, reactions. For standard workflows with simpler interface, use datamol (wrapper around RDKit). Use rdkit for advanced control, custom sanitization, specialized algorithms.

Frontend & Design

Gamma Phase Associator

49

UCSB-NLP-Chang/Skill-Usage

An overview of the python package for running the GaMMA earthquake phase association algorithm. The algorithm expects phase picks data and station data as input and produces (through unsupervised clustering) earthquake events with source information like earthquake location, origin time and magnitude. The skill explains commonly used functions and the expected input/output format.

Software Development

Erlang Distribution

49

UCSB-NLP-Chang/Skill-Usage

Use when erlang distributed systems including node connectivity, distributed processes, global name registration, distributed supervision, network partitions, and building fault-tolerant multi-node applications on the BEAM VM.

Software Development

Gh CLI

49

UCSB-NLP-Chang/Skill-Usage

The gh CLI is GitHub's official command line tool for interacting with GitHub repositories, issues, pull requests, and more. When needs to interact with GitHub repositories, issues, pull requests, and more, use this skill.

Software Development

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.