Project 16: Local Maximum

Buy Low, Sell High!!


We can estimate the trend of a particular market with a polynomial.  In the polynomial, we would want to know where the lowest and highest points in the graph are located because this would indicate when the market was at its lowest and highest.

Project 16: The following variables 'lowerX', 'upperX', 'co' have been initialized.  There is also a working method called getYPoly.

lowerX is the lowest x-value in our range that we are checking for a maximum in (lower X is 1 in the example above)

upperX is the highest x-value in our range that we are checking for a maximum in (upperX is 4 in the example above)

co is an array of values that represent the polynomial's coefficients in ascending order

example: the polynomial graphed below is y = x^3 -  4x^2 - 11x + 30

The array 'co' would hold values: {30, -11, -4, 1}.

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: Correctly initialize variables 'x' and 'y' that correspond to the point on the graph that has the highest y-value where x is in the range between lowerX and upperX.


In the example above, 'x' would be 2.0 and 'y' would be 0.0 because this is the highest point on the graph between x = 1 and x = 4.

For the Polynomial shown above (coefficients would be: 0,5,-5,1), x would be .6125718 and y would be 1.416502 

**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