Code Error on Line 39 and 41

2 ビュー (過去 30 日間)
Briana Canet
Briana Canet 2022 年 3 月 21 日
編集済み: Cris LaPierre 2022 年 3 月 22 日
There is an error in my code in Line 39 and 41 in K_a2 and Mu_a2, respectively. Maybe a dot/period is missing.
% Approach 1
E_m = 70000; % Elastic modulus of matrix, MPa
v_m = .33; % Poisson ratio of matrix
E_i = 250000; % Elastic modulus of inclusion, MPa
v_i = .2; % Poisson ratio of inclusion
% Fiber volume fraction
f_i = 0:0.01:1;
% 0 is 0% fiber and 1 is 100% fiber content
% points to be plotted
K_m = (E_m)/(3*(1-2*(v_m))); % Bulk modulus of matrix, MPa
K_i = (E_i)/(3*(1-2*(v_i))); % Bulk modulus of inclusion, MPa
Mu_m = (E_m)/(2*(1+v_m));
Mu_i = (E_i)/(2*(1+v_i));
% Iteration 1
s1_a1 = (1+v_m)/(3*(1-v_m));
s2_a1 = (2*(4-5*v_m))/(15*(1-v_m));
K_a1 = K_m*((1+f_i*(K_m/(K_m-K_i)-s1_a1)^-1)).^-1;
Mu_a1 = Mu_m*((1+f_i*(Mu_m/(Mu_m-Mu_i)-s2_a1)^-1)).^-1;
% Iteration 2
v_a2 = (3*K_a1-2*Mu_a1)/(2*(3*K_a1+Mu_a1));
s1_a2 = (1+v_a2)/(3*(1-v_a2));
s2_a2 = (2*(4-5*v_a2))/(15*(1-v_a2));
K_a2 = K_m*(1+(f_i*((K_i/K_m)-1)*(1+((K_i/K_a1)-1)*s1_a2).^-1));
Error using /
Matrix dimensions must agree.
Mu_a2 = Mu_m*(1+(f_i*((Mu_i/K_m)-1)*(1+((Mu_i/Mu_a1)-1)*s1_a2).^-1));
% Reuss and Voigt
K_Reuss = (((1-f_i)/K_m) + (f_i/K_i)).^-1;
K_Voigt = (((1-f_i)*K_m) + (f_i*K_i));
% Plotting
figure(1)
plot(f_i,K_a1, 'Color', 'red', 'LineWidth', 2.5);
hold on;
plot(f_i,K_a2, 'Color', 'blue', 'LineWidth', 2.5);
hold off;
grid off;
legend('K_a1', 'K_a2','K_a3', 'K_a4', 'K_a5')
legend('Location','northwest','FontSize',12)
title('Comp1: Bulk Modulus vs. Inclusion Volume Fraction')
xlabel('Inclusion Volume Fraction, f_i')
ylabel('Bulk Modulus, K [MPa]')

回答 (1 件)

Cris LaPierre
Cris LaPierre 2022 年 3 月 21 日
You are correct on how to fix it.
f_i and K_a1 are both 1x101 vectors. Use elementwise operators to preserve the vectors.
K_a2 = K_m*(1+(f_i*((K_i/K_m)-1).*(1+((K_i./K_a1)-1)*s1_a2).^-1));
Mu_a2 = Mu_m*(1+(f_i*((Mu_i/K_m)-1).*(1+((Mu_i./Mu_a1)-1)*s1_a2).^-1));
% add elementwise operators ^* ^*
% Approach 1
E_m = 70000; % Elastic modulus of matrix, MPa
v_m = .33; % Poisson ratio of matrix
E_i = 250000; % Elastic modulus of inclusion, MPa
v_i = .2; % Poisson ratio of inclusion
% Fiber volume fraction
f_i = 0:0.01:1;
% 0 is 0% fiber and 1 is 100% fiber content
% points to be plotted
K_m = (E_m)/(3*(1-2*(v_m))); % Bulk modulus of matrix, MPa
K_i = (E_i)/(3*(1-2*(v_i))); % Bulk modulus of inclusion, MPa
Mu_m = (E_m)/(2*(1+v_m));
Mu_i = (E_i)/(2*(1+v_i));
% Iteration 1
s1_a1 = (1+v_m)/(3*(1-v_m));
s2_a1 = (2*(4-5*v_m))/(15*(1-v_m));
K_a1 = K_m*((1+f_i*(K_m/(K_m-K_i)-s1_a1)^-1)).^-1;
Mu_a1 = Mu_m*((1+f_i*(Mu_m/(Mu_m-Mu_i)-s2_a1)^-1)).^-1;
% Iteration 2
v_a2 = (3*K_a1-2*Mu_a1)/(2*(3*K_a1+Mu_a1));
s1_a2 = (1+v_a2)/(3*(1-v_a2));
s2_a2 = (2*(4-5*v_a2))/(15*(1-v_a2));
K_a2 = K_m*(1+(f_i*((K_i/K_m)-1).*(1+((K_i./K_a1)-1)*s1_a2).^-1));
Mu_a2 = Mu_m*(1+(f_i*((Mu_i/K_m)-1).*(1+((Mu_i./Mu_a1)-1)*s1_a2).^-1));
% Reuss and Voigt
K_Reuss = (((1-f_i)/K_m) + (f_i/K_i)).^-1;
K_Voigt = (((1-f_i)*K_m) + (f_i*K_i));
% Plotting
figure(1)
plot(f_i,K_a1, 'Color', 'red', 'LineWidth', 2.5);
hold on;
plot(f_i,K_a2, 'Color', 'blue', 'LineWidth', 2.5);
hold off;
grid off;
legend('K_a1', 'K_a2')
legend('Location','northwest','FontSize',12)
title('Comp1: Bulk Modulus vs. Inclusion Volume Fraction')
xlabel('Inclusion Volume Fraction, f_i')
ylabel('Bulk Modulus, K [MPa]')
  3 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 3 月 22 日
編集済み: Cris LaPierre 2022 年 3 月 22 日
For the same reason you use a ".^" at the end of each expression.
You can read more about array vs matrix operations here.
A = 1:3;
% with the dot
3./A
ans = 1×3
3.0000 1.5000 1.0000
% without the dot
3/A
Error using /
Matrix dimensions must agree.
Steven Lord
Steven Lord 2022 年 3 月 22 日
Do you want to perform array or matrix operations?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeThermal Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by