3MATLAB Examples The following examples shows the essential commands needed in this project and some of the simulation tools. Additional help can be found using the MATLAB help tool. Example 1: a=[0 1;2 1]; b=[0;1]; c=[1 0]; d=[0]; k = -place(a,b,[-1 -2]) (solves the eigenvalues assignment problem) ak=(a+b*k); t=0:0.01:6; (defines a vector t such that 0 ≤ t ≤ 6 in 0.01 sec intervals. sys=ss(ak,[],eye(2),[]); (builds the state space realization with A = ak, B = 0, C = I, and D = 0. the matrix C = I so that the output is equal to each of the states. This is for the purpose of simulation.) z=initial(sys,[2;-4],t); (Simulates x˙ = ak x(0) with x(0) = [2;−4]). The result is the vector z that has 2 columns and as many rows as the vector t x1=[1 0]*z’; x2=[0 1]*z’; (Extracts x1 and x2 as the first and second column of z, respectively. subplot(2,1,1);plot(t,x1),grid title(’Response to Initial Condition’) ylabel(’State x1’) subplot(2,1,2);plot(t,x2),grid title(’Response to Initial Condition’) ylabel(’State x2’) (The function subplot(x,y,z) splits the plot into x rows and y columns. z indicated the number of each plot. Thus, for example, subplot(3,2,z) subdivides the page into 3 rows and 2 columns. The last number will index each plot from 1 tp 6. Example 2: a=[0 1;2 1]; b=[0;1]; c=[1 0]; d=[0]; k = -place(a,b,[-1 -2]) (solves the eigenvalues assignment problem) ak=(a+b*k); t=0:0.01:6; [x, y, t]=step (ak, b, eye(2), d, 1, t) (Computes the closed loop step response. x is the state (two columns in this example), y is the output (single column in this example)). x1 = [1 0] ∗ x′; x2 = [0 1] ∗ x′;
欢迎咨询51作业君