I need help with Optimizer to Find Minimum Error

Hello guys,

I have a Plant data and try to fitting it with 2nd Differential Equation that described APMonitor by Find Minimum of the Sum of Relative Error (modified from Sum of Absolute Error to get 0 - 100% error value).

I have some insight by following https://discuss.mathdotnet.com/t/how-to-use-the-optimization-class/545, but i have trouble to have divergent result. Either i get NaN or Infinity Sum of Relative Error. I tried to to manipulate it by override the Sum of Relative Error Value that resulted NaN or Infinity to last good value.

But i get exception on my Application

System.overflow: ‘Value was either too large or too small for a Decimal.’

I still don’t understand how to get convergent result properly. Please guide me to solve this.

If you need the code i will edit my post :slight_smile:


  1. I Use ForwardDifferenceGradientObjectiveFunction to get Gradient
  2. I use ConjugateGradientMinimizer to evaluate the gradient
  3. after all i do FindMinimum

Thanks in advance
Andre Mailoa
Process Control Engineer

As noted towards the end of the link in your second paragraph, the choice of the initial guesses is critical. It may be your function will only converge with very good guesses. Also, the Conjugate Gradient method assumes the surface is smooth, i.e. can be approximated by a polynomial.

I suggest trying to prove the code is correct by using it to find the parameters of a simple function. Once you know the code is OK, you can work on adjusting the input parameters of the hard function.