#ifndef PROBSYSEQU01_H
#define PROBSYSEQU01_H

typedef unsigned int uint;
typedef unsigned int const uintc;


/*!
\brief Test problem. 

Solve a 2D non linear simultaneous equation.
 */
class probsysequ01
{
public:

  /** Counts the number of times the function is evaluated. */
  uint counter;

  double * xi;
 
  probsysequ01()
    : counter(0), xi(new double[2]) {}
  ~probsysequ01()
    { delete[] xi; }

  /** Evaluate the function to be minimized. */
  void operator () 
  (
    double & fval 
  ) 
  {
    double t0 = xi[0]-0.1136*(xi[0]+3.0*xi[1])*(1.0-xi[0]);
    double t1 = xi[1]+7.5*(2.0*xi[0]-xi[1])*(1.0-xi[1]);
    fval = t0*t0 + t1*t1;
//cout << SHOW(fval) << endl;
    ++counter;
  }

  /** Numerically evaluate the partial derivative. */
  void partialderivative
  (
    double & val,
    uintc i,
    double const h
  )
  {
    assert(i<2);
    static double x2[2];

    //Save initial value.
    x2[i] = xi[i];

    xi[i] -= h*0.5;
    double f0;
    operator()(f0);

    double f1;
    xi[i] += h;
    operator()(f1);

    val = (f1-f0)/h;

    // Restore initial value.
    xi[i] = x2[i];
  };

};


#endif



