# [math] Curve fitting ...

9 messages
Open this post in threaded view
|

## [math] Curve fitting ...

 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 fitter = new CurveFitter(optimizer); double[] x = { -82 , ​-85 , ​-89  }; double[] y = { ​1 , ​1.4 , ​2  }; for (int i = 0; i < x.length; i++) ​  ​ fitter.addObservedPoint(x[i], y[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 !!
Open this post in threaded view
|

## Re: [math] Curve fitting ...

 Have you considered using an interactive system like R, Matlab or Octave? You might be happier. Or even have you considered goal search in Excel? On Wed, Aug 13, 2014 at 6:08 PM, South Light <[hidden email]> wrote: > 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 fitter = new > CurveFitter(optimizer); > > double[] x = { > -82 > , > ​-85 > , > ​-89 >  }; > > double[] y = { > ​1 > , > ​1.4 > , > ​2 >  }; > > for (int i = 0; i < x.length; i++) > ​  ​ > fitter.addObservedPoint(x[i], y[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 !! >
Open this post in threaded view
|

## Re: [math] Curve fitting ...

 In reply to this post by South Light On Wed, 13 Aug 2014 22:08:39 -0300, South Light wrote: > 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 The "CurveFitter" class is deprecated. Please use "AbstractCurveFitter" instead. Best regards, Gilles > [...] --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email]
Open this post in threaded view
|

## Re: [math] Curve fitting ...

 In reply to this post by Ted Dunning Hi Ted, Thanks a lot for your suggestion but I need to add it using java. Thanks ​again​ .​ 2014-08-14 2:22 GMT-03:00 Ted Dunning <[hidden email]>: > Have you considered using an interactive system like R, Matlab or Octave? > > You might be happier. > > Or even have you considered goal search in Excel? > > > > > On Wed, Aug 13, 2014 at 6:08 PM, South Light <[hidden email]> > wrote: > > > 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 fitter = new > > CurveFitter(optimizer); > > > > double[] x = { > > -82 > > , > > ​-85 > > , > > ​-89 > >  }; > > > > double[] y = { > > ​1 > > , > > ​1.4 > > , > > ​2 > >  }; > > > > for (int i = 0; i < x.length; i++) > > ​  ​ > > fitter.addObservedPoint(x[i], y[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 !! > > >
Open this post in threaded view
|

## Re: [math] Curve fitting ...

 In reply to this post by Gilles Sadowski Hi Gilles ​, Can you tell me which is the best subclass from AbstractCurveFitter to fit better to the problem ? Thanks a lot . 2014-08-14 6:33 GMT-03:00 Gilles <[hidden email]>: > On Wed, 13 Aug 2014 22:08:39 -0300, South Light wrote: > >> 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 >> > > The "CurveFitter" class is deprecated. > Please use "AbstractCurveFitter" instead. > > > Best regards, > Gilles > >  [...] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > >
Open this post in threaded view
|

## Re: [math] Curve fitting ...

Open this post in threaded view
|