commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mat Jaggard <matt...@jaggard.org.uk>
Subject Re: [Math] Unable to fit a polynomial to data points correctly.
Date Wed, 08 Aug 2012 12:50:36 GMT
Really? I think I must be missing something. When I plot them in excel
I get the attached results...


On 8 August 2012 13:23, Gilles Sadowski <gilles@harfang.homelinux.org> wrote:
> On Tue, Aug 07, 2012 at 11:59:09PM +0100, Mat Jaggard wrote:
>> I have tried to create a polynomial that fits some data using the
>> following code:
>>
>>                 PolynomialFitter fitter = new PolynomialFitter(14, new
>> GaussNewtonOptimizer());
>>                 for (int i = 0; i < numValues; i++)
>>                 {
>>                         fitter.addObservedPoint(xValues[i], yValues[i]);
>>                 }
>>                 return new PolynomialFunction(fitter.fit());
>>
>> I've also tried using a degree of 4. In both cases and using both a
>> GaussNewtonOptimizer and a LevenbergMarquardtOptimizer, I'm able to
>> get a straight line to be fitted correctly, but the following data
>> results with a constant value but very small multipliers for x, and
>> higher orders.
>>
>> Is anyone able to let me know why this is happening and what I can do about
>> it?
>>
>> Many thanks,
>> Mat.
>>
>> The result I get is...
>> y = 110.281064 + 0.002316943x - 3.86E-09x^2 + 4.01E-15x^3 - 1.58E-21x^4
>>
>> From this data:
>>
>> [...]
>
> Plotting those data, and the above polynomial shows that Commons Math did a
> decent job. What led you to think that the fit is not correct?
> [Maybe the data could be better fitted with another function...]
>
>
> Regards,
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


Mime
View raw message