{laugh} Excel would be a bit of overkill, but thank you for the suggestion. As far as the progress goes, it hasn't even been all that difficult: I've simply been experimenting with what it's like to feel different degrees of hunger, just being curious about it. I realized that it's been years since I've actually felt hungry (yeah... sounds crazy, I know), and I know that it won't kill me to experience it. As a side benefit, food now tastes absolutely amazing, and I get really full on a dollar's worth of salad greens. It feels fantastic.
Regarding your code: bravo! That's pretty much what I was looking for - it's very readable, and the algorithm even makes sense to me. I've been playing around with my own code in the meantime, and came up with something more-or-less similar (except I handle the _end_ case as the special one.)
use POSIX qw/strftime/; use strict; $|++; use constant Intervals => 20; my ($prev_time, $prev_val, $tmin, $tmax, $last_val, @curve); open my $data, "weightdata.txt" or die "weightdata.txt: $!\n"; while (<$data>){ chomp; next unless m{^\s*([\d/]+)\s+([\d.]+)}; my($m, $d, $y) = split /\//, $1; my $time_point = strftime("%s", 0, 0, 0, $d, $m - 1, $y - 1900); if (defined $prev_time){ my $slope = ($2 - $prev_val) / ($time_point - $prev_time); push @curve, [ $prev_time, $time_point, $prev_val, $slope ]; } ($prev_time, $prev_val) = ($time_point, $2); ($tmax, $last_val) = ($time_point, $2); } close $data; $tmin = $curve[0][0]; my $interval = ($tmax - $tmin) / (Intervals - 1); my ($prev_t, $val, $slope); for my $t (0 .. Intervals - 2){ my $calc_t = $t * $interval + $tmin; shift @curve unless $calc_t >= $curve[0][0] && $calc_t <= $curve[0 +][1]; ($prev_t, $val, $slope) = @{$curve[0]}[0, 2, 3]; printf "%2d: Weight on %s was %.1f\n", $t + 1, strftime("%F",local +time($calc_t)), ($calc_t - $prev_t) * $slope + $val; } printf "%2d: Weight on %s was %.1f\n", Intervals, strftime("%F",localt +ime($tmax)), $last_val;
I've even looked at the intervals carefully - they're consistent - and the change in weight from one plotted point to another (yep, looks right.) I just might be getting the hang of this process. :)
Thanks very much for your response; I'm definitely finding all this highly educational.
In reply to Re^2: Interpolating data slope for multiple points
by oko1
in thread Interpolating data slope for multiple points
by oko1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |