~ubuntu-branches/ubuntu/lucid/pdl/lucid

« back to all changes in this revision

Viewing changes to Example/Simplex/tsimp.pl

  • Committer: Bazaar Package Importer
  • Author(s): Ben Gertzfield
  • Date: 2002-04-08 18:47:16 UTC
  • Revision ID: james.westby@ubuntu.com-20020408184716-0hf64dc96kin3htp
Tags: upstream-2.3.2
ImportĀ upstreamĀ versionĀ 2.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#use blib;
 
2
use PDL;
 
3
use PDL::Primitive;
 
4
use PDL::Graphics::PGPLOT;
 
5
use PDL::Opt::Simplex;
 
6
 
 
7
use Carp;
 
8
 
 
9
$SIG{__DIE__} = sub {print Carp::longmess(@_); die FOO};
 
10
 
 
11
# First, a 1-dimensional test:
 
12
 
 
13
sub func1 {
 
14
        my($x) = @_;
 
15
        return ($x**2)->slice('(0)');
 
16
}
 
17
 
 
18
sub logs1 {
 
19
        print "NOW: $_[0],$_[1]\n\n";
 
20
}
 
21
simplex(ones(1)*10,0.3,0.01,15,\&func1,\&logs1);
 
22
 
 
23
# Try a simple ellipsoid:
 
24
 
 
25
my $mult = pdl 4,1;
 
26
 
 
27
dev "/XSERVE";
 
28
env -15,5,-15,5;
 
29
hold;
 
30
 
 
31
sub func {
 
32
        my($x) = @_;
 
33
        my $b = ($mult * $x) ** 2;
 
34
        sumover($b,(my $res = null));
 
35
        $res;
 
36
}
 
37
 
 
38
sub logs {
 
39
        print "NOW: $_[0],$_[1]\n\n";
 
40
        line($_[0]->slice("(0)"),$_[0]->slice("(1)"));
 
41
        line($_[0]->slice("(0),0:2:2"),$_[0]->slice("(1),0:2:2"));
 
42
}
 
43
 
 
44
simplex(pdl(-10,-10), 0.5, 0.01, 30,
 
45
        \&func,
 
46
        \&logs
 
47
);
 
48
 
 
49
 
 
50