Optimizing a function with no local maximum? suppose we have a function f(x)=$\sqrt{\left(\ x\ \right)}\ +\ \left(\frac{C-x}{4}\right)$ and we want to maximize the function when C=<4 and x<C. How do we procede with the problem?
Note that I've never studied optimization, I'm just trying to solve a budget constraint problem in microeconomics.
 A: Calling
$$
f(x,C) = \sqrt{x}+\frac{C-x}{4}
$$
In the following plot in blue we have the feasible region $(0 < x < C, C\le 4)$ to the maximization problem, and in black the level curves to the surface $f(x,C)$

As we can easily verify, the maximum is located at $x = C = 4$
A: Solving $f'(x)=0$ gives
$$
\frac1{2\sqrt x} -\frac14=0,
$$
where the solution is $x=4$. Since $f'(x)>0$ for $0<x<4$, the function is strictly monotonically increasing on $[0,C]$, hence the maximum is at the right boundary of the intervall, hence at $x=C$.
A: A little bit more formal derivation (although I think @Cesareo already has a nice, clear illustration).
This is an optimizitaion problem
$$\begin{aligned}
\text{max}_{x,C}\ &f(x,C)\\
\text{s.t.}\\
{h}_1(x,C)=x-c&\leq{0},\\
h_2(x,C)=C-4&\leq 0
\end{aligned}$$
in two variables, x and C,where $\vec{h}=[h_1, h_2]^T=[(x-C),\ (C-4) ]^T$. For a maximum (or minimum), the KKT equations
$$\begin{aligned}
\nabla f(x,C) + \nabla \vec{h}(x,C)\vec{\mu} &= \vec{0}\\
\vec{\mu}^T\vec{h}(x,C)&=0\\
\vec{\mu} &\geq \vec{0}
\end{aligned}$$
are a necessary condition, where $\nabla(\cdot)$ signifies the gradient of the respective quantity (which is the transpose of the Jacobian). The latter two equations are the so-called complementary slackness conditions, and $\vec{\mu}=[\mu_1,\mu_2]^T$ is a vector of Lagrange multipliers.
An inequality $i$ at the solution is said to be active if $h_i(x,C)=0$ and inactive if $h_i(x,C)<0$. The complementary slackness conditions say that if an inequality constraint is active, the corresponding Lagrange multiplier is $\mu_i>0$. If an inequality is inactive this implies that the corresponding $\mu_i=0$. This is why this condition is called complementary. Either the inequality is zero or its corresponding Lagrange multiplier is.
Applying this to your problem yields
$$\begin{align}
\frac{1}{2\sqrt{x}}-\frac{1}{4} + \mu_1&=0\\
 \frac{1}{4} -\mu_1 + \mu_2&=0\\
\mu_1(x-C)+\mu_2(C-4)&=0\\
\vec{\mu}&\geq \vec{0}.
\end{align}$$
Now, we have to distinguish between four cases:

*

*both $h_1(x,C)$ and $h_2(x,C)$ are inactive at the solution which implies $\Rightarrow$ $\mu_1=\mu_2=0$. This, however, is not valid since this would result in $\frac{1}{4}=0$ (from the second equation above) which is not true.

*$h_1(x,C)$ is active and $h_2(x,C)$ is inactive at the solution which implies $\Rightarrow$ $\mu_1=0$. From the second equation we now get $\mu_2=-\frac{1}{4}$ and from the first equation we get the candidate $x=1$. From the third equation, however, we see that $C=-16$ which violates $h_1(x,C)$ ($x$ must be smaller or equal to $C$).

*$h_1(x,C)$ is inactive and $h_2(x,C)$ is active at the solution which implies $\Rightarrow$ $\mu_2=0$. From the second equation we now get $\mu_1=\frac{1}{4}$ and from the first equation we get $\frac{1}{2\sqrt{x}}=0$ which is impossible.

*This only leaves us with the last possibility that both inequalities must be active at the solution so that $x^\ast=C^\ast$ and $x^\ast=4$ and $f(x^\ast,C^\ast)=2$.

