# How do I setup the lagrangian for this problem?

I have a function $y(x)$, that I would like to maximize, subject to two constraints. It is given by:

$$\max_{x} \ y(x) = a \ cos(x) + b \ sin(x) \\ \text{subject to:} \\ x \geq 0 \\ x \leq \frac{2}{3}\pi$$

($a$ and $b$ are just scalars).

Anyway, I am not really sure how to constrict this lagrangian for this problem, given the constraints. I can solve the problem without constraints, but with those constraints, one that is less than, and one that is greater than, I am getting confused as to how to set the problem up.

How do I set up the lagrangian here?

Thanks.

• Why do you need a Lagrangian ?. – Felix Marin Mar 2 '14 at 0:40
• @FelixMarin Hi Felix, I am new to this, but I was under the impression that for the constraints here, I need to form a lagrangian before taking its derivative... – Spacey Mar 2 '14 at 0:40

Well, your problem is one-dimensional, so you don't need a Lagrangian. The only possible extremal points are those where $y'(x)=0$, and the end-points $0$ and $2\pi/3$. So you don't take any derivatives for the end-point, you simply compute the values.

You would need a Lagrangian for the boundaries, but only in more dimensions, for example when optimizing a function over a polygon in $\mathbb R^2$.

If you insisted in constructing the Lagrangians, then the one for the right boundary is as follows: The boundary condition is $g_1(x)=x-2\pi/3$, therefore your Lagrangian is $\Lambda(x,\lambda_1) = f(x) - \lambda_1g_1(x)$. Now you solve $\frac{\partial\Lambda}{\partial x}=0$ to find out that it has always got a solution $\lambda_1 = \frac{\partial f}{\partial x}$. We are not really getting anything reasonable, are we?

To show a different example, let's optimize $f(x,y)$ over the domain $y\geq0$ and $y\leq x^2-1$. This is a piece of plane with boundary consisting of two curves and two points. Now the maximum is maximum of:

• $f(x,y)$ over the interior (solve by basic calculus);
• $f(x,y)$ over $y=0$ and $x\in(-1,1)$ (solve by Lagrangians);
• $f(x,y)$ over $y=x^2-1$ and $x\in(-1,1)$ (solve by Lagrangians);
• $f(-1,0)$ (one point, so nothing to do);
• $f(1,0)$ (one point, so nothing to do).

So you see, it's a lot of work. I'll just show the Lagragian of the parabola. You have $g(x,y)=x^2-1-y$ and $\Lambda(x,y,\lambda_1)=f(x,y)-\lambda_1 g(x,y)$. Now you search for $\lambda_1$ and $x,y$ such that: $$g(x,y)=0,\quad \frac{\partial\Lambda}{\partial x}=0,\quad \frac{\partial\Lambda}{\partial y}=0.$$

• Hmm... ok, that's news to me! :-) So how would I solve this problem with those constraints? (I can already easily solve it without the constraints, by taking derivative of the objective, set to zero, check sign of second derivative, etc). Its this part with the constraints that I am wondering about. – Spacey Mar 2 '14 at 1:08
• Well, you simply search (by the derivatives method) for maxima inside $(0,2\pi/3)$, let's call it $y_M$. Then the maximum you look for is simply $\max(y_M, y(0), y(2\pi/3))$. – yo' Mar 2 '14 at 1:13
• You mean just solve normally, and then just pick the result between $0$ and $\frac{2}{3}\pi$ inclusive? I thought there would be a more analytical way of doing it, no? – Spacey Mar 2 '14 at 1:16
• Also I thought we always form a lagrangian anytime we have a constrained optimization problem from my understanding of the google links... – Spacey Mar 2 '14 at 1:19
• @Spacey This is analytical. You always need to treat the boundary seperately. Remember that $y(x)=2x$ has to global maximum, still it has a maximum in $[0,1]$, attained at $2$. You can actually construct Lagrangians for each of the boundary point, but the domains of these are single points, so it's a non-sense to do. – yo' Mar 2 '14 at 1:20