# commons-user mailing list archives

##### Site index · List index
Message view
Top
From South Light <southligh...@gmail.com>
Subject [math] Curve fitting ...
Date Thu, 14 Aug 2014 01:08:39 GMT
```Hi,

May be someone can help me with this problem.

Given the follow function: y = 10 ^ ((x + 82) / (-10 * A))

I would like to found the A value witch curve fit better for a set of x,y
values, usually the set is about 20 to 25 x,y values.

I use the CurveFitter class and the ParametricUnivariateFunction

ParametricUnivariateFunction function = new  ParametricUnivariateFunction()
{

​  ​
@Override
​  ​
public double[] gradient(double x, double[] params) {
​
(????? comment)
​  ​
}

​  ​
@Override
​  ​
public double value(double x, double[] params) {

​    ​
double a = params[0];

​    ​
return Math.pow(10, ((x + 82) /
​(​
-10 *
​a
​)​
));

​  ​
}

};

LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();

CurveFitter<ParametricUnivariateFunction> fitter = new
CurveFitter<ParametricUnivariateFunction>(optimizer);

double[] x = {
-82
,
​-85
,
​-89
};

double[] y = {
​1
,
​1.4
,
​2
};

for (int i = 0; i < x.length; i++)
​  ​

double[] result = fitter.fit(function, new double[] { 1, 10 });

​A. ​Is this the best way to solve the problem or there's another better
way?

B. What do we need to write on the gradient area (????? comment) ?​

Any help will be more then welcome.

Many thanks !!

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