Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Perl to count current value based on next value

  1. #11
    iMac71 is offline Gee! These Aren't Roasted!
    Join Date
    Dec 2012
    Beans
    171

    Re: Perl to count current value based on next value

    Quote Originally Posted by Vaphell View Post
    assuming linear interpolation
    I think that the point be exactly this one: is the interpolation linear or not?
    I guess not, because otherwise the algorithm would be very simple; but if the interpolation isn't linear, the unknown values would be unpredictable without more informations about their sequence.

  2. #12

    Re: Perl to count current value based on next value

    The formula OP gave is just linear interpolation when you know y[n-1] and y[n+1] and have to find y[n]. (Actually in that particular case it simplifies greatly, but you need the general formula to interpolate with a gap of 2 or more.)

  3. #13
    Join Date
    Feb 2011
    Beans
    35

    Re: Perl to count current value based on next value

    Quote Originally Posted by Tony Flury View Post
    This is almost exactly the same problem as this thread :

    http://ubuntuforums.org/showthread.php?t=2103750

    and this one :

    http://ubuntuforums.org/showthread.php?t=2103383

    The first one is marked as solved.

    One of the arts of programming is re-use - so adapt the solution previously provided.
    They are not the same...

  4. #14
    Join Date
    Feb 2011
    Beans
    35

    Re: Perl to count current value based on next value

    Quote Originally Posted by iMac71 View Post
    I think that the point be exactly this one: is the interpolation linear or not?
    I guess not, because otherwise the algorithm would be very simple; but if the interpolation isn't linear, the unknown values would be unpredictable without more informations about their sequence.
    It is linear which based on two points.

  5. #15
    Join Date
    Feb 2011
    Beans
    35

    Re: Perl to count current value based on next value

    Quote Originally Posted by trent.josephsen View Post
    The formula OP gave is just linear interpolation when you know y[n-1] and y[n+1] and have to find y[n]. (Actually in that particular case it simplifies greatly, but you need the general formula to interpolate with a gap of 2 or more.)
    Correct

  6. #16
    iMac71 is offline Gee! These Aren't Roasted!
    Join Date
    Dec 2012
    Beans
    171

    Re: Perl to count current value based on next value

    the following script might be what you're looking for:
    PHP Code:
    my $loop 1;

    while (<>)
    {
        
    my $delta_x$x_i$y_i$x_k$y_k;
        if (
    $loop == 1) {
            (
    $x_i$y_i$x_k$y_k) = split
        
    }
        else {
            (
    $x_i$y_i) = ($x_k$y_k);
            (
    $x_k$y_k) = split
        
    }
        
    $delta_x = ($x_k $x_i) / 2;
        
    my $x_j $x_i $delta_x;
        
    my $y_j = (($x_j $x_k) / ($x_i $x_k)) * $y_i + (($x_j $x_i) / ($x_k $x_i)) * $y_k;
        print 
    $x_i,"\t",$y_i,"\n(",$x_j,")\t(",$y_j,")\n";
        
    $loop++;

    when you run the script, the data should be entered as follows:
    - first input line: two couples of coordinates (i.e. two points);
    - next input lines: a couple of coordinates (i.e. one point).
    Last edited by iMac71; January 18th, 2013 at 10:10 PM. Reason: Insertion of $delta_x as the difference between two non consecutive values of x

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •