Plotting Displacement, Velocity and Acceleration vs. Time

10 ビュー (過去 30 日間)
Jeanette Sarra
Jeanette Sarra 2019 年 4 月 3 日
コメント済み: Kim Hao Teong 2021 年 2 月 23 日
Hi, I am a new MATLAB user, so please bear with me. I'm trying to plot the values of displacement(u), velocity(v), and acceleration(a) versus time(tn) using the Newmark's Beta Method for a SDOF system. But all I get is an empty plot. I would really appreciate if someone could help me. Thank you in advance.
%%
%Newmark-Beta Method
%% Given Values
clear all;
clc;
close all;
load elcentro.dat % load the Seismic data
t = elcentro(:,1); %time values
Ag = elcentro(:,2); %acceleration values
g = 9.81; %acceleration due to gravity
Dt = 0.02; %time step
m = 1; %mass
xi = 0.02; %damping ratio
endp = 31.18; %terminating value of t
tn = 0:Dt:31.18;
T = 1; %Period
%% Solver
omega = 2*pi/T;
k = (omega^2)*m; %stiffness
c = 2*m*omega*xi; %damping coefficient
%parameters
gamma = 1/2;
beta = 1/6;
u(1) = 0; %displacement initial condition
v(1) = 0; %velocity initial condition
a(1) = 0; %acceleration initial condition
keff = k +gamma*c/(beta*Dt) + m/(beta*Dt*Dt);
A = m/(beta*Dt)+gamma*c/beta;
B = m/(2*beta)+(Dt*c*((0.5*gamma/beta)-1));
u0 = u;
v0 = v;
a0 = a;
%loop for every time step
for i = 1:(length(t)-Dt)
DF = -m*g.*(Ag(i+1)-Ag(i));
[t,u,v,a] = Newmark(t,A,B,DF,Dt,keff,u0,v0,a0,gamma,beta);
u_t1(:,i) = u(:,1)';
v_t1(:,i) = v(:,1)';
a_t1(:,i) = a(:,1)';
u0 = u;
v0 = v;
a0 = a;
t0 = t;
end
umax = max(abs(u_t1));
vmax = max(abs(v_t1));
amax = max(abs(a_t1));
fprintf('\n-------NEWMARK BETA METHOD-------\n');
fprintf('\nMaximum Response of a SDOF System\n\n');
fprintf('Maximum Displacement = %f\n',umax);
fprintf('Maximum Velocity = %f\n',vmax);
fprintf('Maximum Acceleration = %f\n',amax);
%% Plotting the Figures for Response
figure(1)
plot(tn,u);
title('Displacement Response')
xlabel('Period(sec)');
ylabel('Displacement (m)');
% Save picture
saveas(gca,'Displacement2.tif');
figure(2)
plot(tn,v);
title('Velocity Response')
xlabel('Period(sec)');
ylabel('Velocity (m/s)');
% Save picture
saveas(gca,'Velocity2.tif');
figure(3)
plot(tn,a);
title('Acceleration Response')
xlabel('Period(sec)');
ylabel('Acceleration (m/s^2)');
% Save picture
saveas(gca,'Acceleration2.tif');
%% Function for Newmark-Beta
function [t,u,v,a] = Newmark (t,A,B,DF,Dt,keff,u0,v0,a0,gamma,beta)
DFbar = DF + A*v0+B*a0;
Du = DFbar/keff;
Dudot = gamma*Du/(beta*Dt)-((gamma*v0)/beta)+ Dt*a0*(1-0.5*(gamma/beta));
Dudotdot = Du/(beta*Dt*Dt)-v0/(beta*Dt)-a0/(2*beta);
u = u0+Du;
v = v0+Dudot;
a = a0+Dudotdot;
t = t+Dt;
end
  2 件のコメント
Adam Danz
Adam Danz 2019 年 4 月 3 日
We need elcentro.dat.
Jeanette Sarra
Jeanette Sarra 2019 年 4 月 4 日

サインインしてコメントする。

採用された回答

KSSV
KSSV 2019 年 4 月 4 日
function Myfunction()
%% @ Jeanette M. Sarra, CE 165
%Newmark-Beta Method
%% Given Values
clear all;
clc;
close all;
elcentro = load('elcentro.dat') ; % load the Seismic data
t = elcentro(:,1); %time values
Ag = elcentro(:,2); %acceleration values
g = 9.81; %acceleration due to gravity
Dt = 0.02; %time step
m = 1; %mass
xi = 0.02; %damping ratio
endp = 31.18; %terminating value of t
tn = 0:Dt:31.18;
T = 1; %Period
%% Solver
omega = 2*pi/T;
k = (omega^2)*m; %stiffness
c = 2*m*omega*xi; %damping coefficient
%parameters
gamma = 1/2;
beta = 1/6;
u(1) = 0; %displacement initial condition
v(1) = 0; %velocity initial condition
a(1) = 0; %acceleration initial condition
keff = k +gamma*c/(beta*Dt) + m/(beta*Dt*Dt);
A = m/(beta*Dt)+gamma*c/beta;
B = m/(2*beta)+(Dt*c*((0.5*gamma/beta)-1));
u0 = u;
v0 = v;
a0 = a;
%loop for every time step
u_t1 = zeros(1,length(t)) ; u_t1(1) = u0 ;
v_t1 = zeros(1,length(t)) ; v_t1(1) = v0 ;
a_t1 = zeros(1,length(t)) ; a_t1(1) = a0 ;
for i = 2:(length(t)-Dt)
DF = -m*g.*(Ag(i+1)-Ag(i));
[t,u,v,a] = Newmark(t,A,B,DF,Dt,keff,u0,v0,a0,gamma,beta);
u_t1(:,i) = u(:,1)';
v_t1(:,i) = v(:,1)';
a_t1(:,i) = a(:,1)';
u0 = u;
v0 = v;
a0 = a;
t0 = t;
end
umax = max(abs(u_t1));
vmax = max(abs(v_t1));
amax = max(abs(a_t1));
fprintf('\n-------NEWMARK BETA METHOD-------\n');
fprintf('\nMaximum Response of a SDOF System\n\n');
fprintf('Maximum Displacement = %f\n',umax);
fprintf('Maximum Velocity = %f\n',vmax);
fprintf('Maximum Acceleration = %f\n',amax);
%% Plotting the Figures for Response
figure(1)
plot(tn,u_t1);
title('Displacement Response')
xlabel('Period(sec)');
ylabel('Displacement (m)');
% Save picture
saveas(gca,'Displacement2.tif');
figure(2)
plot(tn,v_t1);
title('Velocity Response')
xlabel('Period(sec)');
ylabel('Velocity (m/s)');
% Save picture
saveas(gca,'Velocity2.tif');
figure(3)
plot(tn,a_t1);
title('Acceleration Response')
xlabel('Period(sec)');
ylabel('Acceleration (m/s^2)');
% Save picture
saveas(gca,'Acceleration2.tif');
end
%% Function for Newmark-Beta
function [t,u,v,a] = Newmark (t,A,B,DF,Dt,keff,u0,v0,a0,gamma,beta)
DFbar = DF + A*v0+B*a0;
Du = DFbar/keff;
Dudot = gamma*Du/(beta*Dt)-((gamma*v0)/beta)+ Dt*a0*(1-0.5*(gamma/beta));
Dudotdot = Du/(beta*Dt*Dt)-v0/(beta*Dt)-a0/(2*beta);
u = u0+Du;
v = v0+Dudot;
a = a0+Dudotdot;
t = t+Dt;
end
  2 件のコメント
Jeanette Sarra
Jeanette Sarra 2019 年 4 月 4 日
It worked! I've been struggling with this code for a day now. hahahhaha. Thank you for your help.
Kim Hao Teong
Kim Hao Teong 2021 年 2 月 23 日
Hi, what is your unit of acceleration in your elcentro.dat?

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by