Demo entry 6357307

st

   

Submitted by anonymous on Apr 21, 2017 at 17:23
Language: Matlab. Code size: 2.7 kB.

%%
clc;
clear;
close;
%%
global EWave
%
File_Name='E:\Matlab_Code\Matlab_Code\Ground_Motions_Library\IMPVALL\H-E01140.AT2';%·¾¶ÐÞ¸Ä
%
fid = fopen(File_Name,'r');
% 
EWave.Str1 = fgetl (fid);
EWave.Str2 = fgetl (fid);
EWave.Str3 = fgetl (fid);
EWave.NPTs=fscanf(fid, '%i ',1);
EWave.DT  =fscanf(fid, '%f ',1);
EWave.Str4 = fgetl (fid);
%
EWave.Acel=zeros(EWave.NPTs,1); 
EWave.Time=zeros(EWave.NPTs,1); 
for i=1:EWave.NPTs
  EWave.Time(i)= (i-1)*EWave.DT; 
  EWave.Acel(i)= fscanf(fid, '%f ',1);
end
%
EWave.AMax=max(abs(EWave.Acel));
%
EWave.Acel=EWave.Acel*0.3/EWave.AMax;
%
% plot(EWave.Time,EWave.Acel);
%%
global MDOF
%
MDOF.ND = 5;
%
MDOF.MVec = zeros(MDOF.ND,1);
MDOF.KVec = zeros(MDOF.ND,1);
 
for i = 1:5
    MDOF.MVec(i) = 1000E3;
end
 
for i = 1:5
    MDOF.KVec(i) = 1.0*2000E6;
end
%%
MDOF.MMatrix = zeros(MDOF.ND, MDOF.ND);
MDOF.KMatrix = zeros(MDOF.ND, MDOF.ND);
%
for i = 1:MDOF.ND
    MDOF.MMatrix(i,i) = MDOF.MVec(i);
end
%
for i = 1:MDOF.ND
    if i == 1
        MDOF.KMatrix(i,i  ) =  MDOF.KVec(i  ) + MDOF.KVec(i+1);
        MDOF.KMatrix(i,i+1) = -MDOF.KVec(i+1);
    else
        if i == MDOF.ND
            MDOF.KMatrix(i,i-1) = -MDOF.KVec(i);
            MDOF.KMatrix(i,i  ) =  MDOF.KVec(i);
        else
            MDOF.KMatrix(i,i-1) = -MDOF.KVec(i  );
            MDOF.KMatrix(i,i  ) =  MDOF.KVec(i  ) + MDOF.KVec(i+1);
            MDOF.KMatrix(i,i+1) = -MDOF.KVec(i+1);
        end
    end
end
%
[MDOF.Eigen_Vec, MDOF.Eigen_Val] = eig(MDOF.MMatrix\MDOF.KMatrix);
%
MDOF.GMMatrix= transpose(MDOF.Eigen_Vec)*MDOF.MMatrix*MDOF.Eigen_Vec;
MDOF.GKMatrix= transpose(MDOF.Eigen_Vec)*MDOF.KMatrix*MDOF.Eigen_Vec;
MDOF.GEVector= transpose(MDOF.Eigen_Vec)*MDOF.MMatrix*ones(MDOF.ND,1);
%%
global SDOF
%
Result.Time=EWave.Time;
Result.Disp=zeros(length(Result.Time),MDOF.ND);
Result.Vel=zeros(length(Result.Time),MDOF.ND);
for i=1:MDOF.ND
SDOF.T=2*pirt(MDOF.Eigen_Val(i,i));
SDOF.W=2*pi/SDOF.T;
SDOF.D=0.00;
%
SDOF.AMatrix=zeros(2,2);
%
SDOF.AMatrix(1,2)=1;
SDOF.AMatrix(2,1)=-2*SDOF.D*SDOF.W;
SDOF.AMatrix(2,2)=-SDOF.W^2;
%
SDOF.BVector=zeros(2,1);
%
SDOF.BVector(2)=-1;
% Execute the time-history analysis
Solver.TD=[min(EWave.Time)  max(EWave.Time)];
Solver.IC=zeros(2,1);
Solver.Opt=odeset('MaxStep',2.0*EWave.DT);
%
[T,V]=ode45(@SDOF_Time_History_Analysis_ODE,Solver.TD,Solver.IC,Solver.Opt);
%
for j=1:length(EWave.Time)
   Result.Disp(j,i)=interp1(T,V(:,1),EWave.Time(j));
   Result.Vel(j,i)=interp1(T,V(:,2),EWave.Time(j));
end
%
disp(i);
%
% subplot(2,1,1)
% plot(T, V(:,1),'blue','LineWidth',2); grid on; hold on;
%
% subplot(2,1,2)
% plot(T, V(:,2),'red','LineWidth',2); grid on; hold on;
end
%%

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).