function plot_air_density // // Plot the density of the Earth's atmosphere (in kg/m^3) as a function // of altitude (in meters), from sea level to a great height. // // Orient the plot so that altitude runs up the y-axis, which makes // sense for this particular sort of graph. // // // MWR 4/23/2003 // limits of altitude (m) start_altitude = 0; end_altitude = 50000; // density of air at sea level (kg/m^3) rho_nought = 1.21; // scale height of the Earth's atmosphere (in meters) scale_height = 8000; // Walk through the range of altitude, calculating the density at // each point. Fill two arrays with data so we can // later make a nice graph. delta_altitude = 100; num_pieces = (end_altitude - start_altitude)/delta_altitude; for i = 1 : num_pieces altitude = start_altitude + i*delta_altitude; density = rho_nought * exp(-altitude/scale_height); y(i) = altitude; x(i) = density; end // now create the graph clf; plot(x, y, 'b+'); xlabel('Density of air (kg/m^3)'); ylabel('Height above sea level (m)'); // end of function "plot_air_density" endfunction