How can I assign multiple inputs into variables
1 view (last 30 days)
Show older comments
Greetings everybody
Currently my coding is used to find the value of certain variables (temperature, pressure, density etc). Please be noted that for each of these variables have a set of datas in a column manner. Ultimately, all of the variables are dependent on the value M1 and the values of M1 are [0.178 0.185 0.192 0.199 0.205 0.218 0.224 0.242 0.242 0.258 0.278 0.306 0.310 0.346 0.381 0.420 0.433 0.440 0.452 0.459 0.470 0.480 0.489 0.497 0.501 0.501 0.500 0.500 0.500 0.499 0.495]
My problem with the coding is that I am unable to figure out on how to assign these values of input into my variables. My coding are as below:
%% Calculation
%Station 1
R = 287; %Gas constant
T01= 339; %Stagnation Temperature or total inlet temperature
Patm = 101325;
P01 = [124638.717 126432.080 128225.442 130018.805 131812.168 135398.894 137192.256637168 142572.345132743 142572.345132743 147952.433628319 155125.884955752 165886.061946903 167679.424778761 183819.690265487 201753.318584071 225067.035398230 234033.849557522 239413.938053097 248380.752212389 253760.840707965 263445 273577.500000000 283710 293842.500000000 303975 309041.250000000 310054.500000000 310561.125000000 311067.750000000 311574.375000000 314107.500000000];
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:');
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
0 Comments
Answers (2)
VBBV
on 18 Mar 2022
%% Calculation
%Station 1
R = 287; %Gas constant
T01= 339; %Stagnation Temperature or total inlet temperature
Patm = 101325;
P01 = [124638.717 126432.080 128225.442 130018.805 131812.168 135398.894 137192.256637168 142572.345132743 142572.345132743 147952.433628319 155125.884955752 165886.061946903 167679.424778761 183819.690265487 201753.318584071 225067.035398230 234033.849557522 239413.938053097 248380.752212389 253760.840707965 263445 273577.500000000 283710 293842.500000000 303975 309041.250000000 310054.500000000 310561.125000000 311067.750000000 311574.375000000 314107.500000000];
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 =[0.178 0.185 0.192 0.199 0.205 0.218 0.224 0.242 0.242 0.258 0.278 0.306 0.310 0.346 0.381 0.420 0.433 0.440 0.452 0.459 0.470 0.480 0.489 0.497 0.501 0.501 0.500 0.500 0.500 0.499 0.495]; %input('What are your M1 value:');
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
plot(M1,mdot1)
2 Comments
VBBV
on 18 Mar 2022
Ok, Then you need to include additional condition involving M1 ( mach) and other variabales after taking M1 as input guesses to evaluate mdot1
M.B
on 18 Mar 2022
Edited: M.B
on 18 Mar 2022
There are dimension issues with the code.
When prompted to enter the value of M1, do you enter a single value of a vector?
E.g. M1 = 0.178 or M1 = [0.178 0.185 0.192 0.199 0.205 ...]
The code below is not elgant nor it is robust, but you should end up having vectors for T1 P1 and C1.
%% Calculation
%Station 1
R = 287; %Gas constant
T01= 339; %Stagnation Temperature or total inlet temperature
Patm = 101325;
P01 = [124638.717 126432.080 128225.442 130018.805 131812.168 135398.894 137192.256637168 142572.345132743 142572.345132743 147952.433628319 155125.884955752 165886.061946903 167679.424778761 183819.690265487 201753.318584071 225067.035398230 234033.849557522 239413.938053097 248380.752212389 253760.840707965 263445 273577.500000000 283710 293842.500000000 303975 309041.250000000 310054.500000000 310561.125000000 311067.750000000 311574.375000000 314107.500000000];
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 = [0.178 0.185 0.192 0.199 0.205 0.218 0.224 0.242 0.242 0.258 0.278 0.306 0.310 0.346 0.381 0.420 0.433 0.440 0.452 0.459 0.470 0.480 0.489 0.497 0.501 0.501 0.500 0.500 0.500 0.499 0.495];
for iter = 1:length(M1)
rho01 = P01(iter)/(R*T01); %Stagnation density
rho1 = rho01/(1 + kc0 * M1(iter)^2)^kc1; %flow density inlet volute
T1(iter) = T01/(1 + kc0 * M1(iter)^2); %static temperature inlet volute
P1(iter) = P01(iter)/(1 + kc0 *M1(iter)^2)^kc2; %static pressure inlet volute
C1(iter) = M1(iter)*(kc*R*T1(iter))^0.5; %absolute velocity inlet
mdot1 = rho1*A1*C1; %mass flow rate inlet volute
end
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!