Matlab code for modelling displacement over time as a plot

For part (a) of this question ive got this code but its not complete and im not sure if im on the right track. Please clarify what changes ive got left to make to answer this question and get the plot showing on my command window. Thank you!
My code:
function dydt = springdamper_threeblocks(t,y)
%Parameters for the system
m_susbar = 7;
m_wheel = 25;
ksus1 = 5000;
ksus2 = 12000;
ktire = 20000;
bsus1 = 500;
bsus2 = 400;
L = 0.4;
xroad = 0.05*sin(8*(2*pi)*t);
%Split up state vector y
xwheel = y(1);
xdotwheel = y(2);
theta = y(3);
thetadot = y(4);
dydt_xwheel = xdotwheel;
dydt_xwheeldotdot = (ksys2*(2*L/3)*thetadot + ksus2*(2*L/3)*theta-ktire*(xwheel-xroad))/m_wheel;
dydt_theta = thetadot;
dydt_thetadotdot = ((ksus1+4*ksus2)*theta)/m_susbar+((bsus1+4*bsus2)*thetadot)/m_susbar;
dydt = [dydt_xwheel; dydt_xwheeldotdot; dydt_thetadotdot];
%Timespan for simulation
t_initial = 0;
t_final = 5;
t_span = [t_initial,t_final];
y0 = [0;0;0];
[t,y] = ode45('springdamper_threeblocks',tspan,y0);
figure
plot(t,y(:,1));
hold on
title('Block Displacements')
xlabel('time(sec)');
ylabel('Position(m)');
legend('block1','block2');
grid on;
figure
plot(t,y(:,3));
hold on,
title('Angular displacement');
xlabel('time(sec)');
ylabel('Angular displacement(rad)');
legend('block1','block2');
grid on;
end

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Question posée :

le 11 Mai 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by