This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org
Python Viv

vp.control.simulate

The nonlinear cart-pole under the state feedback u = -K s, from the state s0 for steps steps of dt (fourth-order Runge-Kutta, the force held over each step). One row per time: t, x, xdot, theta, thetadot, u.

Part of the distribution vipyr; it runs from a checkout of the repository. Planned on PyPI as pip install vipyr.

Signature

vp.control.simulate(K, s0, dt, steps)

Parameters

K : ndarray[float64], required
s0 : ndarray[float64], required
dt : float, required
steps : int, required

Returns

A frozen SimulateResult. Iterating it gives the fields below in order; it also has params, tests, log and check().

trajectory : ndarray[float64]
One row per time step: t, x, xdot, theta, thetadot, u (seconds, meters, radians, newtons).

Raises

TypeError
An argument of the wrong type, or an unknown keyword.
vipyr.VivBuildError
An ImportError: no C compiler, or the program's C does not build.

Examples

import numpy as np
import vipyr as vp
A, B = vp.control.cartpole_model(h=1e-5)
K = vp.control.lqr(A=A, B=B, Q=np.diag([1.0, 1.0, 20.0, 1.0]), R=np.array([[0.05]])).K
r = vp.control.simulate(K=K.ravel(), s0=np.array([0.0, 0.0, np.radians(25), 0.0]), dt=0.01, steps=600)
print(r.trajectory.shape, abs(r.trajectory[-1, 3]) < 1e-3)   # 6 s later the pole is upright
assert r.check()
(601, 6) True

Each example ran as written when these pages were generated, and the output shown is what it printed.

Checked against

Reference
The cart-pole post's closed loop: from 25 degrees under its LQR gains the pole ends within 0.00096 rad of upright after 6 s (posts/2026-09-22-lqr-balances-the-cart-pole.viv).

Source