What you are suggesting will (roughly) work, but you might consider just fitting log x versus log y.
Your error terms will not be squared error, but instead will be squared relative error. On Wed, Aug 26, 2009 at 2:19 PM, Fabio Cerqueira <[email protected]>wrote: > 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 > -- Ted Dunning, CTO DeepDyve
