First-Order System Exercises#
π§ Quick Theory Recap#
A first-order linear system can be expressed as:
or equivalently:
where:
\( A = -\frac{b}{m} \), \( B = \frac{k_u}{m} \), and \( w(t) = -g \sin(\theta(t)) \)
π How to Use the Streamlit Visualizer#
Launch your Streamlit app for the first-order system.
Adjust the sliders for:
Vehicle mass \(m\)
Drag coefficient \(b\)
Force coefficient \(k_u\)
Input step magnitude, simulation duration, and road slope \(\theta(t)\).
Observe:
Input (u vs t) β throttle input
Disturbance (w vs t) β effect of road slope
Output (v vs t) β system velocity
from IPython.display import display, HTML
download_url = "https://raw.githubusercontent.com/suann124/AIinTeaching/main/exercises/cruise_control_app.py"
# Jupyter front-end download button
button_html = f"""
<a href="{download_url}" download="cruise_control_app.py">
<button style="padding:8px 16px; font-size:16px; background-color:#1a73e8; color:white; border:none; border-radius:4px; cursor:pointer;">
Download cruise_control_app.py
</button>
</a>
"""
display(HTML(button_html))
Create and activate a new conda environment (Python 3.9 recommended):
conda create -n first_order_system python=3.9
conda activate first_order_system
Install Streamlit within the environment:
pip install streamlit streamlit-js-eval
Make sure cruise_control_app.py is in your working directory.
Launch the Streamlit visualizer with:
streamlit run cruise_control_app.py
Open the provided local URL in your browser to interact with the app.
You should see a dashboard with sliders and plots like this:
#
#
Click the βRun Analysisβ button to update the plots after adjusting the sliders.
βοΈ Exercise 1 β Model Derivation#
Given:
Derive the canonical form \( \dot{v}(t) = A v(t) + B u(t) + w(t) \).
Identify the parameters:
\( A = -b/m \)
\( B = k_u/m \)
\( T = -1/A \)
\( K = -B/A \)
Parameter Sets:
Case |
m (kg) |
b (NΒ·s/m) |
k_u (N/unit) |
|---|---|---|---|
1 |
1600 |
300 |
50 |
2 |
800 |
200 |
60 |
π Check in the Visualizer:
Run these parameters and confirm that the time constant (T) and steady-state velocity match your computed values.
βοΈ Exercise 2 β Free Response#
Assume \( u(t)=0 \) and \( \theta(t)=0 \).
Solve analytically: \( v(t) = v(0)e^{A t} \).
For \( A = -0.2 \) and \( v(0)=1 \), plot \( v(t) \) for 0β20 seconds.
Describe how the response changes for:
\( A < 0 \): Stable (decays to 0)
\( A = 0 \): Constant
\( A > 0 \): Unstable (grows exponentially)
π Check in the Visualizer:
Set throttle to zero and vary drag (b). Observe how the system decays or diverges.
βοΈ Exercise 3 β Forced (Step) Response#
For constant input \( u(t) = U_0 \):
Derive \( v_{ss} = -\frac{B}{A}U_0 \).
Show that after one time constant \(T\), the response reaches ~63% of its final value.
Compute expected settling time (β 5T).
π Check in the Visualizer:
Apply a throttle step and confirm these behaviors.
βοΈ Exercise 4 β Disturbance Effect#
Now consider a slope disturbance:
Compute \( w(t) = -g \sin(\theta(t)) \).
Predict how \(v(t)\) changes when the slope rises.
Derive new steady-state velocity \( v_{ss,dist} = -\frac{B u + w}{A} \).
π Check in the Visualizer:
Enable road slope disturbance and observe the output change.
π¬ Exercise 6 β Reflection#
Answer briefly:
Why does the first-order model always respond smoothly (no overshoot)?
Why is the time constant a measure of system βspeedβ?
What physical factors determine stability?
How does adding feedback change this behavior conceptually?