|
From: | Ben Abbott |
Subject: | Re: Polyfit with scaling |
Date: | Thu, 31 Jan 2008 21:26:18 -0500 |
On Jan 31, 2008, at 3:08 PM, Thomas Weber wrote: On 31/01/08 07:47 -0500, Ben Abbott wrote:It doesn't appear that the example has much comparative value. ? hmmm ... I agree we should use the better algorithm. In any event, I've modified polyfit.m to optionally use the method employed by wpolyfit. To do this; I wrote two new scripts. One to offset a polynomial's dependent variable (polyshift), and one to scale a polynomial's dependent variable (polyscale). Below I compared the present version of polyfit to the one attached to this email. octave:1> x = 1:4; octave:2> y = polyval ([1, 1, 1], x); octave:3> polyfit (x, y, 2) ans = 1.00000 1.00000 1.00000 octave:4> polyfit (x, y, 2, 1) ans = 1.00000 1.00000 1.00000 octave:5> polyfit (x, y, 3) ans = 0 1 1 1 octave:6> polyfit (x, y, 3, 1) ans = 5.2633e-16 1.0000e+00 1.0000e+00 1.0000e+00 octave:7> polyfit (x, y, 4) ans = -0.0020445 0.0204453 0.9284416 1.1022263 0.9509314 octave:8> p = polyfit (x, y, 4, 1) p = -5.0886 50.8856 -177.0996 255.4281 -121.1255 octave:9> polyval (p, x) ans = 3.0000 7.0000 13.0000 21.0000 octave:10> polyval ([1, 1, 1], x) ans = 3 7 13 21 Comparing to Matlab ... >> x = 1:4; >> y = polyval([1, 1, 1], x); >> polyfit(x, y, 2) ans = 1.0000 1.0000 1.0000 >> polyfit(x, y, 3) ans = 0.0000 1.0000 1.0000 1.0000 >> polyfit(x, y, 4) Warning: Polynomial is not unique; degree >= number of data points. > In polyfit at 72 ans = 0.0200 -0.2000 1.7000 0 1.4800 The offset and scaling appears to significantly modify the result when the order of the fit exceeds to order of the original polynomial. I am not an expert in such matters. How might we quantitatively determine which algorithm is best? I've attached the modified polyfit.m as well as the two new scripts it relies upon. Perhaps it is worth the effort for others to compare their results with mine, and to compare Matlab's results on a computer other than an Intel/ppc based Mac (each gave the same result). Ben |
polyfit.m
Description: Binary data
polyscale.m
Description: Binary data
polyshift.m
Description: Binary data
[Prev in Thread] | Current Thread | [Next in Thread] |