[system] / trunk / pg / macros / PGanalyzeGraph.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/PGanalyzeGraph.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6545 - (download) (as text) (annotate)
Sun Nov 21 03:42:29 2010 UTC (9 years, 2 months ago) by gage
File size: 2447 byte(s)
updated POD documentation


    1 sub _PGanalyzeGraph_init {}
    2 
    3 ################################################################
    4 # subroutines
    5 ################################################################
    6 
    7 =head1 NAME
    8 
    9 PGanalyzeGraph.pl
   10 
   11 =head1 DESCRIPTION
   12 
   13 These routines support the
   14 analysis of  graphical input from students.
   15 
   16 =cut
   17 
   18 
   19 =head4  detect_intervals
   20 
   21 
   22 
   23    input:   $pointDisplayString
   24 
   25    return: (\@combined_intervals, \@values)
   26            @values contains the y values of the function in order
   27            @combined_intervals contains anonymous arrays of the form
   28                [ $slope, $left_x, $right_x]  indicating the gradient on that segment.
   29                successive intervals will have different slopes.
   30 
   31 
   32 =cut
   33 
   34 
   35 
   36 sub detect_intervals {
   37   my $pointDisplayString = shift;
   38   my @intervals;
   39   my @combined_intervals=();
   40   my @points;
   41   my @values;
   42   $out_string ='';
   43   return "" unless defined $pointDisplayString and $pointDisplayString =~/\S/;
   44   @pointDisplayLines = split("\n",$pointDisplayString);
   45   #drop first line
   46   #shift @pointDisplayLines;
   47   my ($prev_x, $prev_y, $prev_yp) = (undef);
   48   my $slope;
   49 
   50     #first calculate the average gradient on each interval
   51 
   52   foreach my $line (@pointDisplayLines) {
   53       chomp($line);
   54       next unless $line =~/\S/;  # skip blank lines
   55       ($x,$y,$yp) = split(/\s+/, $line);
   56 
   57       if (defined $prev_x) {
   58          $slope = $y - $prev_y;
   59 
   60       if ($slope >0) {
   61         $slope_str="increasing";
   62       } elsif ($slope <0) {
   63         $slope_str="decreasing";
   64       } else {
   65         $slope_str = "constant";
   66       }
   67       push @intervals, [$slope_str, $prev_x, $x];
   68 
   69       #TEXT("f is $slope_str on the interval [$prev_x, $x]$BR");
   70     }
   71     #TEXT("x=$x y = $y yp = $yp $BR");
   72     push @points, [$x, $y, $yp];
   73     push @values, $y;
   74     $prev_x =$x; $prev_y=$y; $prev_yp = $yp;
   75 
   76   }
   77   my $prev_slope = undef;
   78   my ($left_x, $right_x);
   79 
   80   ########
   81   # Combine adjacent intervals with the same properites
   82   ########
   83   foreach my $item (@intervals) {
   84     if (defined $prev_slope) {
   85       if ($prev_slope eq $item->[0]) {
   86         $right_x = $item->[2];
   87       } else {
   88         push @combined_intervals, [$prev_slope, $left_x, $right_x];
   89         $left_x = $item->[1];
   90         $right_x = $item->[2];
   91       }
   92 
   93     } else {
   94       $left_x = $item->[1];
   95       $right_x = $item->[2];
   96     }
   97     $prev_slope = $item->[0];
   98     # warn "intervals",join(" ", @combined_intervals);
   99   }
  100   push @combined_intervals, [$prev_slope, $left_x, $right_x];
  101 
  102   (\@combined_intervals, \@values);
  103 }
  104 
  105 
  106 
  107 
  108 
  109 
  110 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9