# sixtyfive.C

minimize

subject to

```00001
00010 //------------------------------------------------------------------------
00011 // P.J. Williams
00012 // Sandia National Laboratories
00013 // pwillia@sandia.gov
00014 //------------------------------------------------------------------------
00015
00016 #ifdef HAVE_CONFIG_H
00017 #include "OPT++_config.h"
00018 #endif
00019
00020 #if defined(SGI) || defined(RS6K)
00021 #define WANT_MATH
00022 #else
00023 #define WANT_STREAM
00024 #define WANT_MATH
00025 #endif
00026
00027 #ifdef HAVE_STD
00028 #include <cstdio>
00029 #include <cstdlib>
00030 #include <cmath>
00031 #else
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <math.h>
00035 #endif
00036
00037 #include "newmatap.h"
00038
00039 #include "NLP.h"
00040 #include "NLF.h"
00041
00042 using NEWMAT::ColumnVector;
00043 using NEWMAT::Matrix;
00044
00045 using namespace OPTPP;
00046
00047 void init_hs65(int ndim, ColumnVector& x)
00048 {
00049   if (ndim != 3)
00050   {
00051     exit (1);
00052   }
00053   double factor = 0.0;
00054   x(1) = -5.0 ;// - (factor - 1)*8.6505  ;
00055   x(2) =  5.0 ;// + (factor - 1)*1.3495  ;
00056   x(3) =  0.0 ;// - (factor - 1)*4.6204  ;
00057 }
00058
00059 void hs65(int mode, int n, const ColumnVector& x, double& fx, ColumnVector& g, int& result)
00060 { // Hock and Schittkowski's Problem 65 (the objective fcn)
00061   double f1, f2, f3, x1, x2, x3;
00062
00063   if (n != 3) return;
00064
00065   x1 = x(1);
00066   x2 = x(2);
00067   x3 = x(3);
00068   f1 = x1 - x2;
00069   f2 = x1 + x2 - 10.0;
00070   f3 = x3 - 5.0;
00071
00072   if (mode & NLPFunction) {
00073     fx  = f1*f1+ (f2*f2)*(1.0/9.0) +f3*f3;
00074     result = NLPFunction;
00075   }
00076   if (mode & NLPGradient) {
00077     g(1) =  2*f1 + (2.0/9.0)*f2;
00078     g(2) = -2*f1 + (2.0/9.0)*f2;
00079     g(3) =  2*f3;
00081   }
00082 }
00083
00084 void ineq_hs65(int mode, int n, const ColumnVector& x, ColumnVector& cfx, Matrix& g, int& result)
00085 { // Hock and Schittkowski's Problem 65
00086       double f1, f2, f3, fx, x1, x2, x3;
00087
00088   if (n != 3) return;
00089
00090   x1 = x(1);
00091   x2 = x(2);
00092   x3 = x(3);
00093   f1 = x1;
00094   f2 = x2;
00095   f3 = x3;
00096
00097   if (mode & NLPConstraint) {
00098     fx  = f1*f1 + f2*f2 + f3*f3;
00099     cfx = fx;
00100     result = NLPConstraint;
00101   }
00102
00103   if (mode & NLPCJacobian) {
00104     g(1,1) = 2*x1;
00105     g(1,2) = 2*x2;
00106     g(1,3) = 2*x3;
00107     result = NLPCJacobian;
00108   }
00109 }
```