Constrained optimization problem with the integral I want to maximize the following integral $I = \int_0^\infty  {f\left( {P(x),x} \right){p_X}(x)dx} $ subject to the constraint $\int_0^\infty  {P(x){p_X}(x)dx}  = P_x$, where $p_X(.)$ is a probability distribution function, $P_x$ is a positive real number and $f(.,.)$ is a function. I want to find $P(.)$ as a function of $x$ by using Lagrange Multiplier method. The Lagranrian is 
$$
L = \int_0^\infty  {f\left( {P(x),x} \right){p_X}(x)dx}  - \lambda \left[ {\int_0^\infty  {P(x){p_X}(x)dx}  - P_x} \right].
$$
After differentiate $L$ and set it to zero as follows
$$
\frac{{\partial L}}{{\partial P(x)}} = 0,
$$
I obtain $P(x)$ now becomes a function of $x$ and $\lambda$: $P(x) = g(x,\lambda )$. Subtituting this result to the constraint to find $\lambda$ yields the integral $\int_0^\infty  {g(x,\lambda ){p_X}(x)dx} $ diverges. So the equation $\int_0^\infty  {g(x,\lambda ){p_X}(x)dx} = P_x$ cannot be solved.
In this case, what should I do to solve the above optimization problem? Please noted that the goal is to find $P(.)$ as a function of $x$.
 A: The first goal is to find those functions $y=y(x)$'s that extremize the functional
$$I[P]=\int_0^{\infty} f(y(x),x)p_X(x)dx-\lambda(\int_0^{\infty} y(x)p_X(x)dx-P_x)$$,
for a fixed $f$ and probability distribution $p_X$. We need to compute the derivative
$$\frac{dI}{d\phi}|_{y}=\lim_{\epsilon\rightarrow 0}\frac{I[y+\epsilon \phi]-I[y]}{\epsilon}$$,
of $I$ at $y$, considering all small variations $\epsilon \phi$ around $y$. In the spirit of the calculus of variations we should formalize the concept of $\phi(x)$ being a "variation" of $y$. For the terminology and some examples I refer to
http://ocw.mit.edu/courses/mathematics/18-086-mathematical-methods-for-engineers-ii-spring-2006/readings/am72.pdf
Let us try to compute $\frac{dI}{d\phi}|_{y}$. Assuming that $f(y,x)$ is differentiable, then we can write
$$f(y+\epsilon \phi,x)-f(y,x)=\langle \nabla (f), h(\epsilon) \rangle + O(\epsilon^2), $$
where we consider the increment $h(\epsilon)=(\epsilon \phi,0)$. $\nabla (f)$ is the gradient of $f$ at $(y,x)$. The functional derivative now becomes (after a bit of algebra) 
$$ \frac{dI}{d\phi}|_{y}=\int_0^{\infty} (\frac{\partial f(y(x),x)}{\partial y}-\lambda)\phi(x) p_X(x)dx. $$
for all variations $\phi$ around $y$. Modulo regularity conditions (I am sloppy here!) we arrive at
$$(\frac{\partial f(y(x),x)}{\partial y}-\lambda)p_X(x)=0$$.
A this point you could consider $\frac{\partial f(y(x),x)}{\partial y}-\lambda=0$ and try to solve it w.r.t. $y(x)$ ; however without extra hypothesis on $y(x)$ you can not determine the Lagrange multiplier.
ps: are you sure that $f=f(y(x),x)$ and not $f=f(y'(x),y(x),x)$?
