title: Karush–Kuhn–Tucker (KKT) conditions and SciPy
body: <p>How can I solve nonlinear optimization problem like this (<a href="https://en.wikipedia.org/wiki/Karush%E2%80%93Kuhn%E2%80%93Tucker_conditions" rel="nofollow">https://en.wikipedia.org/wiki/Karush%E2%80%93Kuhn%E2%80%93Tucker_conditions</a>) with SciPy:</p>
  
  <p>Optimize: f(X) = x1^2 + x2^2</p>
  
  <p>Constraint functions: x1 >= 0; x2 >= 0; x1 + 2*x2 &lt;= 4</p>
  
  <p>I wrote this:</p>
  
  <pre><code>import numpy as np
  
  def func(X):
      x = X[0]
      y = X[1]
      L = X[2]
      return x**2 + y**2 + L * (x + 2*y - 4)
  
  def dfunc(X):
      dLambda = np.zeros(len(X))
      h = 1e-3
      for i in range(len(X)):
          dX = np.zeros(len(X))
          dX[i] = h
          dLambda[i] = (func(X+dX)-func(X-dX))/(2*h);
      return dLambda
  
  import scipy
  from scipy.optimize import fsolve
  
  X1 = fsolve(dfunc, [1, 1, 0])
  print X1
  </code></pre>
  
  <p>I found only one solution: 0.8,1.6</p>
  
  <p>But there are more: 0,0 4,0 0,2</p>
  
  <p>How can I find it with SciPy?</p>