Arrays have incompatible sizes for this operation.

1 visualizzazione (ultimi 30 giorni)
I am trying to plot my graph for 4 given values in one graph for this matlab code.
format long
% Given Values
T = 429.65; % K - Given Temperture
P = 99.6 ; % kPa - Pressure
% Specific Diameters given
Dp1 = 0.01:0.01:10;
Dp = Dp1 * 10^-6;
%Actual particle Density given.
Pp = 1260; % kg/m^3
% Standard Temperture and Mu at SATP
Ts0 = 298.15; % K
Ts = 110.4; % K
Rair = 0.287; % kJ / kg * K
Mu_s = 1.849*10^-5; % kg/m*s
g = 9.81;
% Calculate Air Density
Pa = P / (Rair * T);
Mu = Mu_s * (T/Ts0)^(3/2) * (Ts0+Ts)/(T+Ts);
% lamda - Mean free path
lamda1 = (Mu/0.499) * sqrt(pi/(8*Pa*P*1000)); % Unit m
lamda = lamda1 *10^6; % Unit Mu*m
% Knudsen number
Kn = lamda1 ./ Dp;
% Cunningham Correction Factor
C = 1 + Kn .* (2.514+0.80.*exp(-0.55./Kn));
% -----------------------------------------------------------------
% Given
Df = [5, 10, 15, 20] *10^-6; % Given in microns change to m
U0 = 0.225; % m/s
e = 0.875; % fraction
L = 0.00335; % m
%intial
Kb = 1.381*10^-23
% Calvert & Englund
Stk = ((Pp-Pa).*Dp.^2.*(U0./e)) ./ (18.*Mu.*Df)
nfDpCE = ((Stk)./(Stk+0.425)).^2
%Cheng
Dap = (Kb.*T.*C)./ (3.*pi.*Mu.*Dp)
alpha = 1 - e;
Kk = -0.5.*log(alpha)+alpha-0.25.*alpha.^2-0.75
Pe = (Df.*U0)./(Dap)
nfDpCheng = 2.92 .* ((1-alpha)./Kk).^(1./3).*Pe.^(-2./3);
nfDp = nfDpCE + nfDpCheng
Lc = (pi./4).*(e./(1-e)).*(Df./nfDp)
nDp = (1 - exp(-L./Lc) )*100
% ========================================================================
Dp2= log(Dp1*10^1);
plot(Dp2,nDp)
This error shows up and I couldn't be able to fix it can you please assist me on this, thank you
Arrays have incompatible sizes for this operation.
Error in HW14Q2 (line 45)
Stk = ((Pp-Pa).*Dp.^2.*(U0./e)) ./ (18.*Mu.*Df)

Risposta accettata

Walter Roberson
Walter Roberson il 21 Apr 2022
format long
% Given Values
T = 429.65; % K - Given Temperture
P = 99.6 ; % kPa - Pressure
% Specific Diameters given
Dp1 = 0.01:0.01:10;
Dp = Dp1 * 10^-6;
%Actual particle Density given.
Pp = 1260; % kg/m^3
% Standard Temperture and Mu at SATP
Ts0 = 298.15; % K
Ts = 110.4; % K
Rair = 0.287; % kJ / kg * K
Mu_s = 1.849*10^-5; % kg/m*s
g = 9.81;
% Calculate Air Density
Pa = P / (Rair * T);
Mu = Mu_s * (T/Ts0)^(3/2) * (Ts0+Ts)/(T+Ts);
% lamda - Mean free path
lamda1 = (Mu/0.499) * sqrt(pi/(8*Pa*P*1000)); % Unit m
lamda = lamda1 *10^6; % Unit Mu*m
% Knudsen number
Kn = lamda1 ./ Dp;
% Cunningham Correction Factor
C = 1 + Kn .* (2.514+0.80.*exp(-0.55./Kn));
% -----------------------------------------------------------------
% Given
Df = [5, 10, 15, 20] *10^-6; % Given in microns change to m
U0 = 0.225; % m/s
e = 0.875; % fraction
L = 0.00335; % m
%intial
Kb = 1.381*10^-23
Kb =
1.381000000000000e-23
% Calvert & Englund
whos
Name Size Bytes Class Attributes C 1x1000 8000 double Df 1x4 32 double Dp 1x1000 8000 double Dp1 1x1000 8000 double Kb 1x1 8 double Kn 1x1000 8000 double L 1x1 8 double Mu 1x1 8 double Mu_s 1x1 8 double P 1x1 8 double Pa 1x1 8 double Pp 1x1 8 double Rair 1x1 8 double T 1x1 8 double Ts 1x1 8 double Ts0 1x1 8 double U0 1x1 8 double cmdout 1x33 66 char e 1x1 8 double g 1x1 8 double lamda 1x1 8 double lamda1 1x1 8 double
Stk = ((Pp-Pa).*Dp.^2.*(U0./e)) ./ (18.*Mu.*Df)
Arrays have incompatible sizes for this operation.
Dp is 1 x 1000, but Df is 1 x 4, so you are dividing a 1 x 1000 element-wise by a 1 x 4.
  1 Commento
Walter Roberson
Walter Roberson il 21 Apr 2022
Modificato: Walter Roberson il 21 Apr 2022
If you want each Df in combination with each Dp then
format long
% Given Values
T = 429.65; % K - Given Temperture
P = 99.6 ; % kPa - Pressure
% Specific Diameters given
Dp1 = 0.01:0.01:10;
Dp = Dp1 * 10^-6;
%Actual particle Density given.
Pp = 1260; % kg/m^3
% Standard Temperture and Mu at SATP
Ts0 = 298.15; % K
Ts = 110.4; % K
Rair = 0.287; % kJ / kg * K
Mu_s = 1.849*10^-5; % kg/m*s
g = 9.81;
% Calculate Air Density
Pa = P / (Rair * T);
Mu = Mu_s * (T/Ts0)^(3/2) * (Ts0+Ts)/(T+Ts);
% lamda - Mean free path
lamda1 = (Mu/0.499) * sqrt(pi/(8*Pa*P*1000)); % Unit m
lamda = lamda1 *10^6; % Unit Mu*m
% Knudsen number
Kn = lamda1 ./ Dp;
% Cunningham Correction Factor
C = 1 + Kn .* (2.514+0.80.*exp(-0.55./Kn));
% -----------------------------------------------------------------
% Given
Df = [5, 10, 15, 20].' *10^-6; % Given in microns change to m
U0 = 0.225; % m/s
e = 0.875; % fraction
L = 0.00335; % m
%intial
Kb = 1.381*10^-23;
% Calvert & Englund
Stk = ((Pp-Pa).*Dp.^2.*(U0./e)) ./ (18.*Mu.*Df);
nfDpCE = ((Stk)./(Stk+0.425)).^2;
%Cheng
Dap = (Kb.*T.*C)./ (3.*pi.*Mu.*Dp);
alpha = 1 - e;
Kk = -0.5.*log(alpha)+alpha-0.25.*alpha.^2-0.75;
Pe = (Df.*U0)./(Dap);
nfDpCheng = 2.92 .* ((1-alpha)./Kk).^(1./3).*Pe.^(-2./3);
nfDp = nfDpCE + nfDpCheng;
Lc = (pi./4).*(e./(1-e)).*(Df./nfDp);
nDp = (1 - exp(-L./Lc) )*100;
% ========================================================================
Dp2= log(Dp1*10^1);
plot(Dp2,nDp)
legend(string(Df))

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming 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!

Translated by