commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fabio Cerqueira <frcerque...@gmail.com>
Subject curve fitting ax^b
Date Wed, 26 Aug 2009 21:19:11 GMT
Hello,

I need to perform curve fitting where the function is of the form: ax^b.
I saw that polynomial fitting is already implemented in
commons.math, but a function like the one I need is not.

Then I found the CurveFitter class and proceeded like below,
but I haven't succeeded. Any suggestion?

Thanks, Fabio

class PowerFunction implements ParametricRealFunction {

  // overriding
  public double[] gradient(double x, double[] parameters) {
    double vet[] = new double[10];
    double coef, exp, newExp, coefTimesExp, power;

    if ( x==0 ) {
      vet[0] = 0;
    }
    else {
      coef = parameters[0];
      exp = parameters[1];
      coefTimesExp = coef * exp;
      newExp = exp-1;
      power = Math.pow( x, newExp );
      vet[0] = coefTimesExp * power;
    }
    return vet;
  } // gradient

  // overriding
  public double value(double x, double[] parameters) {
    double coef, exp, power;
    coef = parameters[0];
    exp = parameters[1];
    power = Math.pow( x, exp );

    return ( coef * power );
  } // value

} // class PowerFunction

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message