
Check a gain margin by hand
The frequency response, the Routh array and rlocus all give a gain margin of 3.
Model a system with tf or ss, plot its frequency response with bode and nyquist, and design a controller with rlocus and lqr.

Loop design usually starts with paying for a control toolbox, or waiting for a shared license. tf, bode, rlocus, step and lqr are part of the RunMat runtime next to the core math functions, free for individuals, education, research and smaller companies.
RuntimeRetuning a loop by hand means redrawing the Bode, step and root locus plots one at a time. Change a pole, a zero or a gain in the script and run it again, and every plot made from that transfer function is redrawn from the new model.
Desktop appCopying gains from a design tool into a separate simulation invites typos. Pass the gain from lqr to ode45 in the same script to simulate the closed loop, including a nonlinear model of the plant.
Differential equationsA controller change that eats into the phase margin can go unnoticed until hardware test. runmat test runs the design script in CI with no license server to activate, so the pull request fails when a margin check fails.
CLI, CI and containers
The frequency response, the Routh array and rlocus all give a gain margin of 3.

Step responses for K = 0.5, 1 and 2, with rise time and overshoot from stepinfo.

At K = 4 the curve encircles -1 and the closed loop has two unstable poles.

A PI controller removes the 29% steady-state error left by proportional control.
A type-1 loop follows a ramp with a constant lag of 1/Kv = 0.5.

Sampling at 0.5 s with a zero-order hold raises the overshoot from 25% to 40%.

A mass-spring-damper with damping ratio 0.1 peaks 14 dB above its static gain.

Pole locations and step responses for damping ratios of 0.2, 0.5 and 0.8.

State feedback from lqr, simulated with ode45 from a 0.2 rad tilt.