Prepare a MATLAB code that develop Response Spectrum (Acceleration & Time ordinates) based on acceleration (m/s/s) & time(seconds) records contained in a .txt file?

37 vues (au cours des 30 derniers jours)
Prepare a MATLAB code that develop Response Spectrum (Acceleration & Time ordinates) based on acceleration (m/s/s) & time(seconds) records contained in a .txt file for multiple damping ratio (i.e. 0%, 2%, 5% etc.)?
Please find the attached acceleration-time record (.txt file).

Réponses (1)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU le 10 Mai 2024
Hi Parvesh,
Try working with the below code snippet.
% Read data from the text file (assuming two columns)
[time, acceleration] = textscan('india.199110192123.abhat.dat_output.txt', '%f %f');
% Attempt conversion to numeric for entire time data (handle cell or numeric)
try
time = cellfun(@str2num, time); % Attempt conversion for all elements
catch ME % Catch potential conversion errors
warning('Error converting time data to numeric. Skipping response spectrum calculation.');
return;
end
% Define damping ratio
damping_ratio = 0.05; % Adjust as needed
% ... (rest of the code from Approach 1)
% Mass (assuming a simple mass-spring system)
mass = 1; % You can replace this with your actual mass
% Stiffness (assuming a simple spring)
stiffness = 100; % You can replace this with your actual stiffness
% Damping matrix (proportional to mass and identity matrix)
damping = damping_ratio * mass * eye(length(time));
% Stiffness matrix
K = diag(2*ones(length(time)-1,1), 1) - diag(ones(length(time),1), 0); % Adjust for different systems
K(1,1) = stiffness; % Set first element for stiffness
% Solve eigenvalue problem (check for successful solution)
[V, D] = eig(mass*eye(length(time)), damping);
if ~all(isfinite(diag(D))) % Check for non-finite eigenvalues
warning('Eigenvalue problem encountered non-finite values. Skipping response spectrum calculation.');
return;
end
% Handle potential mismatch between acceleration and V
num_rows_diff = size(V, 1) - size(acceleration, 1);
if num_rows_diff > 0
warning('Number of rows in acceleration is less than DOF in V. Truncating V (might affect accuracy).');
V = V(1:end-num_rows_diff, :); % Truncate V to match acceleration rows
end
% Modal transformation
q = V \ acceleration;
% Frequency response function (assuming equal spacing in time)
% Ensure time difference is calculated correctly
dt = diff(time); % Use diff for numeric time vector
if isempty(dt) % Handle potential single-element time data
warning('Time data might have a single element. Skipping response spectrum calculation.');
return;
end
f = linspace(0, 1/(2*dt(1)), length(time)/2 + 1); % Frequency vector (adjust if needed)
omega = 2*pi*f;
H = zeros(length(f), size(V,2));
% Element-wise multiplication (avoiding unnecessary diagonals)
for j = 1:size(V,2)
H(:,j) = V(:,j)' .* freqresp(V(:,j), mass, damping(j,j), stiffness, [], omega);
end
% Absolute response spectrum (considering all modes)
response_spectrum = abs(sum(q.*H, 2));
% Plot the response spectrum
figure;
plot(time, response_spectrum);
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Response Spectrum (Damping Ratio: 5%)');
% Note: This code assumes a simple mass-spring system. Adjust K and mass for other systems.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by