# Optimization problem involving step function

I've got to optimize the following function with respect to $\phi$:

$q(\phi, x) = \frac{1}{n} \sum_{i=1}^{n}{H(y_i)}$

where

$y_i = k - \phi l - x_i$

and $H(.)$ denotes the Heaviside function. $k$ and $l$ are constants, and $x$ follows either (1) a continuous uniform distribution or (2) a normal distribution. This is part of a quite standard programming problem but I'm a little stuck with finding the optimal $\phi$

I'm sure this is a totally simple question but I can't quite figure it out... any help is greatly appreciated...

-
How does a finite number $n$ of discrete values $x_i$ being drawn from a continuous distribution have anything to do with $q$ being continuously differentiable? $q$ has $n$ jumps, no matter how the $n$ discrete values $x_i$ were produced. – joriki Aug 24 '12 at 19:23
You are right of course about $q$, sorry for this glitch. Do you think there is a way to work around it anyway, maybe something along these lines? math.stackexchange.com/questions/16788/… – jush Aug 24 '12 at 20:08
The title and body don't match. I've provided an answer to the question in the body. – joriki Aug 24 '12 at 20:27

The step functions all add up in the same direction, since $\phi$ has the same sign in all $y_i$ – thus $q$ is minimal for all $\phi$ such that all step functions are $0$, which occurs for $\phi\lessgtr(k-x)/l$, where the inequality is $\lt$ or $\gt$ and $x$ is the greatest or least of the $x_i$, depending on whether $l$ is negative or positive, respectively.