# mathematical optimization – Maximization of piecewise function

I’m trying to maximize piecewise functions with parameters but haven’t been able to do so. Here is a minimum example:

``````f(x_, a_) = -(x - 10*a)^2 + 50*a;
w(x_, a_) = (Piecewise) {
{f(x, a), 1/2 < a < 8/x && 0 < x < 20},
{-10, True}
};
``````

I want to maximize $$w$$ over $$x$$ ($$a$$ is a parameter). Any ideas on how to solve this symbolically (or even numerically with $$a$$ in a grid)?