CODE FOR LAB 03
function dxdt= mass_damper_spring(t,x)
M1=750;B1=20;K1=15;Fa= 300;
M2=750;B2=20;K2=15;
B3=30;
dxdt = zeros(4,1);
dxdt(1)=x(2);
dxdt(2)=(Fa/M1)-(K1/M1)*x(1)-((B1+B3)/M1)*x(2)+(B3/M1)*x(4);
dxdt(3)=x(4);
dxdt(4)=(B3/M2)*x(2)-(K2/M2)*x(3)-((B2+B3)/M2)*x(4);
[t,x]=ode45(('mass_damper_spring'),[0 400],[0;0;0;0]);
subplot(2,1,1)
plot(t,x(:,1));grid;
xlabel('time');ylabel('displacement');
title('Displacement at node A for Case 1');
subplot(2,1,2)
plot(t,x(:,2));grid;
xlabel('time');ylabel('Velocity');
title('Vellocity at node A for Case 1');
figure
subplot(2,1,1)
plot(t,x(:,3));grid;
xlabel('time');ylabel('displacement');
title('Displacement at node B for Case 1');
subplot(2,1,2)
plot(t,x(:,4));grid;
xlabel('time');ylabel('Velocity');
title('Vellocity at node B for Case 1');
CODE FOR LAB 04
function dxdt= electrical_system(t,x)
R1=10;L1=1;C=5;e=50;
R2=10;L2=1;
dxdt = zeros(3,1);
dxdt(1)=-(R1/L1)*x(1)-(1/L1)*x(3)+(e/L1);
dxdt(2)=-(R2/L2)*x(2)+(1/L2)*x(3);
dxdt(3)=(1/C)*x(1)-(1/C)*x(2);
[t,x]=ode45(('electrical_system'),[0 500],[0;0;0]);
subplot(3,1,1)
plot(t,x(:,1));grid;
xlabel('time');ylabel('current');
title('Current of L1');
subplot(3,1,2)
plot(t,x(:,2));grid;
xlabel('time');ylabel('curent');
title('Current of L2');
subplot(3,1,3)
plot(t,x(:,3));grid;
xlabel('time');ylabel('velocity');
title('Voltage of C');