Hi, I am looking for a way to obtain the first and second derivative of the "xt" function stated in the code below. This is to obtain the velocity and acceleration graph of the displacement "xt" given. Is there a command on Matlab that will allow me to do so ?
%data given
m=4;
k=2500;
c=100;
x0=0.1;
xd0=-10;
n=50;
dt=0.01;
t=[0:dt:(n*dt)];
%natural frequency
wn=sqrt(k/m);
%damping ratio
tho=c/(2*sqrt(k*m));
%Calculating displacement
if tho<1 %underdamped
xt=(exp(-tho.*wn.*t).*(((xd0+tho.*wn.*x0)/(wn.*(1-tho^2)^0.5)).*sin(((1-tho^2)^0.5).*wn.*t)+x0.*cos(((1-tho^2)^0.5).*wn.*t)));
end
%plot displacement, velocity and acceleration
plot(t,xt,t,xdt,t,xddt);
legend('Displacement','velocity','acceleration')
title('System responses')
xlabel('time(s)')
ylabel('x(t), v(t),a(t)')
grid on
Best Answer