Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I find local maxima of this quadratic function?

$$f(x) = \sum _{i=1}^n -\frac{(z_i - x)_+^2}{2} - \left\{((\frac{(z_i - x)_+^2}{2})-(\frac{(y_i - x)_+^2}{2}) ) * c_i\right\} $$

which + means If $z_i$ is bigger than u its equal $z_i - x$ and else it's equal zero. Also $z_i$, $y_i$ and $c_i$ is a vector of values with same lengths.$z_i$ and $y_i$ is an interval.

$$ z = (0.04124633, 0.05404163, 0.30939022, 0.57690859, 0.70211949, 0.73597262, 0.92130814,1.05226194, 1.68227033, 1.91068738)$$ $$y = (0.2112338, 0.4172289, 0.3991616, 0.8755037, 1.2448935, 1.3493179, 1.6522002, 2.4177490, 4.7770777, 2.3840472)$$ $$ c = (5.337958, 2.275704, 10.64689, 2.873863, 1.293402, 1.03867, 0.6372883, 0.1032198, 0.000045619, 0.5670724)$$ I plot this quadratic function in terms of x which can be change between max finite value of $z_i$ and $y_i$ and see that theres is one local maxima but I do not know how can I find it matematically?

share|cite|improve this question
up vote 0 down vote accepted

Since the function is everywhere differentiable, it can have local extrema only at the points where $f'=0$. The formula for the derivative is $$\begin{split} f'(x) &= \sum _{i=1}^n (z_i-x)_+ + c_i \{(z_i - x)_+- (y_i - x)_+ \} \\ &= \sum_{i=1}^n (1+c_i)(z_i-x)_+ - \sum_{i=1}^n c_i (y_i - x)_+ \end{split} \tag 1 $$ if I parsed your formula correctly (it appears to have a few unnecessary parentheses). This function is piecewise linear; its graph has corners at the points $z_i$ and $y_i$.

I don't think there is a very clever way to deal with such piecewise linear functions. I would list the numbers $z_i,y_i$ in increasing order, plug each into $f'$, and noted the signs. The maximum will be found within an interval where $f'$ is positive at the left endpoint and is negative at the right endpoint. The precise location is found by solving linear equation (since $f'$ is linear within the interval of interest).

For example, on the interval $(1.68227033, 1.91068738 )$ we have $$\sum_{i=1}^n (1+c_i)(z_i-x)_+ = (1+0.5670724) (1.91068738-x)$$ and $$\sum_{i=1}^n c_i (y_i - x)_+ = 0.1032198 (2.4177490-x)+0.000045619 (4.7770777-x) + 0.5670724(2.3840472-x)$$ So, you can simplify $f'(x)=\sum_{i=1}^n (1+c_i)(z_i-x)_+ - \sum_{i=1}^n c_i (y_i - x)_+$ by expanding the parentheses, and check if $f'$ turns to zero or not.

share|cite|improve this answer
Could you please give me an example to understand better your explanation? I dont know how to find and check each interval. Thanks. – rose May 14 '13 at 3:10
@rose Added an example. – 75064 May 14 '13 at 3:18
Thanks for your example. At the end for example I find that for this interval the value is equal -1.552835 and because its not in the interval (1.68227033,1.91068738) , so we do not have local maxima in this interval and I should continue for the rest 18 intervals. – rose May 14 '13 at 3:57
@rose Yes, and as I wrote, you can simplify the task by plugging in the endpoints before you try to solve the linear equation. Because if a linear function takes values of the same sign at both endpoints, then it does not turn into zero on that interval. – 75064 May 14 '13 at 4:05
yes. Thanks. Just I want to mention that your derivative for each parts neeed a minus. – rose May 14 '13 at 4:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.