In: Physics
(only matlab code please)
solve and plot the relation between the position vs time where m1= 1 kg , m2 = 1.5 kg (Mass) k1= 100 N/m , k2 = 125 N/m (spring) b = 1 (damper) Initial conditions: y1(0) =0.15 m , y ’1(0) =0.05 m/s y2(0) =0.05 m , y ’2(0) =0.03 m/s U1(t) = unit step starting at t (step time) = 0 sec U2 = u (t,5) (t (step time) = 5 sec) t = linspace(0,25)
and the two ordinary differential equations is as follow
(1)= d2y1/dt =(1/m1)*((u1-k1*y1)+b*(dy2/dt-dy1/dt));
(2)= d2y2/dt = (1/m2)*((u2-k2*y2)+b*(dy1/dt-dy2/dt));
where d2y1/dt represent second order of y1
% Here is the script
t=linspace(0,25,1000);
% t=linspace(0,25);
initial_Conditios=[0.15 0.05 0.05 0.03];
[t,y]=ode45(@diff_eq, t, initial_Conditios);
plot(t,[y(:,1), y(:,2)])
legend('y_1','y_2')
grid on
% code ends
Here is the function (do not copy this line)
function ODE_problem=diff_eq(t,V)
m1=100;
m2=1.5;
k1=100;
k2=125;
b=1;
U1=t>=0;
U2=t>=5;
y1=V(1);
y2=V(2);
dy1_dt=V(3);
dy2_dt=V(4);
ODE_problem=[dy1_dt;...
dy2_dt;...
(1/m1)*((U1-k1*y1)+b*(dy2_dt-dy1_dt));...
(1/m2)*((U2-k2*y2)+b*(dy1_dt-dy2_dt))];
end
Here is the screenshot