Output argument "T" (and maybe others) not assigned during call to "StdAtm".
1 view (last 30 days)
Show older comments
The first loop works and I don't know why T, rho, and P are not defined when I call the volume_function(4, 0.5).
function [t, h, V] = volume_function(m, dt)
h = 0;
hmax = 51000;
w = 0;
t = 0;
[T, ~, P] = StdAtm(h);
volume = [];
Vmax = 5000;
V = (m.*4124.*T)./(P);
volume = [volume, V];
time = [];
height = [];
height = [height, h];
while h <= hmax || V < Vmax
[T, rho, P] = StdAtm(h);
V = (m.*4124.*T)./(P);
R = (((3./4).*V)./(pi)).^(1./3);
volume = [volume, V];
mu = 0.000017890.*((T/288.15).^(1.5)).*((288.15+110.4)./(T+110.4));
Re = (rho.*w.*(2.*R))./(mu);
Cd = ((24)./(1+Re))+((6)./(1+sqrt(Re)))+0.1;
D = 0.5.*rho.*(w.^2).*pi.*(R.^2).*Cd;
W = (m+40).*9.81;
rho_H = (P)./(4124.*T);
B = (4./3).*pi*(R.^3)*(rho-rho_H).*9.81;
Fnet = B - D - W;
a = Fnet./(m+40);
w = w + a.*dt;
h = h + w.*dt;
height = [height, h];
t = t + dt;
time = [time, t];
end
end
function [T, rho, P] = StdAtm(h)
if h >= 0 && h < 11000
lapse = -0.0065;
T0 = 288.15;
P0 = 101325;
h0 = 0;
T = T0 + (lapse.*h);
if lapse ~= 0
P = P0 .* ((T0)/(T0 + lapse.*(h - h0))).^((9.81.* 0.02896)./(8.314.*lapse));
else
P = P0 .* exp((-9.81.* 0.02896.*(h-h0))./(8.314.*T0));
end
rho = P0./(8.314.*T0);
elseif h >= 11000 && h < 20000
lapse = 0;
T0 = 216.65;
P0 = 22632.1;
h0 = 11000;
T = T0 + (lapse.*h);
if lapse ~= 0
P = P0 .* ((T0)/(T0 + lapse.*(h - h0))).^((9.81.* 0.02896)./(8.314.*lapse));
else
P = P0 .* exp((-9.81.* 0.02896.*(h-h0))./(8.314.*T0));
end
rho = P0./(8.314.*T0);
elseif h >= 20000 && h < 32000
lapse = 0.001;
T0 = 216.65;
P0 = 5474.89;
h0 = 20000;
T = T0 + (lapse.*h);
if lapse ~= 0
P = P0 .* ((T0)/(T0 + lapse.*(h - h0))).^((9.81.* 0.02896)./(8.314.*lapse));
else
P = P0 .* exp((-9.81.* 0.02896.*(h-h0))./(8.314.*T0));
end
rho = P0./(8.314.*T0);
elseif h >= 32000 && h < 47000
lapse = 0.0028;
T0 = 228.65;
P0 = 868.019;
h0 = 32000;
T = T0 + (lapse.*h);
if lapse ~= 0
P = P0 .* ((T0)/(T0 + lapse.*(h - h0))).^((9.81.* 0.02896)./(8.314.*lapse));
else
P = P0 .* exp((-9.81.* 0.02896.*(h-h0))./(8.314.*T0));
end
rho = P0./(8.314.*T0);
elseif h >= 47000 && h <= 51000
lapse = 0;
T0 = 270.65;
P0 = 110.906;
h0 = 47000;
T = T0 + (lapse.*h);
if lapse ~= 0
P = P0 .* ((T0)/(T0 + lapse.*(h - h0))).^((9.81.* 0.02896)./(8.314.*lapse));
else
P = P0 .* exp((-9.81.* 0.02896.*(h-h0))./(8.314.*T0));
end
rho = P0./(8.314.*T0);
end
end
0 Comments
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!