In the previous exercise you used the 'brute force' method to obtain enough (velocity, power) coordinate pairs for a suitable plot of the power curve. Thus each time you executed the program you obtained a single coordinate pair. Furthermore you had to painstakingly plot the power curve by hand, so as to determine both the steady-state coast-down velocity (no applied power) as well as the steady-state velocity reached when you applied a certain power to the pedals. This was a time consuming task however you probably derived a great feeling of satisfaction in completing it.
In this exercise you will extend your program by adding a new function find_root which will allow you to evaluate the steady-state coast-down velocity without having to plot the power curve. In a forthcoming exercise we will further extend the program to include evaluating the steady-state velocity when a specific amount of power is applied to the pedals.
Consider the steady-state power equation which we derived in the previous exercise:
Thus we wish to determine the value of velocity V which will make P(V) = 0. In other words we would like to determine the root of the power equation P(V). 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 and add a new function find_root to the HPvehicle class. One approach to developing this program is to first copy your hpv.cpp program to a new file hpvroot.cpp, and then modify hpvroot.cpp using either the vi (or nano/pico) editor as follows:
cp hpv.cpp hpvroot.cpp vi hpvroot.cpp
The structure diagram of the modified program follows:
Notice that no modification should be done to the original functions. Notice that function find_power is not invoked directly by the main function, but only indirectly through function find_root. Recall that you are not attempting to determine a value of power, but the coast-down velocity when the power is zero.
A typical program execution output follows:
evaluate coastdown velocity as a function of wind and slope hpv initialised as follows: mass (hpv + rider): 92[kg] cda (coeff.drag*area): 0.4[sq.m] cr (coeff.rolling resist): 0.005 local conditions initialised as follws: gravity acceleration: 9.807[m/s/s] air density: 1.18[kg/cu.m] wind velocity: 0[mph] slope: 0 ----------------------------------------------------- enter wind velocity [mph] - positive for headwind -1 value entered is -1[mph] enter slope (height/distance) - positive for uphill -0.02 value entered is -0.02 new local conditions: wind velocity = -1[mph] slope = -0.02 enter low and high velocity bounds [mph] 1 25 values entered are [1,25] [mph] enter required accuracy in coastdown velocity [mph] 0.1 required accuracy is 0.1[mph] coastdown velocity is 18.016[mph]
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.
The source code file hpvroot.cpp should be in your home directory by 10:00 a.m. of the due date.