Borrar filtros
Borrar filtros

While loop setting error calculation is not calculating properly.

1 visualización (últimos 30 días)
Shawn Alcorn
Shawn Alcorn el 31 de Ag. de 2022
Movida: Voss el 31 de Ag. de 2022
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 comentarios
Torsten
Torsten el 31 de Ag. de 2022
Editada: Torsten el 31 de Ag. de 2022
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 el 31 de Ag. de 2022
M1 changes with each iteration of the for loop. It doesnt need to be reset. It only changes when the for loop starts over.

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten el 31 de Ag. de 2022
Movida: Voss el 31 de Ag. de 2022
betaIter_deg (and thus betaIter) need to be reset because they are incremented in the while-loop.
  1 comentario
Shawn Alcorn
Shawn Alcorn el 31 de Ag. de 2022
Movida: Voss el 31 de Ag. de 2022
that was it thank you. I had that reset earlier and must have accidentally removed it during debugging.

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by