Hot Air Balloons - 2 (Program: "balroot")

In the previous exercise, each time you executed the program you entered a value for altitude, and the program evaluated the payload that could be lifted to that altitude. The more adventurous among you may have read Edgar Allen Poe's classic short stories, including "The Unparalleled Adventure of One Hans Pfaall" (~1835), describing how a Dutch adventurer ballooned to the moon (about 200,000km). Just for fun, grab some oxygen and try to see what would happen if you entered an altitude of say 2e8m on the keyboard. You may be intrigued by the response - what in the atmosphere does it mean? Essentially you are attempting to use the equations beyond their specified domain of usage (0 to 11,000m). I shudder at the thought of what would happen if you attempted an altitude of -6,380,000m, which would bring you directly to the center of the earth! (Note: to enter this value type: -6.38e6). In this exercise you will modify your payload function find_payload by trapping the condition of an out-of-range altitude, and returning a value of zero in this case.

Consider again the sequence of equations that we used to evaluate the payload lifted to a certain altitude:


Notice that the independent variable is the altitude (z), thus given the value of altitude we can determine the amount of payload that can be lifted to that altitude. However the problem is normally posed in the reverse order. We normally know what the payload is and would like to know to what altitude we can lift this specific payload. Unfortunately the equations given above cannot be easily solved in the reverse order.

The approach that you used in the previous exercise was the 'brute force' approach: obtain enough (altitude, payload) coordinate pairs for a suitable plot of the payload curve. Thus each time you executed the program you obtained a single coordinate pair. Furthermore you had to painstakingly plot the payload curve by hand, so as to determine the altitude reached for a certain specific payload mass. This was a time consuming task however you probably derived a great feeling of satisfaction in completing it.

In this exercise you will use a "root-finding" method to extend your previous program, which will allow you to evaluate the altitude reached for a certain specific payload mass without having to plot the payload curve. This will be done by adding two new methods to our Balloon class: find_altitude and dif_payload. Essentially we would like to find the value of altitude that will make the value returned by method find_payload equal to the required payload.

Consider the method dif_payload, which is defined as follows:

 float dif_payload(float altitude, float req_payload){
    // returns difference in payload - the root of dif_payload
    // is the altitude which balloon can attain with req_payload
    return (find_payload(altitude) - req_payload);
}

Thus the value of altitude that makes the value returned by find_payload equal to the required payload req_payload is the same value of altitude that makes dif_payload equal zero. In other words we would like to determine the root of the function dif_payload. In lab5 you will develop a function sin_root to evaluate the root of the function sin(x) using the Bisection method. This is a very similar problem, hence you will be able to apply the function that you develop in lab5 directly to this exercise.

This exercise is an extension of the previous exercise in that you will need to modify the main function module, the method find_payload, and add two new methods to the Balloon class: find_altitude and dif_payload. One approach to developing this program is to first copy your balloon.cpp program to a new file balroot.cpp, and then modify balroot.cpp using the vi (or nano) editor as follows:

cp balloon.cpp balroot.cpp
vi balroot.cpp

The structure diagram of the modified program follows:

Notice that function find_payload is not invoked directly by the main function, but only indirectly through function find_altitude. Recall that you are not attempting to determine a value of payload, but the altitude reached for a specific required payload.

A typical program execution output follows:

enter balloon volume (typically 1000 cu.m):
1000
enter balloon empty mass (typ. 100)[kg]
100
balloon initialised as follows:
balloon volume: 1000[cu.m]
balloon empty mass: 100[kg]
standard atmospheric conditions:
temperature lapse rate: -0.0065[deg C/m]
temperature at sea level: 15[deg C]
standard pressure at sea level: 101325[Pa]
find altitude as a function of required payload
enter the required payload [kg]:
150
required payload entered is 150.0[kg]
enter low and high bounds of altitude [m]:
0 13000
altitude bounds are [0.0,13000.0][m]
enter required accuracy in altitude [m]
1
required accuracy is 1.0[m]
WARNING! Altitude 13000.0[m] out of range
for a required payload of 150.0[kg]
altitude attained is 3451.1[m]

Notice the various items of data entry to this program are written in Italics script. In order to enable this program to be graded automatically, this sequence of data entry should be strictly adhered to. Notice also that we have given an upper altitude value of 13,000 m, which is above the allowable upper altitude limit of 11,000 m. The warning message is displayed when the method find_payload is invoked with this out-of-range altitude argument.

The source code file balroot.cpp should be in your home directory by 10:00am of the due date.