File: poly.t

package info (click to toggle)
pdl 1%3A2.4.7%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,128 kB
  • ctags: 5,821
  • sloc: perl: 26,328; fortran: 13,113; ansic: 9,378; makefile: 71; sh: 50; sed: 6
file content (44 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use PDL::LiteF;
BEGIN {
        eval " use PDL::Fit::Polynomial; ";
        $loaded = ($@ ? 0 : 1);
}


kill INT,$$ if $ENV{UNDER_DEBUGGER}; # Useful for debugging.
print "1..1\n";

unless ($loaded) {
        for (1..1) {
                print "ok $_ # Skipped: probably PDL::Slatec not available.\n";
        }
        exit;
}

sub ok {
        my $no = shift ;
        my $result = shift ;
        print "not " unless $result ;
        print "ok $no\n" ;
}

$x = sequence(20)-10;
$y = 30-2*$x+3*$x**2-2*$x**3;

# Random numbers, generated by  grandom($y)*100
# Hard-wired to avoid OS seed variations barfing test

$rand = pdl qw/65.735917 -40.510143 -122.07767 -19.591344 -139.76362  
106.44639 -0.30094068 -5.3129683  49.815455  97.247868 -9.3130775  
19.585472  8.5260268 -194.49596  73.822799  25.628967  133.36015 -2.6611465  
9.0335632 -0.82946383/;

$y += $rand;

#points $x,$y;

$yfit = fitpoly1d($x,$y,4);

#hold; line $x, $yfit;

ok(1, max(abs($y-$yfit)) < 220); # need to add 10 for windows