Cleveland State University
Department of Electrical and
Computer Engineering
EEC 510
Linear Systems
function Ex04
% function Ex04.
% Simulate a series RLC circuit.
% The output is the voltage across
the capacitor.
% Set the R, L, and C values.
R = 1;
L = 10e-3;
C = 200E-4;
% Set the system matrices.
% xdot = Ax + Bu, y = Cx + Du.
A = [0 1/C; -1/L -R/L];
B = [0; 1/L];
C = [1 0];
D = [0];
% Create a Matlab state-space
model.
sys = ss(A, B, C, D);
% Close all figures.
close 'all';
% Compute and plot the step
response.
figure;
[y, t] = step(sys);
plot(t, y);
title('Step Response');
% Compute and plot the impulse
response.
figure;
[y, t] = impulse(sys);
plot(t, y);
title('Impulse
Response');
% Compute and plot the zero-state response
to a sinusoidal input.
figure;
dt = 0.002;
tf = 4;
t = 0 : dt : tf;
u = sin(t);
[ysine, t] = lsim(sys, u, t);
plot(t, ysine);
title('Sine Response');
% Compute and plot the zero-input
response.
figure;
x0 = [1; 1];
[yinitial, t] = initial(sys, x0, t);
plot(t, yinitial);
title('Initial
Condition Response');
% Manually compute the total
response, taking into account
% both initial conditions and
external input.
% Note that if dt is too large
this simulation will not work.
x = x0;
u = sin(0);
yarray = [C * x + D * u];
for t = dt : dt : tf
xdot = A *
x + B * u;
x = x +
xdot * dt;
y = C * x
+ D * u;
yarray =
[yarray y];
u =
sin(t);
end
% Compare the total response
obtained manually with the total
% response obtained by
superimposing the zero-state and the
% zero-input responses.
figure;
t = 0 : dt : tf;
plot(t, ysine+yinitial, '-',
t, yarray, '--');
title('Total Response');
Department of Electrical and Computer Engineering
Last Revised: March 13, 2001