Dynamic Response of SDOF - Matlab Code
Dynamic Response of SDOF - Matlab Code
sin
cos
sin
cos sin
cos
sin cos cos sin
sin
cos
cos sin
sin
cos
plot result
(2) Calculate the response by using the central difference method (dt=0.1s)
matlab code
% input data
m=44.357;
% mass (unit=kN.s2/m)
k=1751.18;
% stiffness (unit=kN/m)
h=0.05;
w=2*pi;
T=1.0;
% period (unit=sec)
c=2*h*m*w;
% damping coefficient
t=[0:dt:10]';
% time
% actually i=-1
% coefficient of d(i+1)
A=m/dt^2-c/(2*dt);
B=k-2*m/dt^2;
C=m/dt^2+c/(2*dt);
% iteration
for i=3:n+2
TT(i)=t(i-2);
F(i)=P(i-2);
d(i)=2*dt*v(i-1)+d(i-2);
d(i+1)=1/C*(F(i)-A*d(i-1)-B*d(i));
v(i)=(d(i+1)-d(i-1))/(2*dt);
a(i)=(d(i+1)-2*d(i)+d(i-1))/dt^2;
v(i+1)=v(i);
% virtual
a(i+1)=a(i);
% virtual
TT(i+1)=TT(i); % virtual
F(i+1)=F(i);
% virtual
end
result=[TT' F' d' v' a'];
xlswrite('cdm result.xls',result)
figure(1)
plot(t,P)
xlabel('time(sec)')
ylabel('Load(kN)')
title('Input loading')
grid on
figure(2)
plot(TT,d)
xlabel('time(sec)')
ylabel('displacement(m)')
title('Displacement Response')
grid on
figure(3)
plot(TT,v)
xlabel('time(sec)')
ylabel('velocity(m/s)')
title('Velocity Response')
grid on
figure(4)
plot(TT,a)
xlabel('time(sec)')
ylabel('acceleration(m/s2)')
title('Acceleration Response')
grid on
(3) Calculate the response by using the constant average acceleration method
(dt=0.1s)
matlab code
% mass (unit=kN.s2/m)
% stiffness (unit=kN/m)
h=0.05;
w=2*pi;
T=1.0;
% period (unit=sec)
c=2*h*m*w;
% damping coefficient
t=[0:dt:10]';
% time
P=44.48*sin(pi*t/0.6);
n=size(P,1);
% iteration
for i=1:n-1
d(i+1)=1/(k+2*c/dt+4*m/dt^2)*(P(i+1)+m*(4/dt^2*d(i)+4/dt*v(i)+a(i))+c*(2/dt*d(i)+
v(i)));
v(i+1)=2/dt*(d(i+1)-d(i))-v(i);
a(i+1)=4/dt^2*(d(i+1)-d(i))-4/dt*v(i)-a(i);
end
(4) Calculate the response by using the linear acceleration method (dt=0.1s)
matlab code
% input data
m=44.357;
% mass (unit=kN.s2/m)
k=1751.18;
% stiffness (unit=kN/m)
h=0.05;
w=2*pi;
T=1.0;
% period (unit=sec)
c=2*h*m*w;
% damping coefficient
t=[0:dt:10]';
% time
P=44.48*sin(pi*t/0.6);
n=size(P,1);
% iteration
for i=1:n-1
d(i+1)=1/(k+6*m/dt^2+3*c/dt)*(P(i+1)+(6*m/dt^2+3*c/dt)*d(i)+(6*m/dt+2*c)*v(i)+(2*
m+c*dt/2)*a(i));
v(i+1)=3/dt*(d(i+1)-d(i))-2*v(i)-dt/2*a(i);
a(i+1)=6/dt^2*(d(i+1)-d(i))-6/dt*v(i)-2*a(i);
end