Filter löschen
Filter löschen

Hey guys, I have a problem. Im writing a code that models engine thrust over an altitude range. It runs ok when i keep a variable constant, 'gamma', but when its varied, it dosent run. Can someone help?

2 Ansichten (letzte 30 Tage)
clc
clear
z = 0:1:100;
[T,P,rho,del,sig,the]= atmosi_100(z);
%% constants
r_o = 6.371e7; % earth radius, m
g_o = 9.81; % gravity, m/s^2
%T/W = F_req/(m_e*9.81);
D = 100; % Drag, N, from aero
m_i = 12000; % initial wet mass, kg
P_c = 2.233e7; % ambient pressure, Pa
g = 9.81; % gravitational acceleration, m/s^2
R = 287; % gas constatnt, J/kg*K
A_e = 1.1; % exit area, m^2
% From App.B
T_c = 3400; % temp, K
gamma = 1.2:0.05:1.4;
Mol = 13.5; % molecular mass, kg/kmol
v_o = 10; % inicial velocity, m/s
time = 140; % time to seperation, s
%% Inputs
F_req = 1334466; % required thrust, N (from Performance)
%% Engine characteristics/SSME design point
% assuming combustion efficiency of 1.0
ex = 77.5;
P_c = 2.2339e+7; % chamber pressure, Pa
A_t = (ex.^-1).*A_e; % throat area, m^2
epsilon = sqrt(gamma./(((gamma+1)./2).^((gamma+1)./(gamma-1))));
m_dot = P_c.*A_t.*g.*(epsilon./sqrt(R.*g.*T_c));
% assume f and I_sp
f = 6;
I_sp = 363;
% Newton-Raphson method for finding exit mach number
b = 2.*(gamma-1)./(gamma+1);
c = ((gamma+1)./(gamma-1)).*((ex).^(b));
d = 2./(gamma-1);
Me_0 = 7.5;
original = (c .* (Me_0 .^ b)) - (Me_0 .^ 2) - d;
derivative = (b .* c .* (Me_0 .^ (b - 1))) - (2 .* Me_0);
Me_1 = Me_0 - (original ./ derivative);
while abs(original) > 10^-2
Me_0 = Me_1;
original = (c .* (Me_0 .^ b)) - (Me_0 .^ 2) - d;
derivative = (b .* c .* (Me_0 .^ (b - 1))) - (2 .* Me_0);
Me_1 = Me_0 - (original ./ derivative);
fprintf('Iteration: M_e = %.20f, error = %.20f \n', Me_1, original);
end
mf_f = 1-exp(-(sqrt(g_o*r_o))./(I_sp*v_o*((1-D)/F_req))); % fuel mass fraction
mf = mf_f *m_i; % mass of fuel, kg,
P_e = P_c.*(1+((gamma-1)./2).*(Me_1.^2)).^(gamma./(1-gamma)); % exit static pressure, Pa
P_te = P_e./(1+((gamma-1)./(Me_1.^2))).^(-gamma./(gamma-1)); % exit total pressure, Pa
% using isentropic relations
T_e = ((P_e./P_te).*T_c.^(gamma./(gamma-1))).^(1./(gamma./(gamma-1)));
v_e = Me_0.*sqrt(gamma.*R.*T_e);
F_ava = (m_dot.*v_e) + (P_e-P).*(A_t.*ex);
S = (m_dot.*f)./F_ava; % specific fuel consumption, kg/s*N
S_t = (S.*F_ava).*time;
%% engine sizing
D_e = 0.00357.*F_ava+14.48; % engine diameter, m
m_e = F_ava./(g*0.0006098.*F_ava+13.44); % engine mass, kg
L_e = 0.000030*F_ava+327.7; % engine length, m
Lstar = 1; % characteristic length, m
A_c = A_t*(8*((2*sqrt(A_t/pi))^(-0.6)) + 1.25); % average combustion chamber cx area, m^2
L_c = Lstar*(A_t/A_c); % combusiton chamber length, m
V_c = Lstar*A_t; % combustion chamber volume, m^3
d_e = sqrt((4.*ex.*A_t)/pi); % exit diameter, m
%% Plots/outputs
fprintf('m_dot = %f [kg/s] \n',m_dot)
fprintf('v_e = %f [m/s] \n',v_e)
fprintf('V_c = %f [m^3] \n,',V_c)
fprintf('A_c = %f [m^2] \n', A_c)
fprintf('m_e = %f [kg] \n',m_e)
fprintf('L_e = %f [m] \n', L_e)
fprintf('D_e = %f [m]',D_e)
fprintf('L_c = %f [m] \n', L_c)
fprintf('S_t = %f [kg]\n', S_t)
% fprintf('m_f = %f [kg]\n', m_f)
figure(1)
plot(z,F_ava)
title('Avalible thrust vs. Altitude')
xlabel('Altitude (km)')
ylabel('F_ava (N)')
figure(2)
plot(z,S)
title('Specific fuel consimption vs. Altitiude')
xlabel('Altitude (km)')
ylabel('S (kg/s*N)')
%% Trade Studies
% plot(F_ava,gamma) % vary gamma from 1.2-1.4
  11 Kommentare
Ikenna Okoye
Ikenna Okoye am 17 Nov. 2018
What inputs do you mean? As in equations, or do you mean the values already hard coded in? The code runs ok when 'gamma' is kept constant, everything works ok then, so im not sure why when run by itself it dosent work for me.
Walter Roberson
Walter Roberson am 17 Nov. 2018
Bearbeitet: Walter Roberson am 18 Nov. 2018
the code prompts 1 for si and 2 for imperial, and prompts for aa numeric height value . Then it tries to call atmos0_100 which we do not have the code for .

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Ikenna Okoye
Ikenna Okoye am 18 Nov. 2018
Sorry, the script that i first posted should already be atmos0_100, the 'i' should be a '0':
function[T,P,rho,del,sig,the]= atmos0_100(z)
global r R_o
%% Constants
% Sea level conditions
P_o = 101325; % (Pa)
rho_o = 1.225; % (Kg/m^3)
T_o = 288.15; % (K)
mu_o = 1.789*10^-5; % (Kg/m/s)
nu_o = 1.46*10^-5; % (m^2/s)
tc_o = 0.02596; % (W/m/K)
R_o = 287.053; % (J/Kg/K)
g_o = 9.80665; % (m/s^2)
Cp = 1005; % (J/Kg/K)
r_o = 6356.766; % (km)
r = 1.4;
%% Process
for i = 1:length(z)
h(i) = (r_o*z(i))/(r_o+z(i));
if h(i) == 0
P(i) = P_o;
T(i) = T_o;
rho(i) = rho_o;
elseif 0<h(i) && h(i)<=11
P(i) = P_o*(T_o/(T_o-6.5*h(i)))^(34.1632/-6.5);
T(i) = T_o-6.5*h(i);
rho(i) = P(i)/(R_o*T(i));
eps(i) = z(i)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
elseif 11<h(i) && h(i)<=20
T(i) = 216.65;
P(i) = 22632.06*exp(-34.1632*(h(i)-11)/T(i));
rho(i) = P(i)/(R_o*T(i));
eps(i) = (z(i)-11)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
elseif 20<h(i) && h(i)<=32
P(i) = 5474.889*(216.65/(216.65+(h(i)-20)))^34.1632;
T(i) = 196.65+h(i);
rho(i) = P(i)/(R_o*T(i));
eps(i) = (z(i)-20)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
elseif 32<h(i) && h(i)<=47
P(i) = 868.0187*(228.65/(228.65+2*r*(h(i)-32)))^(34.1632/(2*r));
T(i) = 139.05+2*r*h(i);
rho(i) = P(i)/(R_o*T(i));
eps(i) = (z(i)-32)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
elseif 47<h(i) && h(i)<=51
T(i) = 270.65;
P(i) = 110.9063*exp(-34.1632*(h(i)-47)/T(i));
rho(i) = P(i)/(R_o*T(i));
eps(i) = (z(i)-47)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
elseif 51<h(i) && h(i)<=71
P(i) = 66.93884*(270.65/(270.65-2*r*(h(i)-51)))^(34.1632/(-2*r));
T(i) = 413.45-2*r*h(i);
rho(i) = P(i)/(R_o*T(i));
eps(i) = (z(i)-51)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
elseif 71<h(i) && h(i)<=85
P(i) = 3.956420*(214.65/(214.65-2*(h(i)-71)))^(34.1632/-2);
T(i) = 356.65-2*h(i);
rho(i) = P(i)/(R_o*T(i));
eps(i) = (z(i)-71)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
elseif 85<z(i) && z(i)<=91
T(i) = 186.8673;
P(i) = exp(2.159582*10^(-6)*z(i)^3 + -4.836957*10^(-4)*z(i)^2 + -.14251928*z(i) + 13.47530);
rho(i) = exp(-3.322622*10^(-6)*z(i)^3 + 9.111460*10^(-4)*z(i)^2 + -.2609971*z(i) + 5.944694);
eps(i) = (z(i)-85)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
else
T(i) = 263.1905-76.3232*sqrt(1-((z(i)-91)/-19.9429)^2);
P(i) = exp(3.304895*10^-5*z(i)^3 + -.009062730*z(i)^2 + .6516698*z(i) + -11.03037);
rho(i) = exp(2.873405*10^-5*z(i)^3 + -.008492037*z(i)^2 + .6541179*z(i) + -23.6201);
eps(i) = (z(i)-85)*10^3/(R_o*T(i));
del(i) = P(i)/P_o;
sig(i) = rho(i)/rho_o;
the(i) = T(i)/T_o;
end
end
  6 Kommentare
Ikenna Okoye
Ikenna Okoye am 19 Nov. 2018
Bearbeitet: Ikenna Okoye am 19 Nov. 2018
The code i posted, 2 comments up, would be in its own file. Total there are three code files: the one just mentioned, the atmosphere program it calls, atmosi0_100 and the propulsion code that I first posted in my question.
Walter Roberson
Walter Roberson am 19 Nov. 2018
"Total there are three code files: the one just mentioned, the atmosphere program it calls, atmosi0_100 and the propulsion code that I first posted in my question. "
"The one just mentioned" appears to be the script starting from "prompt =".
You seem to be saying that the atmosphere program it calls is the routine named atmosi0_100, which would be consistent for that script.
The propulsion code that you first posted appears to refer to the block of code that starts with
clc
clear
z = 0:1:100;
[T,P,rho,del,sig,the]= atmosi_100(z);
which calls atmosi_100 which is a different function, a fourth function.
Considering that the code posted first starts with "clear" then it would not appear to make sense to call the script first to establish any variables, as any variables would be erase by the clear. This suggests that the script that does the prompt is to be called at some point after the propulsion code, but the relationship between them is not obvious.

Melden Sie sich an, um zu kommentieren.


Ikenna Okoye
Ikenna Okoye am 19 Nov. 2018
Right the propulsion code calls the funciton file, that starts with prompt, that then calls atmos0_100. Does that clarify?

Community Treasure Hunt

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

Start Hunting!

Translated by