0% found this document useful (0 votes)
19 views

Matlab Example PSV SV

This document contains code to numerically simulate the response of a single-degree-of-freedom system subjected to earthquake ground motion. The code loops through different values of natural period and damping to calculate response quantities like maximum displacement and velocity.

Uploaded by

Hammad Sarguroh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Matlab Example PSV SV

This document contains code to numerically simulate the response of a single-degree-of-freedom system subjected to earthquake ground motion. The code loops through different values of natural period and damping to calculate response quantities like maximum displacement and velocity.

Uploaded by

Hammad Sarguroh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

6/10/23 4:28 PM C:\Users\MSI PC\Documents\...\SPECTRUM.

m 1 of 3

% Start recording the output in 'output.txt'


%diary('hammad.txt');
% Define input values
z = 0.02; % time interval of loading

% Define time span and time step


dt = 0.02; % Time step
t_span = 0:dt:78.6; % Time span from 0 to 78.6 with a step size of 0.02 seconds

% Define T value ranges and step sizes


T_ranges = [0.04:0.01:0.20, 0.20:0.02:0.50, 0.50:0.05:1.00, 1.00:0.10:2.00, 2.00:
0.20:4.00];

% Initialize vector and initial conditions


X_0 = 0; % Initial displacement
X_prime_0 = 0; % Initial velocity
X = zeros(length(t_span), 2); % Initialize the vector
X(1, :) = [X_0, X_prime_0]; % Set initial conditions

% Initialize variables to store maximum values


max_displacement = zeros(length(T_ranges), 2);
max_velocity = zeros(length(T_ranges), 2);
SV = zeros(length(T_ranges), 2);
PSV = zeros(length(T_ranges), 2);

% Specify the Excel file path containing external forcing data


excel_file = 'PGA.xls'; % Replace with your Excel file path
sheet_name = 'Sheet1';

% Read external forcing data from the Excel file using xlsread
[~, ~, external_forcing_data] = xlsread(excel_file, sheet_name);

% Extract the external forcing values column


external_forcing_values = cell2mat(external_forcing_data(:, 2));

% Loop through different values of x


for x_idx = 1:2 % Loop through x = 0 and x = 0.05
if x_idx == 1
x = 0;
else
x = 0.05;
end

% Main loop for numerical scheme


for i = 1:length(T_ranges)
T = T_ranges(i);
y = 2*pi / T; % Calculate y based on T

% Calculate [A] and [B] matrices using DHMAT subroutine


6/10/23 4:28 PM C:\Users\MSI PC\Documents\...\SPECTRUM.m 2 of 3

[A, B] = DHMAT(x, y, z);

% Print [A] and [B] matrices just once for each value of T and x
%fprintf('x=%.2f, T=%.2f, [A] matrix:\n', x, T);
%disp(A);
%fprintf('x=%.2f, T=%.2f, [B] matrix:\n', x, T);
%disp(B);

% Initialize variables to store maximum values for this T and x


max_displacement_T = -inf; % Initialize to negative infinity
max_velocity_T = -inf; % Initialize to negative infinity

for j = 1:length(t_span)-1
t_i = t_span(j);
t_i_plus_1 = t_span(j+1);

% Determine the appropriate A and B matrices for the current y value


A = A;
B = B;

% Determine the appropriate external forcing values for the current time
fi = external_forcing_values(j); % Use external forcing data

% Calculate the new state vector [X_i+1, X'_i+1] using the numerical
scheme
X_i = X(j, :);
X_i_plus_1 = A * X_i' + B * [fi, external_forcing_values(j+1)]';

X(j+1, :) = X_i_plus_1';

% Update maximum displacement and velocity for this T and x


max_displacement_T = max(max_displacement_T, X_i_plus_1(1));
max_velocity_T = max(max_velocity_T, X_i_plus_1(2));

%Print Xi_plus_1 and [fi, external_forcing_values(j+1)] side by side at


each time step with T and x
%fprintf('x=%.2f, T=%.2f, Time: %.2f, Xi_plus_1: [%.4f, %.4f], [fi,
external_forcing_values(j+1)]: [%.4f, %.4f]\n', x, T, t_i_plus_1, X_i_plus_1(1),
X_i_plus_1(2), fi, external_forcing_values(j+1));
end
% Stop recording the output
%diary off;

% Store maximum displacement and velocity for this T and x


max_displacement(i, x_idx) = max_displacement_T;
max_velocity(i, x_idx) = max_velocity_T;

% Calculate SV (spectral velocity) for this T and x


SV(i, x_idx) = max_velocity_T;
6/10/23 4:28 PM C:\Users\MSI PC\Documents\...\SPECTRUM.m 3 of 3

% Calculate PSV (peak spectral velocity ) for this T and x


PSV(i, x_idx) = max_displacement_T * y;

% Print maximum displacement, velocity, SV, and PSV for this T and x
fprintf('x=%.2f, T=%.2f, Maximum Displacement: %.4f\n' , x, T,
max_displacement_T);
fprintf('x=%.2f, T=%.2f, Maximum Velocity: %.4f\n' , x, T, max_velocity_T);
fprintf('x=%.2f, T=%.2f, SV (spectral velocity): %.4f\n' , x, T, SV(i,
x_idx));
fprintf('x=%.2f, T=%.2f, PSV (peak spectral velocity y): %.4f\n' , x, T, PSV
(i, x_idx));
end
end

% Plot SV (spectral velocity) vs. T for both x values with legends


figure;
semilogx(T_ranges, SV(:, 1), '-', 'LineWidth', 2, 'DisplayName', 'zeta = 0');
hold on;
semilogx(T_ranges, SV(:, 2), '-', 'LineWidth', 2, 'DisplayName', 'zeta = 0.05');
hold off;
title('SV (spectral velocity) vs. T' );
xlabel('Natural Time Period T (sec)' );
ylabel('Spectral Velocity SV (m/sec)' );
xlim([0.04, 4]); % Set the x-axis limits to [0.04, 4] on a log scale
ylim([0, 1]); % Set the y-axis limits to [0, 1]
xticks([0.04, 0.1, 0.5, 1, 2, 4]); % Set custom x-axis ticks on a log scale
legend;

% Plot PSV (peak spectral velocity) vs. T for both x values with legends
figure;
semilogx(T_ranges, PSV(:, 1), '-', 'LineWidth', 2, 'DisplayName', 'zeta = 0');
hold on;
semilogx(T_ranges, PSV(:, 2), '-', 'LineWidth', 2, 'DisplayName', 'zeta = 0.05');
hold off;
title('PSV (peak spectral velocity) vs. T' );
xlabel('Natural Time Period T (sec)' );
ylabel('Peak Spectral Velocity SA (m/sec)' );
xlim([0.04, 4]); % Set the x-axis limits to [0.04, 4] on a log scale
ylim([0, 1]); % Set the y-axis limits to [0, 1]
xticks([0.04, 0.1, 0.5, 1, 2, 4]); % Set custom x-axis ticks on a log scale
legend;

You might also like