I need to determine the maximum value for y = ax^2 + bx + c, where I know the coefficients and the upper and lower x values.
Say the input values are:
- a = 5
- b = 1
- c = 2
- x lower limit = -5
- x upper limit = 5
Given these input, how do I determine the the maximum value for the quadratic equation above?
My goal is to implement a function in a computer programming language that has a signature such as funcMax(int a, int b, int c, int xUpper, int xLower). The part that is confusing me is that I have two x values for this signature but one x in the formula above.
But computer programming aside for now, mathematically, how do I get the max value for the above equation, using the above input (with two x values)?
For this quadratic function, the global maximum happens either at the two ends or at a local maximum.
The first two cases are simple, you have to only compare the $y$ evaluated at the upper and lower limits of $x$ respectively.
And there is a local maximum only if the $a$ value is negative, shown by the second derivative test. When this is the case, the maximum value is given by taking $x = -\frac b{2a}$. (You can verify this by completing square or first derivative test.) Then you have to check if this $x$ is within your domain given by the upper and lower limits.
If I write your required function out:
$$\begin{align*}&\text{funcMax}(a,b,c,x_{Upper}, x_{Lower}) \\ =& \begin{cases} \max(ax_{Upper}^2 + bx_{Upper}+c, ax_{Lower}^2 + bx_{Lower}+c,\frac{b^2}{4a}-\frac{b^2}{2a}+c) & \text{if }a\ne0\text{ and }x_{Upper}\le-\frac{b}{2a}\le x_{Lower}\\ \max(ax_{Upper}^2 + bx_{Upper}+c, ax_{Lower}^2 + bx_{Lower}+c) & \text{otherwise} \end{cases}\end{align*}$$