I have a chart in excel that represents some value over a one day period. So I add the reference function and I get something like this:
y = 1E-13x6 - 2E-10x5 + 8E-08x4 - 1E-05x3 + 0,0004x2 + 0,0275x + 8,414
A mesure in my data set is:
09:36:21 => 5,27
The firts thing I need to know is how to transform the timestamp into a value to give to the function. After some cell value transforming I’ve found out that excel gives timestamps a representation between 0.00000 and 0.99999, so for example 09:36:21 is 0.400243055555556. Then I’ve coded a little java test script:
double x = 0.400243055555556;
double x6 = (1*Math.pow(10, -13))*Math.pow(x, 6);
double x5 = (2*Math.pow(10, -10))*Math.pow(x, 5);
double x4 = (8*Math.pow(10, -8))*Math.pow(x, 4);
double x3 = (1*Math.pow(10, -5))*Math.pow(x, 3);
double x2 = (4*Math.pow(10, -4))*Math.pow(x, 2);
double y = x6 - x5 + x4 - x3 + x2 + 0.0275*x + 8.414;
But after executing this script I get y = 8.425070122712738. So this is obviously not working. I must say that all the values in the chart range from 5 to 12.
I’m obviously doing something wrong, but I don’t know what. Maybe I’ve coded the function badly, or maybe the x I’m choosing is not a right value, but something is wrong. Can anyone help?
Update: My code wasn’t that good, what duffymo suggested worked better. But the problem was that Excel was giving my the wrong tendendy line. I’ve managed to get the good one using a scatter graph.
I would not recommend coding it this way – roundoff could be an issue.
I would recommend Horner scheme:
I coded it this way and got the same answer that you did:
Here’s the result I get. The higher order terms aren’t doing much good; the coefficients are small, and when you raise a fraction to a power it diminishes the effect even more.
Still not what you want, but I think the coding is far simpler.