You are on page 1of 2

16/10/17 2:18 PM G:\M Tech\Dynamics\COde\New\NmarkLin.

m 1 of 2

clc
clear all
close all
format long;
m=1; % m is the mass of the structure
T=0.5; % T is the Natural Period of Vibration
z=0.05; % z is the Damping ratio
w=2*pi/T; % w is the natural frequency
k=m*w^2; % k is the stiffness constant
c=2*m*z*w; % c is the Damping Coefficient
dt=0.0
G=0.5; % Gamma
B=1/6; % Beta
k1=k+c*(G/(B*dt))+(m/(B*dt^2));
a=(m/(B*dt))+((c*G))/B;
b=(m/(2*B))+(dt*c*((G/(2*B))-1));
data=xlsread('data.xlsx','sheet1');
t=data(:,1);
ag=data(:,2); %ag is Ground acceleration
d(1)=0; % d is Relative Displacement
v(1)=0; % v is Relative Velocity
for i=1:3000
P(i)=-m*ag(i); %P is Ground force (Po)
P(i+1)=-m*ag(i+1); %A is Relative Acceleration
A(i)=(P(i)-c*v(i)-k*d(i))/m;
dP(i)=P(i+1)-P(i)+a*v(i)+b*A(i); %dP is (delta Pcap)
dd(i)=dP(i)/k1;
dv(i)=((G*dd(i))/(B*dt))-G*v(i)/B+((dt*A(i))*(1-G/(2*B)));
dA(i)=(dd(i)/(B*dt^2))-(v(i)/(B*dt))-(A(i)/(2*B));
d(i+1)=d(i)+dd(i); %dA is (delta relative accelaration)
v(i+1)=v(i)+dv(i);
A(i+1)=A(i)+dA(i);

At(i)=A(i)+ag(i);
At(i+1)=A(i+1)+ag(i+1); %At is Total Acceleration

end

%Total Acceleration
figure;
plot(t,At);
title('Total Acceleration Vs Time');
xlabel('Time(sec)');
ylabel('Total Acceleration(m/s^2)');
grid on;
indexmin = find(min(At) == At);
tmin = t(indexmin);
tsmin = At(indexmin);
indexmax = find(max(At) == At);
tmax = t(indexmax);
tsmax = At(indexmax);
16/10/17 2:18 PM G:\M Tech\Dynamics\COde\New\NmarkLin.m 2 of 2

strmin = ['Minimum = ',num2str(tsmin)];


text(tmin,tsmin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(tsmax)];
text(tmax,tsmax,strmax,'HorizontalAlignment','right');

%Relative Displacement Plot


figure;
plot(t,d);
grid on;
title('Relative Displacement Vs Time');
xlabel('Time(sec)');
ylabel('Relative Displacement(m)');
indexmin = find(min(d) == d);
tmin = t(indexmin);
dmin = d(indexmin);
indexmax = find(max(d) == d);
tmax = t(indexmax);
dmax = d(indexmax);
strmin = ['Minimum = ',num2str(dmin)];
text(tmin,dmin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(dmax)];
text(tmax,dmax,strmax,'HorizontalAlignment','right');

You might also like