Cleveland State University
Department of Electrical and
Computer Engineering
EEC 510
Linear Systems
function Ex01(ControlMag)
% function Ex01.
% Nonlinear system simulation.
% To see the effects of
linearization, run this with
% ControlMag values = 0.05, 0.5,
and 5.
% Close all open figures.
close all;
% The simulation runs from 0 to tf
in steps of dt.
dt = 0.02;
tf = 5;
% Nonlinear simulation.
x1 = 1;
x2 = 1;
x1array = [];
x2array = [];
for t = 0 : dt : tf
u =
ControlMag * sin(2*pi*t);
x1dot = -1
/ x2 / x2;
x2dot = u *
x1;
x1 = x1 +
dt * x1dot;
x2 = x2 +
dt * x2dot;
x1array =
[x1array x1];
x2array =
[x2array x2];
end
% Linearized simulation.
x1bar = 0;
x2bar = 0;
x1arrayLin = [];
x2arrayLin = [];
for t = 0 : dt : tf
u = ControlMag
* sin(2*pi*t);
x1bardot =
2 * x2bar;
x2bardot =
(1 - t) * u;
x1bar =
x1bar + dt * x1bardot;
x2bar =
x2bar + dt * x2bardot;
x1arrayLin
= [x1arrayLin 1 - t + x1bar];
x2arrayLin
= [x2arrayLin 1 + x2bar];
end
% Compare the results of the
nonlinear and linearized simulations.
figure;
t = [0 : dt : tf];
plot(t, x1array, '-',
t, x1arrayLin, '--');
title(['x1, Control
Magnitude = ',num2str(ControlMag), ...
', Solid = Nonlinear, Dashed = Linearized']);
figure;
plot(t, x2array, '-',
t, x2arrayLin, '--');
title(['x2, Control
Magnitude = ',num2str(ControlMag), ...
', Solid = Nonlinear, Dashed = Linearized']);
Department of Electrical and Computer Engineering
Last Revised: March 13, 2001