Is there a way I could assign my variable to a bunch of equations with its value generated on its own ?

1 vue (au cours des 30 derniers jours)
Hi there everybody, Im currently doing on my coding right now and encountered on this problem. I would like my variable M2 to generate its own value in which the value satisfies to a bunch of equations that would lead the final equation DeltaP = Patm - P7 = 0. However i wasnt able to achieve such task and would like help on this matter.
R = 287;
T1 = 339;
kc = 1.4;
kc0 = 0.2;
kc1 = 2.498;
kc2 = 3.498;
ktp_volute = 0.9
r1 = 1;
rrms2 = 2;
SW = 0.95;
M1 = rand(1);
for i= 1:length(M1)
%% Ctheta Exit Volute
C1 = M1*(kc*R*T1)^0.5; %absolute velocity inlet
Ctheta_exitvolute = C1*SW*(r1 / rrms2 );
%% Ctheta Inlet Rotor
T02 = 339;
T2 = 332.193;
alpha2 = 70.423;
Rad = deg2rad(alpha2);
%M2 = (M1 * T1^0.5 * SW * r1/rrms2) / T2*0.5 * sin(Rad);
M2 = rand(1);
C2 = M2.*(kc*R*T2).^0.5; %absolute velocity inlet volute
Ctheta2_inletrotor = C2.*sin(Rad);
Delta_Ctheta = Ctheta_exitvolute - Ctheta2_inletrotor;
iter = 0;
maxIter = 0;
%% Delta_Ctheta
while Delta_Ctheta < 0 && iter > maxIter
iter = iter + 1;
Ctheta_exitvolute = C1*SW*(r1 / rrms2 );
Ctheta2_inletrotor = C2.*sin(Rad);
Delta_Ctheta = Ctheta_exitvolute - Ctheta2_inletrotor;
end
if iter == maxIter
warning('Max Iterations reached')
end
end
M6 = rand (1);
M7 = rand(1);
Ktp1 = 1.6775e-12 ;
M2_rel = 0.288;
P01 = 124638.717;
P2 = P01./(((1 + kc0 * M2.^2).^kc2).*(1+ktp_volute)-ktp_volute)
P02_rel = P2.*(1 + kc0 * M2_rel.^2).^kc2;
W2 = 79.468;
W6 = 61.967;
Kpass6 = 0.1;
Kinc1 = 0.522;
Kpass2 = 0.060;
U2 = 207.88944;
U6 = 136.4506;
W6_ideal = sqrt(((W6.^2).* (1+Kpass6)) + ((Kpass2 + Kinc1).* (W2.^2)));
T02_rel = T2.*(1 + kc0 * M2_rel.^2);
T06_rel = T02_rel - kc0./(kc*R) * (U2.^2 - U6.^2);
P06_idrel = P02_rel.* (T06_rel/T02_rel).^kc2;
Wcr2 = sqrt((2 * kc * R * T02_rel)./(kc+1))
Wcr6 = Wcr2.* sqrt(T06_rel/T02_rel)
P6 = (1 - ((W6_ideal./Wcr6).^2).* ((kc-1)./(kc+1))).^(1/kc2).* P06_idrel;
P06 = P6.*((1 + kc0 * M6.^2).^kc2);
for i = 1:length(M7);
P7 = P06 / (((1 + kc0 * M7^2)^kc2) * (1 + Ktp1) - Ktp1)
Patm = 101325;
DeltaP = Patm - P7;
while DeltaP < 0 && iter > maxIter
iter = iter + 1;
P7 = P06 / (((1 + kc0 * M7^2)^kc2) * (1 + Ktp1) - Ktp1);
Delta_P = Patm - P7;
end
if iter == maxIter
warning('Max Iterations reached')
end
end
  3 commentaires
Danish Iqhwan Rohaizad
Danish Iqhwan Rohaizad le 10 Avr 2022
Thank you Stephen for your response. I have edited my coding as per below and would like to ask if its possible for M2 to achieve by using if statement in which the loop would continue on looping until the value M2 obtained ultimately leads Delta_Ctheta2(i) = Ctheta2_exitvolute - NewCtheta2_inletrotor to achieving a value of 0
%% Calculation
%Station 1
R = 287; %Gas constant
T01= 339; %Stagnation Temperature or total inlet temperature
Patm = 101325;
P01 = 124638.717;
A1 = 0.0025686; %Area inlet volute
kc = 1.4; %specific heat ratio
kc0 = 0.2; %specific heat ratio at total state
kc1 = 2.498; %specific heat ratio at inlet volute
kc2 = 3.498; %specific heat ratio at inlet rotor
%Mach Number 1 (Guess)
%M1 =input('What are your M1 value:');% enter the vector M1
M1 = rand(1)
for iter_1 = 1:length(M1)
rho01 = P01./(R*T01); %Stagnation density
rho1 = rho01./(1 + kc0 * M1.^2).^kc1; %flow density inlet volute
T1 = T01./(1 + kc0 * M1.^2); %static temperature inlet volute
P1 = P01./(1 + kc0 *M1.^2).^kc2; %static pressure inlet volute
C1 = M1.*(kc*R*T1).^0.5; %absolute velocity inlet
mdot1 = rho1.*A1.*C1; %mass flow rate inlet volute
end
%% Station 2
%M2 = input('What are your M2 values:');% enter the vector M2
M2 = rand(1)
T02 = 339; %Stagnation temperature or total temperature at rotor inlet
N = 47503; %Rotor speed
omega = (2*pi/60)*N; %Rotor 100% speed angular velocity
ktp_volute= 0.9; %Coeeficient Total Pressure Loss Volute
SW = 0.95; % Swirl Coefficient
B2 = 1; %Inlet rotor blockage factor
r1 = 0.0739; %Inlet volute radius
r2max = 0.047576; %Rotor shroud tip radius at leading edge
r2min = 0.036006; %Rotor hub radius at leading edge
rrms2 = (r2max + r2min)/2; %Average between r2max and r2min
U2 = rrms2 * omega; %Blade speed rotor tip
for iter_2 = 1:length(M2)
Ctheta2_exitvolute = C1.*SW.*(r1 / rrms2 ); %Tangential absolute velocity inlet rotor
P2 = P01./(((1 + kc0 * M2(iter_2).^2).^kc2).*(1+ktp_volute)-ktp_volute); %Static pressure inlet rotor
T2 = T02./(1 + kc0 * M2(iter_2).^2); %static temperature inlet rotor
P02 = P2.*(1 + kc0 * M2(iter_2).^2).^kc2; %Total pressure inlet rotor
rho2 = P2./(R*T2); %Stagnation density
% using continuity equation, mass flow rate inlet rotor = mass flow rate inlet volute
% mdot1 = mdot2
mdot2 = mdot1; %mass flow inlet rotor
leh = 0.018; %rotor leading height
A2 = pi * (r2max +r2min) * leh;%Area Inlet Rotor
%Absolute velocity inlet rotor
alpha2 = (atand((rho2./rho1).*((A2/rrms2)./( A1/r1)).*SW));
Rad = deg2rad(alpha2);
C2 = M2(iter_2).*(kc*R*T2).^0.5; %absolute velocity inlet volute
Ctheta2_inletrotor = C2*sin(Rad);
if Ctheta2_inletrotor < Ctheta2_exitvolute
New_M2 = rand(1);
elseif Ctheta2_inletrotor > Ctheta2_exitvolute
New_M2 = rand(1);
else Ctheta2_inletrotor == Ctheta2_exitvolute
end
New_C2 = New_M2.*(kc*R*T2).^0.5;
NewCtheta2_inletrotor = New_C2*sin(Rad);
Delta_Ctheta2(i) = Ctheta2_exitvolute - NewCtheta2_inletrotor;
end
However, everytime i run this coding I am not able to achieve the value 0 as I intended.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by