help-octave
[Top][All Lists]

## polyfit problem?

 From: Haisam K. Ido Subject: polyfit problem? Date: Tue, 16 Mar 1999 22:02:56 +0000 (GMT)

```When I use octave to get a 9th degree polynomial for xy below, via
polyfit I get very strange coefficients, while when I use gnuplot's fit
capability on the same data I get reasonable coefficients.  I have
enclosed the *.m file and its output and the gnuplot calls.  I am using
Octave, version 2.0.13 (i686-pc-linux-gnu) and gnuplot Linux version 3.5
(pre 3.6).  Why is this happening?

Octave:
------

format long;

xy = [ 121.45, 0.00482;
65.01, -0.02255;
10.22, -0.00868;
316.28, -0.00524;
262.02, -0.01249;
207.25, -0.01086;
152.47, 0.00172;
98.96, 0.00063;
43.46, -0.01849;
346.99, -0.00166;
293.78, 0.00226;
240.28, -0.01598;
186.25, -0.00506;
129.48, 0.00282;
74.97, -0.01459;
19.25, -0.01225 ]

polyfit( xy(:,1), xy(:,2), 9)

Octave results:
--------------
warning: matrix singular to machine precision, rcond = 4.86298e-48
ans =

-3.42177255249508e-23
2.24685068543842e-20
-3.68064283803191e-18
-3.82644066001161e-20
-2.68657546731279e-22
-1.59579705833446e-24
-8.68469491229232e-27
-4.78345278952551e-29
1.96567339973953e-26
-1.15740058325638e-33

Gnuplot:
-------

> f(x)= a0*x**0 + a1*x**1 + a2*x**2 + a3*x**3 + a4*x**4 + a5*x**5 + \
a6*x**6 + a7*x**7 + a8*x**8 + a9*x**9

> fit f(x) "data.dat" u 1:2 via  a0,a1,a2,a3,a4,a5,a6,a7,a8,a9

data.dat is enclosed below

Gnuplot results:
---------------

After 19 iterations the fit converged.
final sum of squares residuals    : 4.84396e-05
rel. change during last iteration : -1.18478e-08

Final set of parameters            68.3% confidence interval (one at
a time)
================================================================

a0              = -0.0298914       +/- 0.00959086      (32.0857%)
a1              = 0.00378069       +/- 0.00134668      (35.6199%)
a2              = -0.000227014     +/- 6.3822e-05      (28.1137%)
a3              = 5.6012e-06       +/- 1.46383e-06     (26.1341%)
a4              = -7.20517e-08     +/- 1.86935e-08     (25.9446%)
a5              = 5.42903e-10      +/- 1.4199e-10      (26.1538%)
a6              = -2.49508e-12     +/- 6.55753e-13     (26.2818%)
a7              = 6.8849e-15       +/- 1.80497e-15     (26.2163%)
a8              = -1.04678e-17     +/- 2.72024e-18     (25.9868%)
a9              = 6.72836e-21      +/- 1.72641e-21     (25.6587%)

data.dat:
--------

121.45  0.00482
65.01   -0.02255
10.22   -0.00868
316.28  -0.00524
262.02  -0.01249
207.25  -0.01086
152.47  0.00172
98.96   0.00063
43.46   -0.01849
346.99  -0.00166
293.78  0.00226
240.28  -0.01598
186.25  -0.00506
129.48  0.00282
74.97   -0.01459
19.25   -0.01225

```