0% found this document useful (0 votes)
42 views2 pages

Code For Lab 03

The document contains code for two lab simulations: 1) A mass-damper-spring system with two masses M1 and M2 connected by a spring and damper. The code sets up and solves the differential equations of motion and plots the displacement and velocity of each mass over time. 2) An electrical circuit simulation with inductors L1 and L2, resistor R1 and R2, capacitor C and voltage source e. The code similarly sets up and solves the differential equations for current and voltage in each component and plots the results.

Uploaded by

maham siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Code For Lab 03

The document contains code for two lab simulations: 1) A mass-damper-spring system with two masses M1 and M2 connected by a spring and damper. The code sets up and solves the differential equations of motion and plots the displacement and velocity of each mass over time. 2) An electrical circuit simulation with inductors L1 and L2, resistor R1 and R2, capacitor C and voltage source e. The code similarly sets up and solves the differential equations for current and voltage in each component and plots the results.

Uploaded by

maham siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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');

You might also like