Index: src/FunctionApproximation/FunctionApproximation.cpp
===================================================================
--- src/FunctionApproximation/FunctionApproximation.cpp	(revision 1dca9a7ed8242e0bbe4f550311b7e370bbdd0fe8)
+++ src/FunctionApproximation/FunctionApproximation.cpp	(revision 5b572453f3696dfe64e32fd5b3a3a1e74aef4b3b)
@@ -79,32 +79,4 @@
 }
 
-
-/* Meyer's (reformulated) problem, minimum at (2.48, 6.18, 3.45) */
-void meyer(double *p, double *x, int m, int n, void *data)
-{
-register int i;
-double ui;
-
-        for(i=0; i<n; ++i){
-                ui=0.45+0.05*i;
-                x[i]=p[0]*exp(10.0*p[1]/(ui+p[2]) - 13.0);
-        }
-}
-
-void jacmeyer(double *p, double *jac, int m, int n, void *data)
-{
-register int i, j;
-double ui, tmp;
-
-  for(i=j=0; i<n; ++i){
-          ui=0.45+0.05*i;
-          tmp=exp(10.0*p[1]/(ui+p[2]) - 13.0);
-
-          jac[j++]=tmp;
-          jac[j++]=10.0*p[0]*tmp/(ui+p[2]);
-          jac[j++]=-10.0*p[0]*p[1]*tmp/((ui+p[2])*(ui+p[2]));
-  }
-}
-
 /** Callback to circumvent boost::bind, boost::function and function pointer problem.
  *
@@ -129,4 +101,15 @@
   function(p,x,m,n,data);
 }
+
+void FunctionApproximation::LevMarDerivativeCallback(double *p, double *x, int m, int n, void *data)
+{
+  FunctionApproximation *approximator = static_cast<FunctionApproximation *>(data);
+  ASSERT( approximator != NULL,
+      "LevMarDerivativeCallback() - received data does not represent a FunctionApproximation object.");
+  boost::function<void(double*,double*,int,int,void*)> function =
+      boost::bind(&FunctionApproximation::evaluateDerivative, approximator, _1, _2, _3, _4, _5);
+  function(p,x,m,n,data);
+}
+
 
 void FunctionApproximation::operator()()
@@ -177,5 +160,11 @@
     // give this pointer as additional data to construct function pointer in
     // LevMarCallback and call
-    ret=dlevmar_dif(&FunctionApproximation::LevMarCallback, p, x, m, n, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
+//    ret=dlevmar_dif(
+//        &FunctionApproximation::LevMarCallback,
+//        p, x, m, n, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
+    ret=dlevmar_der(
+        &FunctionApproximation::LevMarCallback,
+        &FunctionApproximation::LevMarDerivativeCallback,
+        p, x, m, n, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
 
     {
@@ -193,10 +182,4 @@
     free(work);
   }
-
-//  {
-//   double err[16];
-//   dlevmar_chkjac(meyer, jacmeyer, p, m, n, NULL, err);
-//   for(i=0; i<n; ++i) printf("gradient %d, err %g\n", i, err[i]);
-//  }
 
   {
@@ -223,4 +206,16 @@
   }
 
+  {
+   double *err = new double[n];
+   dlevmar_chkjac(
+      &FunctionApproximation::LevMarCallback,
+      &FunctionApproximation::LevMarDerivativeCallback,
+      p, m, n, this, err);
+   for(i=0; i<n; ++i)
+     LOG(1, "INFO: gradient " << i << ", err " << err[i] << ".");
+   delete[] err;
+  }
+
+
   delete[] p;
   delete[] x;
@@ -232,33 +227,69 @@
 }
 
+void FunctionApproximation::prepareModel(double *p, int m)
+{
+  ASSERT( (size_t)m == model.getParameterDimension(),
+      "FunctionApproximation::prepareModel() - LevMar expects "+toString(m)
+      +" parameters but the model function expects "+toString(model.getParameterDimension())+".");
+  FunctionModel::parameters_t params(m, 0.);
+  std::copy(p, p+m, params.begin());
+  model.setParameters(params);
+}
+
 void FunctionApproximation::evaluate(double *p, double *x, int m, int n, void *data)
 {
   // first set parameters
-  ASSERT( (size_t)m == model.getParameterDimension(),
-      "FunctionApproximation::evaluate() - LevMar expects "+toString(m)
-      +" parameters but the model function expects "+toString(model.getParameterDimension())+".");
+  prepareModel(p,m);
+
+  // then evaluate
   ASSERT( (size_t)n == output_data.size(),
       "FunctionApproximation::evaluate() - LevMar expects "+toString(n)
       +" outputs but we provide "+toString(output_data.size())+".");
-  FunctionModel::parameters_t params(m, 0.);
-  std::copy(p, p+m, params.begin());
-  model.setParameters(params);
-
-  // then evaluate
   if (!output_data.empty()) {
     inputs_t::const_iterator initer = input_data.begin();
     outputs_t::const_iterator outiter = output_data.begin();
     size_t index = 0;
-    for (; initer != input_data.end(); ++initer, ++outiter, ++index) {
+    for (; initer != input_data.end(); ++initer, ++outiter) {
       // result may be a vector, calculate L2 norm
       const FunctionModel::results_t functionvalue =
           model(*initer);
-      std::vector<double> differences(functionvalue.size(), 0.);
-      std::transform(
-          functionvalue.begin(), functionvalue.end(), outiter->begin(),
-          differences.begin(),
-          &SquaredDifference);
-      x[index] = std::accumulate(differences.begin(), differences.end(), 0.);
-    }
-  }
-}
+      x[index++] = functionvalue[0];
+//      std::vector<double> differences(functionvalue.size(), 0.);
+//      std::transform(
+//          functionvalue.begin(), functionvalue.end(), outiter->begin(),
+//          differences.begin(),
+//          &SquaredDifference);
+//      x[index] = std::accumulate(differences.begin(), differences.end(), 0.);
+    }
+  }
+}
+
+void FunctionApproximation::evaluateDerivative(double *p, double *jac, int m, int n, void *data)
+{
+  // first set parameters
+  prepareModel(p,m);
+
+  // then evaluate
+  ASSERT( (size_t)n == output_data.size(),
+      "FunctionApproximation::evaluateDerivative() - LevMar expects "+toString(n)
+      +" outputs but we provide "+toString(output_data.size())+".");
+  if (!output_data.empty()) {
+    inputs_t::const_iterator initer = input_data.begin();
+    outputs_t::const_iterator outiter = output_data.begin();
+    size_t index = 0;
+    for (; initer != input_data.end(); ++initer, ++outiter) {
+      // result may be a vector, calculate L2 norm
+      for (int paramindex = 0; paramindex < m; ++paramindex) {
+        const FunctionModel::results_t functionvalue =
+            model.parameter_derivative(*initer, paramindex);
+        jac[index++] = functionvalue[0];
+      }
+//      std::vector<double> differences(functionvalue.size(), 0.);
+//      std::transform(
+//          functionvalue.begin(), functionvalue.end(), outiter->begin(),
+//          differences.begin(),
+//          &SquaredDifference);
+//      x[index] = std::accumulate(differences.begin(), differences.end(), 0.);
+    }
+  }
+}
Index: src/FunctionApproximation/FunctionApproximation.hpp
===================================================================
--- src/FunctionApproximation/FunctionApproximation.hpp	(revision 1dca9a7ed8242e0bbe4f550311b7e370bbdd0fe8)
+++ src/FunctionApproximation/FunctionApproximation.hpp	(revision 5b572453f3696dfe64e32fd5b3a3a1e74aef4b3b)
@@ -88,6 +88,5 @@
 
   /** Evaluates the model function for each pair of training tuple and returns
-   * the error between the output of the function and the expected output as a
-   * vector.
+   * the output of the function as a vector.
    *
    * This function as a signature compatible to the one required by the
@@ -102,6 +101,24 @@
   void evaluate(double *p, double *x, int m, int n, void *data);
 
+  /** Evaluates the parameter derivative of the model function for each pair of
+   * training tuple and returns the output of the function as vector.
+   *
+   * This function as a signature compatible to the one required by the
+   * LevMar package (with double precision).
+   *
+   * \param *p array of parameters for the model function of dimension \a m
+   * \param *jac on output jacobian matrix of result values of dimension \a n times \a m
+   * \param m parameter dimension
+   * \param n output dimension times parameter dimension
+   * \param *data additional data, unused here
+   */
+  void evaluateDerivative(double *p, double *jac, int m, int n, void *data);
+
 private:
   static void LevMarCallback(double *p, double *x, int m, int n, void *data);
+
+  static void LevMarDerivativeCallback(double *p, double *x, int m, int n, void *data);
+
+  void prepareModel(double *p, int m);
 
 private:
Index: src/FunctionApproximation/FunctionArgument.hpp
===================================================================
--- src/FunctionApproximation/FunctionArgument.hpp	(revision 1dca9a7ed8242e0bbe4f550311b7e370bbdd0fe8)
+++ src/FunctionApproximation/FunctionArgument.hpp	(revision 5b572453f3696dfe64e32fd5b3a3a1e74aef4b3b)
@@ -26,6 +26,37 @@
 struct argument_t
 {
+  typedef std::pair<size_t, size_t> indices_t;
+
+  /** Default constructor for class argument_t.
+   *
+   */
+  argument_t() :
+    indices( std::make_pair(0,1) ),
+    distance(0.)
+  {}
+
+  /** Constructor for class argument_t.
+   *
+   * This constructors uses the index pair (0,1) as default.
+   *
+   * \param _distance distance argument
+   */
+  argument_t(const double &_distance) :
+    indices( std::make_pair(0,1) ),
+    distance(_distance)
+  {}
+
+  /** Constructor for class argument_t.
+   *
+   * \param _indices pair of indices associated with the \a _distance
+   * \param _distance distance argument
+   */
+  argument_t(const indices_t &_indices, const double &_distance) :
+    indices( _indices ),
+    distance(_distance)
+  {}
+
   //!> indices between which the distance is given
-  std::pair<size_t, size_t> indices;
+  indices_t indices;
   //!> distance
   double distance;
Index: src/LevMartester.cpp
===================================================================
--- src/LevMartester.cpp	(revision 1dca9a7ed8242e0bbe4f550311b7e370bbdd0fe8)
+++ src/LevMartester.cpp	(revision 5b572453f3696dfe64e32fd5b3a3a1e74aef4b3b)
@@ -177,5 +177,5 @@
 
   // now perform the function approximation by optimizing the model function
-  PairPotential_Harmonic harmonic(1., 2., 0.);
+  PairPotential_Harmonic harmonic(1., 2.9, -80.);
   FunctionModel &model = harmonic;
   FunctionApproximation approximator(1, 1, model);
Index: src/Potentials/Specifics/PairPotential_Harmonic.cpp
===================================================================
--- src/Potentials/Specifics/PairPotential_Harmonic.cpp	(revision 1dca9a7ed8242e0bbe4f550311b7e370bbdd0fe8)
+++ src/Potentials/Specifics/PairPotential_Harmonic.cpp	(revision 5b572453f3696dfe64e32fd5b3a3a1e74aef4b3b)
@@ -88,2 +88,40 @@
 }
 
+PairPotential_Harmonic::results_t
+PairPotential_Harmonic::parameter_derivative(
+    const arguments_t &arguments,
+    const size_t index
+    ) const
+{
+  ASSERT( arguments.size() == 1,
+      "PairPotential_Harmonic::parameter_derivative() - requires exactly one argument.");
+  const argument_t &r_ij = arguments[0];
+  switch (index) {
+    case spring_constant:
+    {
+      const result_t result =
+                 Helpers::pow( r_ij.distance - params[equilibrium_distance], 2 );
+      return std::vector<result_t>(1, result);
+      break;
+    }
+    case equilibrium_distance:
+    {
+      const result_t result =
+          -2. * params[spring_constant]
+                 * ( r_ij.distance - params[equilibrium_distance]);
+      return std::vector<result_t>(1, result);
+      break;
+    }
+    case energy_offset:
+    {
+      const result_t result = +1.;
+      return std::vector<result_t>(1, result);
+      break;
+    }
+    default:
+      break;
+  }
+
+  return PairPotential_Harmonic::results_t(1, 0.);
+}
+
Index: src/Potentials/Specifics/PairPotential_Harmonic.hpp
===================================================================
--- src/Potentials/Specifics/PairPotential_Harmonic.hpp	(revision 1dca9a7ed8242e0bbe4f550311b7e370bbdd0fe8)
+++ src/Potentials/Specifics/PairPotential_Harmonic.hpp	(revision 5b572453f3696dfe64e32fd5b3a3a1e74aef4b3b)
@@ -94,5 +94,5 @@
    *         input
    */
-//  results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
+  results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
 
 private:
