Cleveland State University
Department of Electrical and
Computer Engineering
EEC 510
Linear Systems
function [t,yArray,y1Array] = Ex00(dt)
% function [t,yArray,y1Array] =
Ex00(dt)
% Series RL circuit simulation
% INPUTS
% dt = integration step size
% OUTPUTS
% t = time array
% yArray = array containing numerical solution
% y1Array = array containing analytical solution
% Close all figures.
close all;
% Set the step size and simulation
length.
if ~exist('dt','var')
dt = 0.1;
end
tf = 10;
% Set the resistor and inductor
values.
R = 1;
L = 1;
% Initialize the simulation.
x0 = -1;
x = x0;
y = 0;
u = 1;
% Initialize some empty arrays for
later use.
yArray = [];
y1Array = [];
% Compute the numerical solution.
for t = 0 : dt : tf
% Compute the output and save it for later plotting.
y = R *
x;
yArray =
[yArray y];
% Integrate the state equation.
xdot =
-R * x / L + u / L;
x = x +
xdot * dt;
end
% Compute the analytic solution
for u = 1.
for t = 0 : dt : tf
y1 = 1 +
exp(-R*t/L) * (R * x0 - 1);
y1Array =
[y1Array y1];
end
% An easier way to compute the
analytic solution ...
t = 0 : dt : tf;
y1Array = ones(size(t)) + exp(-R*t/L) * (R * x0 -
1);
% Plot the results.
figure;
plot(t, yArray, '-',
t, y1Array, '--');
title('Solid =
Numerical, Dashed = Analytic');
xlabel('Time');
ylabel('Output
Voltage');
Department of Electrical and Computer Engineering
Last Revised: August 28, 2002