How can I fix this error?

2 次查看(过去 30 天)
Anita Burns
Anita Burns 2024-4-3
评论: Voss 2024-4-4
%Compute stresses through the thickness of a laminate
%Read in number of layers
num_layers=input('Enter the number of layers: ');
%Read in material properties
E_L=input('Enter longitudinal modulus E_L [GPa]: ');
E_T=input('Enter transverse modulus E_T [GPa]: ');
G_LT=input('Enter shear modulus G_LT [GPa]: ');
v_LT=input('Enter Poisson"s Ratio v_LT: ');
thickness=input('Enter lamina thickness: ');
%Compute Q
Q=calculate_Q(E_L,E_T,G_LT,v_LT);
%Givin mid-plane strains and curvatures
%Format: [εx,εy,γxy, κx, κy]
epsilon_x=input('Enter εx: ');
epsilon_y=input('Enter εy: ');
gamma_xy=input('Enter γxy: ');
kappa_x=input('Enter κx: ');
kappa_y=input('Enter κy: ');
mid_plane_data=[epsilon_x, epsilon_y, gamma_xy, kappa_x, kappa_y];
%Compute stresses for each layer
top_bottom_stresses = cell(num_layers, 2);
for i = 1:size(mid_plane_data, 1)
data = mid_plane_data(i,:);
strain = data(1:3)';
curvature = data(4:5)';
% Compute S matrix
S = (Q)^-1;
% Compute strain due to curvature
strain_due_to_curvature = S .* curvature .* thickness / 2;
% Compute total strain at top and bottom
total_strain_top = strain + strain_due_to_curvature;
total_strain_bottom = strain - strain_due_to_curvature;
% Compute stress at top and bottom
stress_top = Q .* total_strain_top;
stress_bottom = Q .* total_strain_bottom;
top_bottom_stresses{i,1} = stress_top;
top_bottom_stresses{i,2} = stress_bottom;
end
%Display Results
fprintf('\nStress Values (in MPa):\n');
fprintf('%-10s %-10s %-10s %-10s %-10s %-10s %-10s\n', 'Layer', ...
'σx_top', 'σy_top', 'τxy_top', 'σx_bottom', 'σy_bottom', ...
'τxy_bottom');
for i=1:num_layers
stress_top=top_bottom_stresses{i,1};
stress_bottom=top_bottom_stresses{i,2};
fprintf('%-10d %-10.2f %-10.2f %-10.2f %-10.2f %-10.2f %-10.2f\n',i,stress_top(1), ...
stress_top(2),stress_top(3),stress_bottom(1),stress_bottom(2), ...
stress_bottom(3));
end
%Plot stress variations through thickness
layer_thickness=0:thickness:(num_layers*thickness);
figure;
hold on;
for i=1:num_layers
stress_top=top_bottom_stresses{i,1};
stress_bottom=top_bottom_stresses{i,2};
plot([stress_top(1),stress_bottom(1)], [layer_thickness(i), layer_thickness(i)],'r-');
plot([stress_top(2),stress_bottom(2)], [layer_thickness(i), layer_thickness(i)],'b-');
plot([stress_top(3),stress_bottom(3)], [layer_thickness(i), layer_thickness(i)],'g-');
end
hold off;
xlabel('Stress [MPa]');
ylabel('Thickness [m]');
title('Stress Variation through Thickness of Laminate');
legend('σx', 'σy', 'τxy');
grid on;
%Function to compute Q matrix
function Q=calculate_Q(E_L,E_T,G_LT,v_LT)
Q=zeros(3,3);
Q(1,1)=E_L/(1-v_LT^2);
Q(1,2)=v_LT*E_T/(1-v_LT^2);
Q(2,1)=Q(1,2);
Q(2,2)=E_T/(1-v_LT^2);
Q(3,3)=G_LT;
end
OUTPUT:
Enter the number of layers: 4
Enter longitudinal modulus E_L [GPa]: 38.60
Enter transverse modulus E_T [GPa]: 8.27
Enter shear modulus G_LT [GPa]: 4.14
Enter Poisson"s Ratio v_LT: 0.26
Enter lamina thickness: 0.002
Enter εx: 0.05
Enter εy: 0.00
Enter γxy: 0.00
Enter κx: 0
Enter κy: 0
Arrays have incompatible sizes for this operation.
Error in Project1 (line 40)
strain_due_to_curvature = S .* curvature .* thickness / 2;
Related documentation
  5 个评论
Anita Burns
Anita Burns 2024-4-4
I've got it figured out. Thank you for your help!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by