In the previous exercise we managed to effectively perform the integration of the velocity function in the while loop structure to obtain the cumulative height attained by the shuttle booster rockets. Unfortunately we find that the accuracy of our results depends upon the number of points chosen to evaluate. Consider the following extracts from two typical executions of program shutloop, in which we evaluate the height attained after an elapsed time of 120 seconds after lift-off:
Evaluate upward velocity as function of elapsed time
for 20,000kg payload, initial total mass is 2,034,681[kg]
enter your initial total mass of shuttle [kg]:
2034681
value entered is 2034681.0[kg]
Shuttle initialised as follows:
total mass at liftoff: 2034681.0[kg]
mass of solid fuel at liftoff: 1004250.0[kg]
booster ejection fuel velocity: 2817.0[m/s],
mass flow rate: 8369.0[kg/s]
orbiter ejection fuel velocity: 3636.0[m/s],
mass flow rate: 1378.0[kg/s]
initial gravity acceleration: 9.8[m/s^2]
enter elapsed time from liftoff [s]: 120
value entered is 120.0 seconds
enter the number of points to evaluate
2
number of points is 2
elapsed time(s) velocity(m/s) height(m)
0.0 0.0 0.0
120.0 1047.9 62875.9
|
|
|
|
enter elapsed time from liftoff [s]: 120
value entered is 120.0 seconds
enter the number of points to evaluate
21
number of points is 21
elapsed time(s) velocity(m/s) height(m)
0.0 0.0 0.0
6.0 26.4 79.1
12.0 54.6 321.9
18.0 84.8 739.9
|
|
|
108.0 871.7 38213.6
114.0 956.8 43699.0
120.0 1047.9 49713.1
|
Which is the correct value of height at an elapsed time of 120 s? Is it 62875.9 m? 49713.1 m? Either of them? Clearly we need to evaluate the height independently of the number of points chosen to evaluate.
In this exercise you should extend
the class Shuttle of the previous
two exercises to include a new method find_height
as indicated in the following structure diagram:

Thus the purpose of method find_height is to integrate the velocity function by means of the Trapezoidal method in order to evaluate the height attained by the booster rockets after an elapsed time etime, as indicated in the following diagram:

In order to develop the function you will need to decide on
the number of integration intervals 'n'.
At this stage we have no theoretical means of relating the required
accuracy and the number of intervals. One practical means is to
choose a value for n (say 2) and note
the resulting value of height. Double this value and repeat the
process, then keep doubling n until
the change in the height is within a specified error bound. It
is convenient to use the previous program exercise shutloop
for this purpose.
Notice that once we have chosen a value for n then the summation
loop sums the n trapezoidal areas. In our previous exercise we
used the while loop structure to do the summation, however
in situations in which we know exactly how many times to execute
the loop, the for loop structure is clearer to read. In
this exercise the for loop structure should be used.
Finally, professional C++ programs are always separated into at
least two files: the program file (often referred to as
the dot-cpp file) and the header file (or dot-h file).
In this exercise you will be required to separate your program
into a program file shutfor.cpp
and a header file shutfor.h.
A direct example is available on condor
in the /home/condor/et181/chapter4
directory and can been used as a paradigm for thus exercise. Recall
the program gfun.cpp to evaluate
the local value of acceleration due to gravity. This program has
been rewritten in terms of gfun1.cpp
and gfun1.h and can also be
found in the chapter4 directory.
Extracts of typical execution output for the new program shutfor follow:
Evaluate upward velocity as function of elapsed time
for 20,000kg payload, initial total mass is 2,034,681[kg]
enter your initial total mass of shuttle [kg]:
2034681
value entered is 2034681.0[kg]
Shuttle initialised as follows:
total mass at liftoff: 2034681.0[kg]
mass of solid fuel at liftoff: 1004250.0[kg]
booster ejection fuel velocity: 2817.0[m/s],
mass flow rate: 8369.0[kg/s]
orbiter ejection fuel velocity: 3636.0[m/s],
mass flow rate: 1378.0[kg/s]
initial gravity acceleration: 9.8[m/s^2]
enter elapsed time from liftoff [s]: 120
value entered is 120.0 seconds
enter the number of points to evaluate
2
number of points is 2
elapsed time(s) velocity(m/s) height(m)
0.0 0.0 0.0
120.0 1047.9 49680.2
|
|
|
|
enter elapsed time from liftoff [s]: 120
value entered is 120.0 seconds
enter the number of points to evaluate
21
number of points is 21
elapsed time(s) velocity(m/s) height(m)
0.0 0.0 0.0
6.0 26.4 78.3
12.0 54.7 320.5
18.0 84.9 738.1
|
|
|
108.0 872.5 38227.0
114.0 957.6 43714.3
120.0 1047.9 49680.2
|
Notice that the height evaluated at an elapsed time of 120 seconds is independent of the number of points to evaluate. Apart from that there is no discernable difference in the output.
Both the program file shutfor.cpp and the header file shutfor.h should be located in your home directory by 10:00 a.m. of the due date.