what to do when array indicies exceed for , FOR loop comparision for below , trying to plot density of atmosphere, how to do the comparison ?

h(1) = 0;
T(1) = 273.15;
p(1) = 101.2;
for t = 1:328084
if h(t)<[11000]
T(t+1) = 15.04 - 0.00649.*h(t);
p(t+1) = 101.29 .*((T(t) + 273.15) /288.08).^5.256;
elseif [11000]> h(t) && h(t)<=[25000]
T(t) = -56.46;
p(t+1) = 22.65.*e^(1.73-0.000157.*h(t));
elseif h(t)>[25000]
T(t) = -131.21+0.00299.*h(t);
p(t+1) = 2.488 .* ((T(t) + 273.15)/216.6).^-11.388;
end
rho_h(t) = p(t) ./(0.2869 * (T(t) + 273.15))
end
figure(1)
plot(T,h)
grid on
legend on
figure(2)
plot(rho_h, h)
grid on
legend on

 Akzeptierte Antwort

h(1) = 0;
That is the only place you assign to h
if h(t)<[11000]
but you need h to be 328084 elements by the end of the loop.

8 Kommentare

What values do you assign to the remaining elements of h ?
nothing I am varying h from 0 to 300000 ft , its height in feet, with the height I am calculating the density and temperature and pressure
h = linspace(0, 300000, 328084);
??
Or
h = 1 : 328084;
??
N = 328084;
h = 0:N-1;
T(1) = 273.15;
p(1) = 101.2;
for t = 1:N-1
if h(t) <= 11000
T(t+1) = 15.04 - 0.00649.*h(t);
p(t+1) = 101.29 .*((T(t+1) + 273.15) /288.08).^5.256;
elseif 11000 < h(t) && h(t) <= 25000
T(t+1) = -56.46;
p(t+1) = 22.65.*exp(1.73-0.000157.*h(t));
else
T(t+1) = -131.21+0.00299.*h(t);
p(t+1) = 2.488 .* ((T(t+1) + 273.15)/216.6).^-11.388;
end
rho_h(t+1) = p(t+1) ./(0.2869 * (T(t+1) + 273.15));
end
figure(1)
whos
Name Size Bytes Class Attributes N 1x1 8 double T 1x328084 2624672 double h 1x328084 2624672 double p 1x328084 2624672 double rho_h 1x328084 2624672 double t 1x1 8 double
plot(T,h)
grid on
legend on
figure(2)
plot(rho_h, h)
grid on
legend on
SL
SL am 25 Sep. 2021
Bearbeitet: SL am 25 Sep. 2021
perfect thank you very much highly appreciate it
please recheck rho_h(1) which is not assigned a value.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by