I would to get my equation to iterate 15 times

1 view (last 30 days)
Abdullah Alsayegh
Abdullah Alsayegh on 27 Mar 2022
Commented: Voss on 27 Mar 2022
I have three equations that are connected to my solution and I need them to iterate 15 times to get a specific solution.
Example here shown in Excle.
The first guess is assigned as Vt_guess and it should calculate the Re, Cd and Vt. after that I want to use the new Vt to be used to calcalute for Re, Cd and the new Vt for 15 times.
My coding:
% Given Temperture and Pressure
T = 308.15; % K - Given Temperture
P = 101.325 ; % kPa - Pressure
% 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);
% Viscosity Mu and v
Mu = Mu_s * (T/Ts0)^(3/2) * (Ts0+Ts)/(T+Ts);
v = Mu / Pa;
% lamda - Mean free path
lamda1 = (Mu/0.499) * sqrt(pi/(8*Pa*P*1000)); % Unit m
lamda = lamda1 *10^6; % Unit Mu*m
% Specific Diameters given
Dp1 = 150;
Dp = Dp1 * 10^-6;
%Actual particle Density given.
Pp = 1450; % kg/m^3
% Knudsen number
Kn = lamda1 / Dp;
% Cunningham Correction Factor
C = 1 + Kn * (2.514+0.80*exp(-0.55/Kn));
% Calcualte
Vt_guess = (((Pp-Pa)/18)*Dp^2*g*(C/Mu));
Re = (Pa*Vt_guess*Dp)/Mu;
Cd = (24/Re) + ((2.6*(Re/5.0)) / (1 + (Re/5.0)^1.52)) + ((0.411*(Re/(2.63*10^5))^-7.94) / (1+(Re/(2.63*10^5))^-8)) + ((0.25*(Re/10^6)) / (1+(Re/10^6)));
Vt = sqrt((4/3)*((Pp-Pa)/Pa)*g*Dp*(C/Cd));

Accepted Answer

Voss
Voss on 27 Mar 2022
format long
% Given Temperture and Pressure
T = 308.15; % K - Given Temperture
P = 101.325 ; % kPa - Pressure
% 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);
% Viscosity Mu and v
Mu = Mu_s * (T/Ts0)^(3/2) * (Ts0+Ts)/(T+Ts);
v = Mu / Pa;
% lamda - Mean free path
lamda1 = (Mu/0.499) * sqrt(pi/(8*Pa*P*1000)); % Unit m
lamda = lamda1 *10^6; % Unit Mu*m
% Specific Diameters given
Dp1 = 150;
Dp = Dp1 * 10^-6;
%Actual particle Density given.
Pp = 1450; % kg/m^3
% Knudsen number
Kn = lamda1 / Dp;
% Cunningham Correction Factor
C = 1 + Kn * (2.514+0.80*exp(-0.55/Kn));
% Calcualte
Vt_guess = (((Pp-Pa)/18)*Dp^2*g*(C/Mu))
Vt_guess =
0.937964464480552
n_iterations = 0;
while n_iterations < 15
Re = (Pa*Vt_guess*Dp)/Mu;
Cd = (24/Re) + ((2.6*(Re/5.0)) / (1 + (Re/5.0)^1.52)) + ((0.411*(Re/(2.63*10^5))^-7.94) / (1+(Re/(2.63*10^5))^-8)) + ((0.25*(Re/10^6)) / (1+(Re/10^6)));
Vt = sqrt((4/3)*((Pp-Pa)/Pa)*g*Dp*(C/Cd));
n_iterations = n_iterations+1;
Vt_guess = Vt
end
Vt_guess =
0.750633827939021
Vt_guess =
0.697325575030236
Vt_guess =
0.680218345749534
Vt_guess =
0.674501359581471
Vt_guess =
0.672564357188532
Vt_guess =
0.671904988513356
Vt_guess =
0.671680176014722
Vt_guess =
0.671603484140667
Vt_guess =
0.671577316833584
Vt_guess =
0.671568387968173
Vt_guess =
0.671565341175319
Vt_guess =
0.671564301511837
Vt_guess =
0.671563946744403
Vt_guess =
0.671563825685962
Vt_guess =
0.671563784376786
  2 Comments
Voss
Voss on 27 Mar 2022
You're welcome!
Yes, simply remove the semicolon at the end of the lines where they are calculated:
Re = (Pa*Vt_guess*Dp)/Mu % no semicolon now, which displays the value to the Command Window
Cd = (24/Re) + ((2.6*(Re/5.0)) / (1 + (Re/5.0)^1.52)) + ((0.411*(Re/(2.63*10^5))^-7.94) / (1+(Re/(2.63*10^5))^-8)) + ((0.25*(Re/10^6)) / (1+(Re/10^6)))

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!