Why am I receiving this error?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
% Input data
EL = 38.60e9; % Longitudinal modulus (Pa)
ET = 8.27e9; % Transverse modulus (Pa)
GLT = 4.14e9; % Shear modulus (Pa)
nuLT = 0.26; % Poisson's ratio
thickness = 0.002; % Thickness of each layer (m)
layer_angles = [45, -45, -45, 45]; % Fiber orientations of each layer (degrees)
mid_plane_strains = [0.05, 0.00, 0.00]; % Mid-plane strains (epsilon_x, epsilon_y, gamma_xy)
curvatures = [0.05, 0.020, 0.0250; 0, 0.010, 0.0125]; % Curvatures (kappa_x, kappa_y, kappa_xy)
% Number of layers
num_layers = length(layer_angles);
% Initialize arrays to store stresses
sigma_x_top = zeros(num_layers, 1);
sigma_y_top = zeros(num_layers, 1);
tau_xy_top = zeros(num_layers, 1);
sigma_x_bottom = zeros(num_layers, 1);
sigma_y_bottom = zeros(num_layers, 1);
tau_xy_bottom = zeros(num_layers, 1);
% Compute stresses for each layer
for i = 1:num_layers
theta = deg2rad(layer_angles(i));
% Transformation matrix
T = [cos(theta)^2, sin(theta)^2, 2*sin(theta)*cos(theta);
sin(theta)^2, cos(theta)^2, -2*sin(theta)*cos(theta);
-sin(theta)*cos(theta), sin(theta)*cos(theta), cos(theta)^2-sin(theta)^2];
% Reduced stiffness matrix
Q11 = EL / (1 - nuLT^2);
Q12 = nuLT * EL / (1 - nuLT^2);
Q22 = ET / (1 - nuLT^2);
Q66 = GLT;
Q = [Q11, Q12, 0;
Q12, Q22, 0;
0, 0, Q66];
% Transform stiffness matrix to layer coordinates
Q_bar = (T) / Q * T';
% Strain matrix
strain = [mid_plane_strains(1); mid_plane_strains(2); mid_plane_strains(3)];
curvature = [curvatures(1, i); curvatures(2, i); 0]; % Assume no curvature in z direction
% Stress resultants
stress_resultants = Q_bar * strain + curvature;
% Stresses at top and bottom of the layer
sigma_x_top(i) = stress_resultants(1) + mid_plane_strains(1) * thickness / 2;
sigma_y_top(i) = stress_resultants(2) + mid_plane_strains(2) * thickness / 2;
tau_xy_top(i) = stress_resultants(3);
sigma_x_bottom(i) = stress_resultants(1) - mid_plane_strains(1) * thickness / 2;
sigma_y_bottom(i) = stress_resultants(2) - mid_plane_strains(2) * thickness / 2;
tau_xy_bottom(i) = stress_resultants(3);
end
% Display results
fprintf('Layer\tSigma_x_top (Pa)\tSigma_y_top (Pa)\tTau_xy_top (Pa)\tSigma_x_bottom (Pa)\tSigma_y_bottom (Pa)\tTau_xy_bottom (Pa)\n');
for i = 1:num_layers
fprintf('%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n', i, sigma_x_top(i), sigma_y_top(i), tau_xy_top(i), sigma_x_bottom(i), sigma_y_bottom(i), tau_xy_bottom(i));
end
% Plot stress variation through thickness
layer_depths = linspace(-thickness/2, thickness/2, num_layers);
figure;
hold on;
plot(sigma_x_top, layer_depths, 'r', 'LineWidth', 1.5);
plot(sigma_y_top, layer_depths, 'g', 'LineWidth', 1.5);
plot(tau_xy_top, layer_depths, 'b', 'LineWidth', 1.5);
plot(sigma_x_bottom, layer_depths, 'r--', 'LineWidth', 1.5);
plot(sigma_y_bottom, layer_depths, 'g--', 'LineWidth', 1.5);
plot(tau_xy_bottom, layer_depths, 'b--', 'LineWidth', 1.5);
title('Stress Variation Through Laminate Thickness');
xlabel('Stress (Pa)');
ylabel('Depth (m)');
legend('\sigma_x', '\sigma_y', '\tau_{xy}', 'Location', 'best');
grid on;
hold off;
ERROR:
Index in position 2 exceeds array bounds. Index must not exceed 3.
Error in Project_1_new (line 45)
curvature = [curvatures(1, i); curvatures(2, i); 0]; % Assume no curvature in z direction
0 Commenti
Risposte (2)
Alan Stevens
il 19 Apr 2024
You have 4 layers
layer_angles = [45, -45, -45, 45];
but data for only three
mid_plane_strains = [0.05, 0.00, 0.00]; % Mid-plane strains (epsilon_x, epsilon_y, gamma_xy)
curvatures = [0.05, 0.020, 0.0250; 0, 0.010, 0.0125]; % Curvatures (kappa_x, kappa_y, kappa_xy)
0 Commenti
Voss
il 19 Apr 2024
curvatures is of size 2-by-3:
curvatures = [0.05, 0.020, 0.0250; 0, 0.010, 0.0125] % Curvatures (kappa_x, kappa_y, kappa_xy)
layer_angles is of size 1-by-4:
layer_angles = [45, -45, -45, 45] % Fiber orientations of each layer (degrees)
The loop iterates from i = 1 to i = 4:
num_layers = length(layer_angles);
% ...
for i = 1:num_layers
Therefore, on the 4th iteration, when this line tries to access elements from column 4 of curvatures:
curvature = [curvatures(1, i); curvatures(2, i); 0]; % Assume no curvature in z direction
the error is thrown because curvatures only has 3 columns.
0 Commenti
Vedere anche
Categorie
Scopri di più su Stress and Strain in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!