Hi Dmitri and All,
I agree that polyfit may not need to be replaced, but from what I have seen
playing with it is that it probably a) needs to be fixed for fits of 5th
order and higher or b) limited to 4th order and lower
I believe there very well may be an actual bug in the implementation for 5th
order and higher fits.
The thermistor example is not all I have used the pivot-row based algorithm
for over the years. It always seems to do a good job for me. You are
right that for someone like me, the fact that it works is the most
important thing. btw, here is an example of a highly respected Scientific
measurement company that also used a 5th order polyfit for a thermistor
www.campbellsci.com/documents/manuals/107-lc.pdf They may have also used a
pivot-row based algorithm since their fit looks a lot like the fit
betterpolyfit would produce... or maybe polyfit and wpolyfit are broken for
a 5th order fit? In practice, I use a 5th order fit with a slightly
reduced temperature range compared to this to get a very nice fit with
minimal error due to the nature of a polynomial function. This can easily
be implemented in an 8-bit embedded system for highly accurate temperature
measurements using thermistors.
I have plotted the (data-fit) and the result as I mentioned in my original
post was that the betterpolyfit produced error several (3-4 times) orders of
magnitude less than the original polyfit function. As for plotting
residuals, and histograms, I'm afraid I will be leaving that for someone
else to do. I have an intuitive feeling that you will find the pivot-row
algorithm will come out on top every time.... possibly at the expense of a
few more computation cycles while generating your coefficients? (still
less than one second on my machine).
I have placed the temp_c, resistance, mv file here
http://www.hanfordsite.com/testing/thermistor.csv for reference in relation
to the polyfit_testing.pdf document.
Also, I have added some headers stating where the original source and
adaptation came from with the betterpolyfit function here
http://www.hanfordsite.com/testing/betterpolyfit.zip As stated in the
source, as far as I know and am concerned, there are no restrictions
whatsoever to this function.
Unless there is a compelling response to continue, I think I will probably
just leave this issue as it is. Hopefully someone else will also find
this function useful as I have.
Thanks,
Todd
Post by Dmitri A. SergatskovPost by Todd ElliottHi Dmitri,
Thanks for the info on the Steinhart equation. I have played around
with
Post by Todd Elliottit, but I find that with betterpolyfit I can get a much better fit than
with
Post by Todd Elliottthe "standard" way of doing it. Using betterpolyfit, I can get the
max
Post by Todd Elliotterror down to 0.05 degrees. I have heard others say "that doesn't
look
Post by Todd Elliottpolynomial" or "too high of an order" before, but what does that mean?
If you can get a better fit over the entire range with a polynomial
equation, then why not?
Technically speaking you can plot n-1 degree polynomial
that will go exactly through n points, yet it would not
necessary make a good fit.
Try to plot (data - fit)
curve, or try to plot derivative of the fit -- I bet those
would look ugly (if you want to be more scientific --
plot a histogram of the residuals, -- does it look gaussian ?).
Post by Todd ElliottAlso, what do you mean it will break later? Can you give me an
example?
No. What am saying is that fitting polynomial in the form of
sum by i of a_i * x^n-i
is numerically unstable for high n. While there are ways to
mitigate those instabilities, the better way is to fit
to a set of orthogonal functions.
But at the end it is all is what works for you. I just do not
think (at least not yet) that polyfit function in octave
have to be replaced.
Sincerely,
Dmitri.
--
--
A VTOL Project in my spare time
http://www.hanfordsite.com/
(some images from WWJ code I have been working on)
http://picasaweb.google.com/tve9999/WorldWindJavaImages/photo#s5093635840816720994