Project 18: Average Rate of Change

Intro Problem:  Suppose a truck drives 400 miles in 6 hours.  We know that on average the truck traveled 400/6 = 66.67 miles per hour.  This does not mean the truck traveled this speed the entire trip, but it is the average rate of change.  It is also true that at some point in the trip, the truck must have been going exactly 66.67 miles per hour (this is actually a Calculus topic).


Similarly, we can calculate the average rate of change for a function along a particular interval.  Some examples are shown below:

To calculate the average rate of change from x = 1 to x = 3 for the function shown above, we would need to calculate the slope of the secant line that passes through the function at x = 1 and x = 3.

The secant line passes through the points (1,0) and (3,4).  The y-coordinates are seen on the graph but can be computed by substituting x = 1 and x = 3 into the polynomial equation.

Therefore, the average rate of change for the equation shown above from x = 1 to x = 2 is 2.

Project 18:  Variables 'co', 'lowX', 'highX' have been initialized.  There is also a working method called getYPoly

co represents the coefficients of the polynomial in ascending (least to greatest) (the values for co would be [4, -3, -2,1] for the example above)

highX and lowX represent the interval in which we are calculating the average rate of change on (lowX is 1 and highX is 3 in the example above)

getYPoly(array, x) is a method that accepts an array of coefficients (representing the coefficients of a polynomial) and an x-value.  The method returns the y-value for the polynomial at the given x.

example 1: co = {30, -11, -4, 1}.  getYPoly(co, 2.0) returns 0.0

example 2: co = {30, -11, -4, 1}.  getYPoly(co, 0.0) returns -2.0

Task: Appropriately initialize the value of 'avgROC' that represents the average rate of change for the polynomial on the given interval.

**If your code works for 5 test cases in a row, you can enter your e-mail address.

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0