#!/usr/bin/env perl
# Take a numerical derivative of a function represented as a table;
# return the result in the form of a "local power",
# i.e. we compute x(f'/f), i.e. the logarithmic derivative muplitied by x.
# Rok Zitko, rok.zitko@ijs.si, May 2008
# $Id$

my ($prevx, $prevy);
my $cnt = 0;

while (<>) {
  chomp;
  my @d = split;
  my $x = $d[0];
  my $y = $d[1];
  
  if ($cnt != 0) {
    my $derivative = ($y - $prevy)/($x - $prevx);
    my $yavg = ($y + $prevy)/2.0;
    if ($yavg != 0) {
      my $logderivative = $derivative/$yavg;
      my $xavg = ($x + $prevx)/2.0;
      my $power = $logderivative * $xavg;
    
      print "$xavg $power\n";
    }
  }
  
  $prevx = $x;
  $prevy = $y;
  $cnt++;
}
