Matlab Example PSV SV
Matlab Example PSV SV
m 1 of 3
% Read external forcing data from the Excel file using xlsread
[~, ~, external_forcing_data] = xlsread(excel_file, sheet_name);
% 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);
for j = 1:length(t_span)-1
t_i = t_span(j);
t_i_plus_1 = t_span(j+1);
% 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';
% 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 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;