Interpolation isn't probably relevant in this case. Bestfit curve (or approximation) which Abigail mentions is.
This is why: we want averages (read: good, useful values) in arbitrary Xs, while interpolation produces a function which will exactly evaluate to those Ys from those Xs we used as data for interpolation. Nothing said about Xs between original datapoints, they can be anything. Think of a sine wave which perfectly interpolates points (0, 0), (pi, 0), ..., (n*pi, 0).
Approximation minimizes distance between the curve and each of the datapoints (the datacloud) to produce exactly what you want: a function to calculate useful value in any point of the X axis.
Give Math::Approx a try. Like this:
my %data = (
mins_from_midnight('07:01') => 82,
mins_from_midnight('23:48') => 188,
# ...
);
my $approx = Math::Approx->new(undef, 3, %data);
print $approx->approx(mins_from_midnight('15:40'));
Update: and yes, the day you took a specific datapoint does not matter. Anyway, you want average and that means all the days are the same for your task. That's ok.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.