Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

4 (exercises). State-Space Form & Numerical Integration

ISAE-SUPAERO

🟩 Complete every # TODO. Solution: 04_StateSpace_NumericalIntegration.ipynb.

import numpy as np
import matplotlib.pyplot as plt
import control
from scipy.integrate import solve_ivp

plt.rcParams["figure.figsize"] = (7, 4.2)
plt.rcParams["axes.grid"] = True

Exercise (handwritten) — identify A and B

🟥 From x˙=x˙\dot x=\dot x, x¨=−kmx−cmx˙+Fm\ddot x=-\frac{k}{m}x-\frac{c}{m}\dot x+\frac{F}{m}, write x˙=Ax+BF\dot{\mathbf x}=\mathbf A\mathbf x+\mathbf B F and identify A\mathbf A, B\mathbf B (and C=[1  0]\mathbf C=[1\ \ 0] if observing position).

Exercise “EX3” — free vibration from a state-space model

🟩 Build A, B, C, D for m=1,c=0.1,k=1m=1,c=0.1,k=1, create sys = control.ss(A,B,C,D), and get the initial-condition response to x0=[1,0]Tx_0=[1,0]^T with control.initial_response.

m, c, k = 1.0, 0.1, 1.0
A = ...  # TODO
B = ...  # TODO
C = ...  # TODO
D = ...  # TODO

sys = ...  # TODO
T = np.linspace(0, 50, 1000)
x0 = [1, 0]

t_out, y_out = ...  # TODO

fig, ax = plt.subplots()
ax.plot(t_out, y_out)
plt.show()

Exercise “EX3b” — cross-check with solve_ivp

🟩 Write sdof_state(t, x, m, c, k) returning Ax\mathbf A\mathbf x and integrate with solve_ivp. Compare with the state-space result above.

def sdof_state(t, x, m, c, k):
    A = ...  # TODO
    return ...  # TODO


sol = ...  # TODO: solve_ivp(...)

# TODO: plot both curves and print the max absolute difference

Exercise “EX3c” — forced vibration

🟩 For m=100,k=1000,c=25m=100,k=1000,c=25, sinusoidal forcing F0=1000F_0=1000,N at ω=2.5\omega=2.5,rad/s: build the state-space forcing vector f(t)=[0, f0cos⁡ωt]T\mathbf f(t)=[0,\ f_0\cos\omega t]^T and solve both via control.forced_response and via solve_ivp on the raw ODE. They should agree.

m, k, c = 100.0, 1000.0, 25.0
w, F0 = 2.5, 1000.0

A = ...  # TODO
B = ...  # TODO
C = ...  # TODO
D = ...  # TODO
sys = ...  # TODO

t = np.arange(0, 10 + 1e-9, 0.01)
u = ...  # TODO

t_lsim, x_lsim = ...  # TODO


def sdof_forced_state(t, x, m, c, k, F0, w):
    A = ...  # TODO
    f = ...  # TODO
    return A @ x + f


sol = ...  # TODO

# TODO: plot both on the same axes

Homework 3 — rectangular force pulse

🟦 Solve mx¨+cx˙+kx=F0[1−H(t−t1)]m\ddot x+c\dot x+kx=F_0[1-H(t-t_1)] numerically (use numpy.heaviside), for m=1,c=0.2,k=4,F0=5,t1=6m=1,c=0.2,k=4,F_0=5,t_1=6. Then verify your answer by superposing a +F0+F_0 step response starting at t=0t=0 and a −F0-F_0 step response starting at t=t1t=t_1 (control.step_response, shifted and subtracted). The two should match.

m, c, k = 1.0, 0.2, 4.0
F0, t1 = 5.0, 6.0
t = np.linspace(0, 30, 3000)


def pulse_ode(t, x, m, c, k, F0, t1):
    A = ...  # TODO
    F = ...  # TODO: F0 * (1 - heaviside(t - t1))
    f = ...  # TODO
    return A @ x + f


sol = ...  # TODO

# TODO: build the step-response superposition and compare