Cleveland State University

Department of Electrical and Computer Engineering

EEC 510

Linear Systems

function Ex02(ControlMag)

% function Ex02.

% Hovering rocket simulation.

% To see the effects of linearization, run this with

% ControlMag values = 3, 30, and 300.

% Close all figures.

close all;

% Define the step size and the simulation length.

dt = 0.01;

tf = 5;

G = 6.673e-11; % gravitational constant (m^3/kg/s^2)

M = 5.98e24; % earth mass (kg)

m0 = 1000; % initial rocket mass (kg)

R = 6.37e6; % earth radius (m)

K = 1000; % thrust proportionality constant

g = 50; % drag constant

% Nonlinear simulation.

x1 = 0;

x2 = 0;

x3 = m0;

x1array = [];

x2array = [];

x3array = [];

for t = 0 : dt : tf

u = G * M * x3 / K / R / R + ControlMag * abs(cos(2*pi*t));

x1dot = x2;

x2dot = (K * u - g * x2) / x3 - G * M / (R + x1)^2;

x3dot = -u;

x1 = x1 + dt * x1dot;

x2 = x2 + dt * x2dot;

x3 = x3 + dt * x3dot;

x1array = [x1array x1];

x2array = [x2array x2];

x3array = [x3array x3];

end

% Linearized simulation.

x1bar = 0;

x2bar = 0;

x3bar = 0;

x1arrayLin = [];

x2arrayLin = [];

x3arrayLin = [];

for t = 0 : dt : tf

m = m0 * exp(-G * M * t / K / R / R);

ubar = ControlMag * abs(cos(2*pi*t));

x1bardot = x2bar;

x2bardot = (2 * G * M / R / R / R) * x1bar - (g / m) * x2bar - ...

(G * M / R / R / m) * x3bar + (K / m) * ubar;

x3bardot = -ubar;

x1bar = x1bar + dt * x1bardot;

x2bar = x2bar + dt * x2bardot;

x3bar = x3bar + dt * x3bardot;

x1arrayLin = [x1arrayLin 0 + x1bar];

x2arrayLin = [x2arrayLin 0 + x2bar];

x3arrayLin = [x3arrayLin m + x3bar];

end

% Plot the results.

figure;

t = [0 : dt : tf];

plot(t, x1array, '-', t, x1arrayLin, '--');

title(['Altitude, Control Magnitude = ', num2str(ControlMag), ...

', Solid = Nonlinear, Dashed = Linearized']);

figure;

plot(t, x2array, '-', t, x2arrayLin, '--');

title(['Velocity, Control Magnitude = ', num2str(ControlMag), ...

', Solid = Nonlinear, Dashed = Linearized']);

figure;

plot(t, x3array, '-', t, x3arrayLin, '--');

title(['Mass, Control Magnitude = ', num2str(ControlMag), ...

', Solid = Nonlinear, Dashed = Linearized']);

Department of Electrical and Computer Engineering

Cleveland State University

Last Revised: March 13, 2001