While loop setting error calculation is not calculating properly.
1 回表示 (過去 30 日間)
古いコメントを表示
While loop within code is suppose to adjust betaIter until thetaTanIter is within a certain value of tangent of 10 degrees. The results I am getting are the exact opposite of what the actual results are suppose to be. The first value of beta is correct but the proceeds in the wrong direction. Beta in degrees should go from 39 degrees to about 12 degrees. Once the beta issue is fixed then all other problems should be corrected as well.
close all
clear all
clc
% Known Static Variables
gamma = 1.4;
theta = 10; %Degrees
theta_Rads = theta*(pi/180);% Radians
P1 = 1; % ATM
T1 = 298.15; % K
i = 1;
betaIter_deg = 2;
betaIter = betaIter_deg*(pi/180); % Initial guess
thetaTan = tan(theta_Rads);
for M1 = 2:1:50
M1_save(i) = M1;
thetaTanIter = 2*cot(betaIter)*(((M1^2)*(sin(betaIter)^2)-1)/(((M1^2)*(gamma+cos(2*betaIter)))+2));
while abs(thetaTan - thetaTanIter) > .00001
betaIter_deg = betaIter_deg + .0001;
betaIter = betaIter_deg *(pi/180);
thetaTanIter = 2*cot(betaIter)*(((M1^2)*(sin(betaIter)^2)-1)/(((M1^2)*(gamma+cos(2*betaIter)))+2));
end
beta = betaIter_deg;
beta_save(i) = beta;
betaRads = beta*(pi/180);
M2(i) = (1/sin(betaRads-theta_Rads))*sqrt((1+((gamma-1)/2)*(M1^2)*(sin(betaRads)^2))/((gamma*(M1^2)*(sin(betaRads)^2))-((gamma-1)/2)));
P2P1(i) = ((2*gamma)/(gamma+1))*((M1^2)*(sin(betaRads)^2)-1);
rho2rho1(i) = ((gamma+1)*(M1^2)*(sin(betaRads)^2))/((gamma-1)*(M1^2)*(sin(betaRads)^2)+2);
T2T1(i) = P2P1/rho2rho1;
betaTheta(i) = beta_save(i)/theta;
i = i+1;
end
plot(M1_save,M2)
xlabel('Upstream Mach Number (M_1)')
ylabel('Downstream Mach Numer (M_2)')
title('M_{1} vs M_{2} - \theta = 10^{\circ}')
figure
plot(M1_save,P2P1)
xlabel('Upstream Mach Number (M_1)')
ylabel('{P2}/{P1}')
title('M_1 vs {P2}/{P1}')
figure
plot(M1_save,T2T1)
xlabel('Upstream Mach Number (M_1)')
ylabel('{T2}/{T1}')
title('M_1 vs {T2}/{T1}')
figure
plot(M1_save,beta_save)
xlabel('Upstream Mach Number (M_1)')
ylabel('\beta (Deg)')
title('M_1 vs \beta')
figure
plot(M1_save,betaTheta)
xlabel('Upstream Mach Number (M_1)')
ylabel('{\beta}/{\theta}')
title('M_1 vs {\beta}/{\theta}')
2 件のコメント
Torsten
2022 年 8 月 31 日
編集済み: Torsten
2022 年 8 月 31 日
You forgot to reset the values for a new M1:
% Known Static Variables
gamma = 1.4;
P1 = 1; % ATM
T1 = 298.15; % K
i = 1;
theta = 10; %Degrees
theta_Rads = theta*(pi/180);% Radians
thetaTan = tan(theta_Rads);
for M1 = 2:1:50
betaIter_deg = 2;
betaIter = betaIter_deg*(pi/180); % Initial guess
M1_save(i) = M1;
thetaTanIter = 2*cot(betaIter)*(((M1^2)*(sin(betaIter)^2)-1)/(((M1^2)*(gamma+cos(2*betaIter)))+2));
while abs(thetaTan - thetaTanIter) > .00001
betaIter_deg = betaIter_deg + .0001;
betaIter = betaIter_deg *(pi/180);
thetaTanIter = 2*cot(betaIter)*(((M1^2)*(sin(betaIter)^2)-1)/(((M1^2)*(gamma+cos(2*betaIter)))+2));
end
beta = betaIter_deg;
beta_save(i) = beta;
betaRads = beta*(pi/180);
M2(i) = (1/sin(betaRads-theta_Rads))*sqrt((1+((gamma-1)/2)*(M1^2)*(sin(betaRads)^2))/((gamma*(M1^2)*(sin(betaRads)^2))-((gamma-1)/2)));
P2P1(i) = ((2*gamma)/(gamma+1))*((M1^2)*(sin(betaRads)^2)-1);
rho2rho1(i) = ((gamma+1)*(M1^2)*(sin(betaRads)^2))/((gamma-1)*(M1^2)*(sin(betaRads)^2)+2);
T2T1(i) = P2P1/rho2rho1;
betaTheta(i) = beta_save(i)/theta;
i = i+1;
end
plot(M1_save,M2)
xlabel('Upstream Mach Number (M_1)')
ylabel('Downstream Mach Numer (M_2)')
title('M_{1} vs M_{2} - \theta = 10^{\circ}')
figure
plot(M1_save,P2P1)
xlabel('Upstream Mach Number (M_1)')
ylabel('{P2}/{P1}')
title('M_1 vs {P2}/{P1}')
figure
plot(M1_save,T2T1)
xlabel('Upstream Mach Number (M_1)')
ylabel('{T2}/{T1}')
title('M_1 vs {T2}/{T1}')
figure
plot(M1_save,beta_save)
xlabel('Upstream Mach Number (M_1)')
ylabel('\beta (Deg)')
title('M_1 vs \beta')
figure
plot(M1_save,betaTheta)
xlabel('Upstream Mach Number (M_1)')
ylabel('{\beta}/{\theta}')
title('M_1 vs {\beta}/{\theta}')
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!