(03-10-2017 07:39 PM)tdh79 Wrote: [ -> ]I need to find polynomial functions from a given set of coordinates
You said it: there are infinitely many polynomial functions that may approximate the given data here. Question is: what do you want?
(03-10-2017 07:39 PM)tdh79 Wrote: [ -> ]Temperatures are measured 6 times during 24 hours:
time - temp (celsius)
0000 8
0400 5
0800 11
1200 16
1600 18
2000 14
There are essentially two different approaches:
1. From n=6 data points you can determine an (n–1) = 5th order polynomial that passes exactly through these six points. That's quite trivial since this is nothing more than solving a 6th order linear equation system. A piece of cake for the 50g. The required equations are simple:
1*a + t*b + t^2*c + t^3 * d + t^4 * e +t^5* f = temperature
Do this six times for every time (t) and temperature combination, solve for a...f.
This is the method proposed by Han in the second post.
2. You can approximate (!) a set of n datapoints by a polynomial regression function of order m < n–1. In your case you can approximate the six points by a polynomial of order 4, 3 or 2. The higher m, the better the match. This is also done by solving a linear equation system, the required equations are found in the respective Wikipedia article already mentioned here.
Example: fit a cubic function (m=3) through these six points. The result is:
temperature ~ 7,7143 – 1,5714 t + 0,3281 t² – 0,0117 t³
Note: t is not given as 800 or 1200 (does not make sense) but as 8 or 12.
Compare this approximation with the original data:
Code:
time temperature estimate
0 8 7,71
4 5 5,93
8 11 10,14
12 16 15,86
16 18 18,57
20 14 13,79
Using a 4th order polynomial, the results move closer to the original data. Here the result is:
temperature ~ 7,9643 – 2,4163 t + 0,6081 t² – 0,0345 t³ + 0,00057 t^4
Again compare this approximation with the original data...
Code:
time temperature estimate
0 8 7,96
4 5 5,18
8 11 10,64
12 16 16,36
16 18 17,82
20 14 14,04
...and the estimate already matches the original data when rounded to whole degrees. Finally a 5th order polynomial would exacly match the data (cf. Han's post).
Regarding Csaba Tizedes' remark: I would simply add a 7th data point for t=24 and temperature = 8 (same as for t=0). A periodic function is not required, simply apply the polynomial on (time mod 24). In this case a 6th order polynomial would result in a perfect fit, and 5th, 4th, 3rd... order approximations would come more or less close.
Dieter