Course materials · Control Engineering I

Control Engineering I · Week 07 · Does Changing the Model Representation Preserve the Response?

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. Model conversion and coordinate transformation

Perform the calculations below first, then compare with MATLAB results.
The model is A=[01−2−3]A=\left[\begin{array}{cc}0&1\\-2&-3\end{array}\right], B=[01]B=\left[\begin{array}{c}0\\1\end{array}\right], C=[10]C=\left[\begin{array}{cc}1&0\end{array}\right], and D=0D=0.
  • Read the given model's A,B,C,DA,B,C,D and write the two state equations by hand.
  • Set the initial conditions to 0 and take the Laplace transform of both state equations. From the first equation, express X2(s)X_2(s) in terms of X1(s)X_1(s), substitute into the second equation, and obtain X1(s)U(s)\frac{X_1(s)}{U(s)}. For C=[10]C=\left[\begin{array}{cc}1&0\end{array}\right], use the relationship between Y(s)Y(s) and X1(s)X_1(s) to express the result as Y(s)U(s)\frac{Y(s)}{U(s)}. Then describe how the output equation changes for C=[01]C=\left[\begin{array}{cc}0&1\end{array}\right].
  • Then compare with the tf result.
Use P=diag(2,0.5)P=\mathrm{diag}(2,0.5) for the coordinate transformation and x0=[11]x_0=\left[\begin{array}{c}1\\1\end{array}\right] for the initial state.
  1. Before running the matrix-transformation code, substitute x=Pzx=Pz and ẋ=Pż\dot x=P\dot z into ẋ=Ax+Bu\dot x=Ax+Bu, and multiply both sides by P−1P^{-1}. Find the matrices corresponding to Az,BzA_z,B_z in ż=Azz+Bzu\dot z=A_z z+B_z u.
  2. Also substitute x=Pzx=Pz into y=Cxy=Cx and find CzC_z of y=Czzy=C_z z.
  3. For the initial state, use x0=Pz0x_0=Pz_0 to find z0z_0. Match the three matrices you derived to Az, Bz and Cz in the “3. Rescale the state coordinates” code in the practice Live Script, and the initial state to z0 in the “4. Correct an initial-value transformation error” code in the practice Live Script. Record hand and code calculations in two adjacent columns, then note whether corresponding entries agree in each matrix or vector.
Before execution — Hand-calculated expressions and values: ⟦write calculations here⟧ After execution — MATLAB output values to compare: ⟦write output values here⟧

2. Responses before and after transformation

Compare input and output with all initial conditions equal to 0.
Prediction before running: ⟦enter here⟧
A=[0 1;-2 -3];B=[0;1];C=[1 0];D=0;sys=ss(A,B,C,D);G=tf(sys);
t=(0:.01:10)';y1=step(sys,t);y2=step(G,t);
disp(size(A));disp(G);disp(max(abs(y1-y2)));assert(max(abs(y1-y2))<1e-8);
Do it yourself:
  1. Keep A,B,D in the “2. Responses before and after transformation” code in the practice Live Script, change to C=[0 1], then rebuild sys and G=tf(sys).
  2. Calculate step(sys,t) and step(G,t) on the same time axis and record the maximum absolute difference between their outputs. Determine whether it is less than 10−810^{-8}.
  3. Write the output equations y=Cxy=Cx and DC gains before and after the change side by side. Explain why changing the selected state changes the output and DC gain.
% ✍ 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. Rescale the state coordinates

First write the relation x=Pz.
Prediction before running: ⟦enter here⟧
A=[0 1;-2 -3];B=[0;1];C=[1 0];P=diag([2 .5]);
Az=P\(A*P);Bz=P\B;Cz=C*P;
sys=ss(A,B,C,0);transformed=ss(Az,Bz,Cz,0);
t=(0:.01:10)';err=max(abs(step(sys,t)-step(transformed,t)));disp(err);assert(err<1e-8);
Do it yourself:
  1. Change to P=diag([3 2]), recalculate Az,Bz,Cz using Az=P\(A*P), Bz=P\B, and Cz=C*P, and record the matrix.
  2. Calculate the step responses of the original and transformed models on the same time axis, and record the maximum absolute difference between their outputs. Determine whether it is less than 10−810^{-8}.
  3. Explain why the output stays the same despite different matrix elements, using the relation between x=Pzx=Pz and the output equation.
% ✍ 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. Correct an initial-value transformation error

Use the model created in the preceding section.
Prediction before running: ⟦enter here⟧
x0=[1;1];z0=P\x0;
yx=initial(sys,x0,t);yz=initial(transformed,z0,t);wrong=initial(transformed,x0,t);
disp([max(abs(yx-yz)),max(abs(yx-wrong))]);assert(max(abs(yx-yz))<1e-8);
figure;plot(t,[yx,yz,wrong]);legend('original','correct transformed','wrong initial state');grid on;
Do it yourself:
  1. Set the initial state to x0=[10]x_0=\left[\begin{array}{c}1\\0\end{array}\right], [01]\left[\begin{array}{c}0\\1\end{array}\right], and [21]\left[\begin{array}{c}2\\1\end{array}\right] in turn. Keep the model, coordinate-transformation matrix and time vector used in “3. Rescale the state coordinates” above. After changing the initial state, rerun the “4. Correct an initial-value transformation error” code in the practice Live Script.
  2. At each x0x_0, find initial(sys,x0,t) for the original model and initial(transformed,P\x0,t) for the transformed model. Also calculate the output when x0 is used unchanged in the same transformed model.
  3. For each initial state, record two columns: the maximum absolute difference between the correctly transformed and original outputs, and that between the output using the unchanged initial value and the original output. Explain why these cases differ, relating your explanation to x0=Pz0x_0=Pz_0.
% ✍ 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: applying an incorrect coordinate transformation to the transformed input matrix
  1. Keep A,B,C,P,Az,Cz in the “3. Rescale the state coordinates” code in the practice Live Script unchanged. In a separate model, calculate the difference from the original model’s step output when Bz=P*B is used incorrectly.
  2. Record the maximum absolute difference at t=(0:0.01:10)'. Change only the definition of Bz to P\B, recalculate the same difference, and compare the two values.
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_Week7.mlx.