Course materials · Control Engineering I

Control Engineering I · Week 06 · State Transition and System Responses

English translation

Edit the code and response fields in your own copy. Name: ⟦enter here⟧ / Student ID: ⟦enter here⟧

How to run

In Live Editor, click inside the code and run the current section with Run Section (Windows/Linux Ctrl+Enter, Mac ⌘+Enter). Run executes the entire document. Edit the explanations and response fields directly.
Initially run from the top, and rerun any section whose values you change. If an undefined-variable error occurs, run the preceding sections first. Outputs appear below or to the right of the code.
Environment: MATLAB Online and Control System Toolbox.

1. Calculate state transitions

Perform the calculations below first, then compare with MATLAB results.
  • Before running the general model below, calculate by hand the simple case with A=[−100−2]A=\left[\begin{array}{cc}-1&0\\0&-2\end{array}\right], 𝒙0=[21]\mathbf x_0=\left[\begin{array}{c}2\\1\end{array}\right], and u(t)=0u(t)=0.
  • For a diagonal matrix, Φ(t)=diag(ea1t,ea2t)\Phi(t)=\mathrm{diag}(e^{a_1t},e^{a_2t}).
  • Write Φ(t)\Phi(t) and 𝒙(t)=Φ(t)𝒙0\mathbf x(t)=\Phi(t)\mathbf x_0 symbolically and check whether they equal their initial values at t=0t=0.
  • In the total-response equation, identify the term due to the initial state and the integral term due to the input. Explain which term is 0 here.
  • At t=1t=1, evaluate x(t) and leave its components in exponential form. Then assign the hand-calculation model to the separate variables A_check=diag([-1 -2]) and x0_check=[2;1], and compare the resulting state vector with expm(A_check)*x0_check.
  • Use this calculation as the baseline prediction for the “2. State Transition Matrix” code in the practice Live Script.
Before execution — Hand-calculated expressions and values: ⟦write calculations here⟧ After execution — MATLAB output values to compare: ⟦write output values here⟧

2. State Transition Matrix

Calculate e^{At} in MATLAB using expm(A*t). At t=0, no time has elapsed, so the initial state must remain unchanged. Thus, Phi(0) is the identity matrix; the code below checks this condition. The similarly named exp applies the exponential function to each element separately, so substituting it for expm here produces a different result.
Prediction before running: ⟦enter here⟧
A=[0 1;-2 -3];
Phi=expm(A*.5);disp(Phi);
assert(norm(expm(A*0)-eye(2))<1e-12);
disp(norm(Phi-exp(A*.5)));
Do it yourself:
  1. Using the same A in the “2. State Transition Matrix” code in the practice Live Script, obtain Phi=expm(A*t) at t∈{0,0.5,1}t\in\{0,0.5,1\} and record the matrix.
  2. norm(expm(A)-expm(A*0.5)*expm(A*0.5)): calculate and record the residual. Check whether it is close to 0 and compare with Φ(1)=Φ(0.5)Φ(0.5)\Phi(1)=\Phi(0.5)\Phi(0.5).
  3. Relate your explanation to Phi-exp(A*0.5) calculated at the same t=0.5t=0.5, and explain why state transition uses expm instead of exp.
% ✍ Your code: add your own code below.
Changed condition: ⟦enter here⟧
Observed result: ⟦enter here⟧
Differences from the prediction and their causes: ⟦enter here⟧

3. Compare state trajectories

Show the units of each state.
Prediction before running: ⟦enter here⟧
A=[0 1;-2 -3];x0=[1;0];t=0:.02:5;X=zeros(2,numel(t));
for j=1:numel(t),X(:,j)=expm(A*t(j))*x0;end
figure;subplot(2,1,1);plot(t,X(1,:));ylabel('Position (m)');grid on;
subplot(2,1,2);plot(t,X(2,:));ylabel('Velocity (m/s)');xlabel('Time (s)');grid on;
Do it yourself:
  1. Using the same A and time axis, change the initial state from [1;0] to [0;1] and recalculate X.
  2. Plot the curves before and after the change for position X(1,:) and linear velocity X(2,:). Label the initial states in the legend.
  3. Explain why position changes later despite an initial position of 0, relating this to the initial linear velocity.
% ✍ Your code: add your own code below.
Changed condition: ⟦enter here⟧
Observed result: ⟦enter here⟧
Differences from the prediction and their causes: ⟦enter here⟧

4. Decompose the total response

Compare using the same input, output, and time axis.
Prediction before running: ⟦enter here⟧
sys=ss([0 1;-2 -3],[0;1],[1 0],0);t=(0:.01:8)';u=ones(size(t));x0=[1;0];
yTotal=lsim(sys,u,t,x0);yInitial=initial(sys,x0,t);yInput=lsim(sys,u,t);
err=max(abs(yTotal-yInitial-yInput));disp(err);assert(err<1e-8);
figure;plot(t,[yTotal,yInitial,yInput]);legend('total','initial','input');grid on;
Do it yourself:
  1. Use sys,t defined in the total-response decomposition code to calculate each of the following two cases.
  • Input u=2*ones(size(t)), baseline initial state x0=[1;0].
  • u=2*ones(size(t)) with input magnitude kept at 2, initial state x0=[0;1].
  1. For each case, calculate the total output lsim(sys,u,t,x0), the output due to the initial state initial(sys,x0,t), and the output due to the input lsim(sys,u,t).
  2. Record max(abs(yTotal-yInitial-yInput)) and explain the relation among the three outputs.
  3. Compare the total output with only the input doubled against twice the baseline total output. Separately determine whether the output due to the initial state also doubles.
% ✍ Your code: add your own code below.
Changed condition: ⟦enter here⟧
Observed result: ⟦enter here⟧
Differences from the prediction and their causes: ⟦enter here⟧

Practice through repetition and check before submission

Summarize the three conditions compared in the preceding hands-on activities below. You do not need to repeat experiments already completed. Predictions may state increasing or decreasing trends instead of exact values.
Repetition 1 — Condition: ⟦enter here⟧ / Prediction: ⟦enter here⟧ / Actual result: ⟦enter here⟧
Trial 2 — Condition: ⟦enter here⟧ / Prediction: ⟦enter here⟧ / Observation: ⟦enter here⟧
Trial 3 — Condition: ⟦enter here⟧ / Prediction: ⟦enter here⟧ / Observation: ⟦enter here⟧
Optional:
Example: Entering the initial state as a row vector
  1. Using the same A in the “2. State Transition Matrix” code in the practice Live Script, test expm(A*0.5)*[1 0] on a separate line and record both matrices’ dimensions and the error message.
  2. Change only the initial state to the column vector [1;0] and calculate. Write both components of the result and replace the incorrect input line with the corrected line.
Include code, actual outputs and plots, and your own interpretation. Submit through KLAS; check the semester schedule and latest announcements for the deadline.
Filename: Name_StudentID_Week6.mlx.