I've been trying to maximize and minimize the following function using Lagrange Multipliers, in Wolfram Mathematica 11.3:

d = Sqrt[x^2 + y^2 + z^2 + u^2 + v^2 + w^2]

Subject to the following constraints:

g = x + y + z + u + v + w - 1 and h = x^2 + y^2 + z^2 + u^2 + v^2 - 1

What I've tried so far is the following:

Gd = {D[d, x], D[d, y], D[d, z], D[d, u], D[d, v], D[d, w]}

Gg = {D[g, x], D[g, y], D[g, z], D[g, u], D[g, v], D[g, w]}

Gh = {D[h, x], D[h, y], D[h, z], D[h, u], D[h, v]}

system = {Gd[[1]] == \[Lambda] Gg[[1]] + \[Micro] Gh[[1]], 
   Gd[[2]] == \[Lambda] Gg[[2]] + \[Micro] Gh[[2]], 
   Gd[[3]] == \[Lambda] Gg[[3]] + \[Micro] Gh[[3]], 
   Gd[[4]] == \[Lambda] Gg[[4]] + \[Micro] Gh[[4]], 
   Gd[[5]] == \[Lambda] Gg[[5]] + \[Micro] Gh[[5]], 
   Gd[[6]] == \[Lambda] Gg[[6]], g == 0, h == 0};
% // MatrixForm

And then a little Solve function:

sist = Solve[system, {x, y, z, u, v, w, \[Lambda], \[Micro]}]

After executing, it just keeps running forever. Any ideas on how to make it easier?

  • $\begingroup$ Are Lagrange multipliers required for some reason? One can simply do this using Maximize. It will be easier if the Sqrt[] is dropped (makes no difference to the arg max). $\endgroup$ Commented Nov 18, 2019 at 18:07

1 Answer 1


For the minimum, you can use NMinValue. I changed it up to use some Region functionality:

NMinValue[{Sqrt[v.v+w^2], Total[v]+w==1, v ∈ Sphere[5]},{v, w}]


Or, you can use explicit scalars:

NMinValue[{Sqrt[x^2+y^2+z^2+u^2+v^2+w^2], x+y+u+v+w==1&&x^2+y^2+z^2+u^2+v^2==1},{x,y,z,u,v,w}]


I'm not sure if using MinValue would ever finish.

For the maximum, you can use MaxValue:

MaxValue[{Sqrt[v.v+w^2], Total[v]+w==1, v ∈ Sphere[5]},{v, w}]

Sqrt[7 + 2 Sqrt[5]]

Or, using explicit scalars:

MaxValue[{Sqrt[x^2+y^2+z^2+u^2+v^2+w^2], x+y+z+u+v+w==1&&x^2+y^2+z^2+u^2+v^2==1},{x,y,z,u,v,w}]

Sqrt[7 + 2 Sqrt[5]]

Use NMinimize and Maximize if you want the location of the extrema as well as the value.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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