How can I assign multiple inputs into variables

1 次查看(过去 30 天)
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

回答(2 个)

VBBV
VBBV 2022-3-18
%% 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
mdot1 = 1×31
0.2121 0.2233 0.2347 0.2462 0.2568 0.2796 0.2906 0.3246 0.3246 0.3575 0.4013 0.4678 0.4784 0.5773 0.6874 0.8301 0.8842 0.9159 0.9701 1.0028 1.0598 1.1179 1.1751 1.2314 1.2812 1.3026 1.3050 1.3071 1.3092 1.3095
plot(M1,mdot1)
  2 个评论
Danish Iqhwan Rohaizad
Yes hi ! Thank you for the quick respond kind sir. If lets say my value of M1 should be obtained through guesses, meaning through trial and error in order to get the other variables (which i do not include in my question above) how do I progress from there ?
VBBV
VBBV 2022-3-18
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
M.B 2022-3-18
编辑:M.B 2022-3-18
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
  1 个评论
Danish Iqhwan Rohaizad
Hi there sir, for your question I would say that the value of M1 is obtained through the means of trial and error or guess and would preferably be entered by the right option. Regarding the vectors for the variables, how do i tweak the coding so that the variables such as rho1 and rho01 appears to that of P1 and C1 in which the variables have values listed in a double manner ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by