# Mpc Horizon Tuning

> Selecting MPC prediction horizon and cost matrices for web handling. Use when this capability is needed.

- Skill: `tomevault-io/mpc-horizon-tuning` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/mpc-horizon-tuning`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/mpc-horizon-tuning/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/mpc-horizon-tuning

---


# MPC Tuning for Tension Control

## Prediction Horizon Selection

**Horizon N** affects performance and computation:
- Too short (N < 5): Poor disturbance rejection
- Too long (N > 20): Excessive computation
- Rule of thumb: N ≈ 2-3× settling time / dt

For R2R systems with dt=0.01s: **N = 5-15** typical

## Cost Matrix Design

**State cost Q**: Emphasize tension tracking
```python
Q_tension = 100 / T_ref²  # High weight on tensions
Q_velocity = 0.1 / v_ref²  # Lower weight on velocities
Q = diag([Q_tension × 6, Q_velocity × 6])
```

**Control cost R**: Penalize actuator effort
```python
R = 0.01-0.1 × eye(n_u)  # Smaller = more aggressive
```

## Trade-offs

| Higher Q | Effect |
|----------|--------|
| Faster tracking | More control effort |
| Lower steady-state error | More aggressive transients |

| Higher R | Effect |
|----------|--------|
| Smoother control | Slower response |
| Less actuator wear | Higher tracking error |

## Terminal Cost

Use LQR solution for terminal cost to guarantee stability:
```python
P = solve_continuous_are(A, B, Q, R)
```

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/benchflow-ai) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->

