# Optimization inside integral

I want maximize the integral

$$\int_a^b \left( 2 cx y(x) - e y(x)^2 \right) \, \mathrm{d}x$$

with respect to to $y(x)$.

If I discretize the problem, I get

$$\frac{b-a}{n}\sum_{i=1}^n 2c(i/n(b-a)+a)y_i-eyi^2$$

If I take the derivative with respect to each $y_i$, I find in undiscretized version $y(x)$ as $\frac{cx}{e}$ If i plugin the values i get my optimization result.

I can understand the dynamics of the problem, but my calculus is a bit rusty, Is there anyone who can pinpoint which chapter of the calculus book should i skim in order to get more formal explanation. Thanks in advance

• You should google for discrete methods in variational calculus. There are plenty of good books that treat the matter with more elemmental or advanced approaches – user335721 Jun 4 '16 at 7:36
• No, this has nothing to do with discrete methods; the discretisation just distracts from the simple structure of the problem. – joriki Jun 4 '16 at 7:38

## 2 Answers

No fancy calculus is required. Since there are no constraints and no derivatives of $y$ occur in the integral, only $y$ itself, the integral is directly maximised by maximising the integrand at each point separately. Setting the derivative of $2cxy-ey^2$ with respect to $y$ to $0$ yields $2cx-2ey=0$ and thus $y=\frac{cx}e$.

• Thanks for the answer, i understand the problem is easy, but i want to write it a bit formally, can you tell which part of the which book should i consult? Thanks – Aylean Clara Grandieur Jun 4 '16 at 7:41
• @AyleanClaraGrandieur: I don't know about books, but the property you need is the monotonicity of integration -- integration (both Riemann and Lebesgue) is monotonic in the sense that if $f\le g$ everywhere, then $\int f\mathrm dx\le\int g\mathrm dx$. That's all you need to formally prove that if you maximise the integrand at every point, you maximise the integral. – joriki Jun 4 '16 at 7:47

The Lagrangian is $\mathcal{L} (y) := 2 cx y(x) - e y(x)^2$. From the Euler-Lagrange equation, we get $2 c x - 2 e y = 0$ and, thus, $y = \left(\frac{c}{e}\right) x$ maximizes the integral.

• Calculus of variations is overkill here; it's enough to just maximise the integrand pointwise. – joriki Jun 4 '16 at 7:50
• @joriki Indeed, that is what the Euler-Lagrange equation tells us to do. – Rodrigo de Azevedo Jun 4 '16 at 7:51
• Sure it does; I was just pointing out that you're taking a sledgehammer to crack a nut. Everyone with a smattering of calculus can solve the problem; if you use a much more advanced method, I think you should at least mention the fact that it's not necessary. – joriki Jun 4 '16 at 7:59
• @joriki I am not a mathematician. I use the few tools I know, even when they're excessive. – Rodrigo de Azevedo Jun 4 '16 at 8:01