Skip to content

Instantly share code, notes, and snippets.

@0xff07
Created March 20, 2018 07:46
Show Gist options
  • Save 0xff07/19a43d96949adf7580908b16a44a480b to your computer and use it in GitHub Desktop.
Save 0xff07/19a43d96949adf7580908b16a44a480b to your computer and use it in GitHub Desktop.
Codes to solve System Dynamics homework 1, WITHOUT WARRANTY.
syms A;
syms t positive;
syms t_0 positive;
syms s;
syms omega positive;
sig1 = A * heaviside(t) - A * heaviside(t - t_0);
sig2 = (heaviside(t) - heaviside(t - 2*pi/omega))*sin(omega * t)*A;
sig1 = laplace(sig1, t, s);
sig2 = simplify(expand(laplace(sig2, t, s)));
%(a)
sys = 1/(s^2 + 5*s + 6);
res(1) = ilaplace(sys * sig1);
res(2) = ilaplace(sys * sig2);
%(b)
sys = 1/(s^2 + 2*s + 2);
res(3) = ilaplace(sys * sig1);
res(4) = ilaplace(sys * sig2);
%(c)
figure(1);
for i = [1 3]
p = res(i);
p = matlabFunction(p(1));
tau = 0:0.001:15;
subplot(2, 2, i);hold on;
axis([0 15 -0.6 0.6]);
for j = 1:5
lab = strcat('t_0 = ', num2str(j));
plot(tau, p(1, tau, j), 'DisplayName', lab);
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4 3]);
end
legend('show');
end
for i = [2 4]
p = res(i);
p = matlabFunction(p(1));
tau = 0:0.001:15;
subplot(2, 2, i);hold all;
axis([0 15 -0.6 0.6]);
for j = 1:5
lab = strcat('\omega = ', num2str(j));
plot(tau, p(1, tau, j), 'DisplayName', lab);
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 40 30]);
end
legend('show');
end
print('-dpng','-r0','SD HW1.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment