Chris Parmer — home

Root locus for L(s)=1/(s(s+1)(s+2))

Control Systems

Example from the compendium of canonical charts

Control Systems — Root locus for L(s)=1/(s(s+1)(s+2))

Python Code

"""Control Systems — Root locus for L(s)=1/(s(s+1)(s+2))."""


import numpy as np
import plotly.graph_objects as go


def generate():
    K_values = np.linspace(0, 30, 3000)

    roots_real = []
    roots_imag = []
    k_colors = []

    for K in K_values:
        # Characteristic polynomial: s^3 + 3s^2 + 2s + K
        coeffs = [1, 3, 2, K]
        roots = np.roots(coeffs)
        for r in roots:
            roots_real.append(r.real)
            roots_imag.append(r.imag)
            k_colors.append(K)

    fig = go.Figure()

    # Root locus colored by K
    fig.add_trace(go.Scatter(
        x=roots_real, y=roots_imag,
        mode="markers",
        name="Root locus",
        marker=dict(
            color=k_colors,
            colorscale="Viridis",
            size=2,
            opacity=0.6,
            colorbar=dict(title="K", thickness=14, len=0.7),
        ),
        hovertemplate="Re=%{x:.3f}, Im=%{y:.3f}<extra></extra>",
    ))

    # Open-loop poles at s=0, -1, -2
    fig.add_trace(go.Scatter(
        x=[0, -1, -2], y=[0, 0, 0],
        mode="markers",
        name="Open-loop poles",
        marker=dict(color="red", size=12, symbol="x", line=dict(width=2.5)),
        hovertemplate="%{x:.0f}+j%{y:.3f}<extra>OL pole</extra>",
    ))

    # Imaginary axis crossing at K≈6, ω≈±√2
    omega_c = np.sqrt(2)
    fig.add_trace(go.Scatter(
        x=[0, 0], y=[omega_c, -omega_c],
        mode="markers",
        name="Crossing (K≈6, ω≈±√2)",
        marker=dict(color=TEAL, size=11, symbol="circle-open", line=dict(width=2.5)),
        hovertemplate="±j√2 (K≈6)<extra></extra>",
    ))

    fig.update_layout(
        xaxis=dict(
            title="Real",
            range=[-4, 1.5],
            zeroline=True,
            zerolinecolor=GRID,
            zerolinewidth=1,
        ),
        yaxis=dict(
            title="Imaginary",
            range=[-5, 5],
            zeroline=True,
            zerolinecolor=GRID,
            zerolinewidth=1,
        ),
        legend=dict(orientation="h", y=1.08),
        margin=dict(t=40, b=60, l=70, r=40),
        height=600,
    )
    return fig


if __name__ == "__main__":
    generate()

Made with Plotly