DEMSLV13

Simple nonlinear complementarity problem

The problem is to solve

\begin{equation} f(x, y) = \begin{bmatrix}1+x(y -2x^2-1)\\ 2x^2-y\end{bmatrix} \end{equation}

subject to $0 \leq x, y \leq 1$

In [1]:
from compecon import MCP
from compecon.tools import jacobian
from demos.setup import np

Solving the problem

To solve this problem we create a MCP object using a lambda function.

In [2]:
a = np.array([0.0, 0.0])
b = np.array([1.0, 1.0])

def func(z):
    x, y = z
    fval = np.array([1 + x * (y - 2*x**2 - 1), 2*x**2 - y])
    return fval
                   
F = MCP(func, a, b)

Solve for initial guess $x_0 = [0.5, 0.5]$

In [3]:
x0 = [0.5, 0.5]
x = F.zero(x0, transform='minmax', print=True)
Using the MINMAX transformation
Solving nonlinear equations by Broyden's method
it    bstep  change
--------------------
   0     1  1.56e-01
   1     1  1.14e-01
   2     1  1.01e-01
   3     0  3.66e-02
   4     0  1.33e-03
   5     0  1.86e-05
   6     0  2.02e-07
   7     0  1.13e-09

The solution is

In [4]:
print('[x, y] = [{:.4f}, {:.4f}]'.format(*x))
[x, y] = [0.7937, 1.0000]