% General RLC circuit model
% script for HW2 #6, to run HW2_6.mdl
% J Cardell, Feb 2009

% constants
R2 = 2;
C1 =0.5;
C2 = 1;
L = 1;

figure
hold on

% Define a color map to define the different colors to use in plotting the
% different responses
color_map = jet(5);

% run the simulink model, mass_spring.mdl
sim('HW2_6');

% define data vectors written to Matlab workspace by Simulink 'To
% Workspace' block
t = sim_u.time;
u = sim_u.signals.values;

% output from the three state variables
iL = iL_out.signals.values;
vc1 = vc1_out.signals.values;
vc2 = vc2_out.signals.values;

% plot the data
plot(t, iL, 'LineWidth', 2, 'color', color_map(1,:))
plot(t, vc1, 'LineWidth', 2, 'color', color_map(2,:))
plot(t, vc2, 'LineWidth', 2, 'color', color_map(5,:))
plot(t, u, 'LineWidth', 2, 'color', color_map(3,:))

title('Response of General RLC Circuit')
xlabel('t (sec)')
ylabel('iL, vC and input')
legend(['iL'], ['vC1'], ['vC2'], 'u')

grid
hold off