필터 지우기
필터 지우기

While loop setting error calculation is not calculating properly.

조회 수: 1 (최근 30일)
Shawn Alcorn
Shawn Alcorn 2022년 8월 31일
이동: Voss 2022년 8월 31일
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
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}')
Shawn Alcorn
Shawn Alcorn 2022년 8월 31일
M1 changes with each iteration of the for loop. It doesnt need to be reset. It only changes when the for loop starts over.

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2022년 8월 31일
이동: Voss 2022년 8월 31일
betaIter_deg (and thus betaIter) need to be reset because they are incremented in the while-loop.
  댓글 수: 1
Shawn Alcorn
Shawn Alcorn 2022년 8월 31일
이동: Voss 2022년 8월 31일
that was it thank you. I had that reset earlier and must have accidentally removed it during debugging.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by