Previous: Functions and Variables for cobyla, Up: cobyla [Contents][Index]

### 47.3 Examples for cobyla

Minimize \(x_1 x_2\) with \(1-x_1^2-x_2^2 \ge 0.\)

The theoretical solution is $$ \eqalign{ x_1 &= {1\over \sqrt{2}} \cr x_2 &= -{1\over \sqrt{2}} } $$

    (%i1) load("fmin_cobyla")$

    (%i2) fmin_cobyla(x1*x2, [x1, x2], [1,1],
                      constraints = [x1^2+x2^2<=1], iprint=1);

       Normal return from subroutine COBYLA

       NFVALS =   66   F =-5.000000E-01    MAXCV = 1.999845E-12
       X = 7.071058E-01  -7.071077E-01
    (%o2) [[x1 = 0.70710584934848, x2 = - 0.7071077130248],
           - 0.49999999999926, [[-1.999955756559757e-12],[]], 66]

Here is the same example but the constraint is \(x_1^2+x_2^2 \le -1\) which is impossible over the reals.

    (%i1) fmin_cobyla(x1*x2, [x1, x2], [1,1],
             constraints = [x1^2+x2^2 <= -1], iprint=1);

       Normal return from subroutine COBYLA

       NFVALS =   65   F = 3.016417E-13    MAXCV = 1.000000E+00
       X =-3.375179E-07  -8.937057E-07
    (%o1) [[x1 = - 3.375178983064622e-7, x2 = - 8.937056510780022e-7],
                                                    3.016416530564557e-13, 65, - 1]
    (%i2) subst(%o1[2], [x1^2+x2^2 <= -1]);
    (%o2)                 [- 6.847914590915444e-13 <= - 1]

We see the return code (`%o1[4]`) is -1 indicating that the constraints may not be satisfied. Substituting the solution into the constraint equation as shown in `%o2` shows that the constraint is, of course, violated.

There are additional examples in the share/cobyla/ex directory and in share/cobyla/rtest_cobyla.mac.

Previous: Functions and Variables for cobyla, Up: cobyla [Contents][Index]