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$)

(See also my next question)

  • 4
    $\begingroup$ 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!). $\endgroup$
    – march
    Sep 23 '15 at 22:09
  • 2
    $\begingroup$ Further, Mx is a identifier not the expression M*x (also written M x). $\endgroup$
    – m_goldberg
    Sep 23 '15 at 22:26
  • $\begingroup$ 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. $\endgroup$
    – bbgodfrey
    Sep 23 '15 at 22:40
f[x_, y_] := (M x + n y)/Sqrt[M^2 x + n^2 y]
g[x_, y_] := x + y - 1
Minimize[{f[x, y], g[x, y] == 0, M > 0, n > 0, x > 0, y > 0}, {x, y}]
  • 2
    $\begingroup$ N is a reserved word in Mathematica. Never start your own symbols with capitals $\endgroup$ Sep 23 '15 at 22:07
  • $\begingroup$ Thank you. Now I'm trying to make the same function for 3 variable (see above). But I've been waiting for some time and still running with no answer, am I doing something wrong? $\endgroup$ Sep 23 '15 at 22:30
  • 1
    $\begingroup$ @odnerpmocon Don't "upgrade" your question, but post another one if you need more help. Upgrading doesn't work in these sites $\endgroup$ Sep 23 '15 at 23:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.