# Lagrange multipliers implementation (beginner question) [closed]

I am trying to write a code to find the minimum of $f(x,y) = (Mx + Ny) \,/\sqrt{M^2 x + N^2 y}$?, subject to the constraint $g(x,y)=x+y-1$. Also, $x,y>0$, and $M$ and $N$ are positive constants.

My code looks like this:

f[x_, y_] :=
(Mx + Ny)/Sqrt[M^2 x + N^2 y] :=
Boole[x > 0 && y > 0 && M > 0 && N > 0]
g[x_, y_] := x + y - 1
Minimize[{f[x, y], g[x, y] == 0}, {x, y}]


However the output I get is:

{$Failed, {x -> 0, y -> 1}}  What am I doing wrong? (Also, why is$N$not colored in$N>0$and$N^2y\$)

• To answer your last question: Don't use capital letters as variable names, because all built-in Mathematica functions are capitalized. In particular, N already has a built-in meaning. That is why N shows up in black. In the future, if such a thing occurs, you can highlight the name, click F1, and it will take you the documentation on the function (which you should be using all the time!). Sep 23 '15 at 22:09
• Further, Mx is a identifier not the expression M*x (also written M x). Sep 23 '15 at 22:26
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Sep 23 '15 at 22:40

f[x_, y_] := (M x + n y)/Sqrt[M^2 x + n^2 y]

• N is a reserved word in Mathematica. Never start your own symbols with capitals Sep 23 '15 at 22:07