File: MROOT.pm

package info (click to toggle)
libpdl-gsl-perl 2.101-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 600 kB
  • sloc: perl: 1,587; ansic: 202; makefile: 9
file content (164 lines) | stat: -rw-r--r-- 3,885 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#
# GENERATED WITH PDL::PP from lib/PDL/GSL/MROOT.pd! Don't modify!
#
package PDL::GSL::MROOT;

our @EXPORT_OK = qw(gslmroot_fsolver gslmroot_fsolver );
our %EXPORT_TAGS = (Func=>\@EXPORT_OK);

use PDL::Core;
use PDL::Exporter;
use DynaLoader;


   
   our @ISA = ( 'PDL::Exporter','DynaLoader' );
   push @PDL::Core::PP, __PACKAGE__;
   bootstrap PDL::GSL::MROOT ;







#line 72 "lib/PDL/GSL/MROOT.pd"

use strict;
use warnings;

=head1 NAME

PDL::GSL::MROOT - PDL interface to multidimensional root-finding routines in GSL

=head1 DESCRIPTION

This is an interface to the multidimensional root-finding package present in the
GNU Scientific Library.

At the moment there is a single function B<gslmroot_fsolver> which provides an interface
to the algorithms in the GSL library that do not use derivatives.

=head1 SYNOPSIS

   use PDL;
   use PDL::GSL::MROOT;

   my $init = pdl (-10.00, -5.0);
   my $epsabs = 1e-7;

  $res = gslmroot_fsolver($init, \&rosenbrock,
                          {Method => 0, EpsAbs => $epsabs});

  sub rosenbrock{
     my ($x) = @_;
     my $c = 1;
     my $d = 10;
     my $y = zeroes($x);

     my $y0 = $y->slice(0);
     $y0 .=  $c * (1 - $x->slice(0));

     my $y1 = $y->slice(1);
     $y1 .=  $d * ($x->slice(1) - $x->slice(0)**2);

     return $y;
  }
#line 68 "lib/PDL/GSL/MROOT.pm"


=head1 FUNCTIONS

=cut






=head2 gslmroot_fsolver

=for sig

  Signature: (double [io]xfree(n);   double epsabs(); int method(); SV* function1)

=for ref

Multidimensional root finder without using derivatives

This function provides an interface to the multidimensional root finding algorithms
in the GSL library. It takes a minimum of two arguments: an ndarray $init with an
initial guess for the roots of the system and a reference to a function. The latter
function must return an ndarray whose i-th element is the i-th equation evaluated at
the vector x (an ndarray which is the sole input to this function). See the example in
the Synopsis above for an illustration. The function returns an ndarray with the roots
for the system of equations.

Two optional arguments can be specified as shown below. One is B<Method>, which can
take the values 0,1,2,3. They correspond to the 'hybrids', 'hybrid', 'dnewton' and
'broyden' algorithms respectively (see GSL documentation for details). The other
optional argument is B<Epsabs>, which sets the absolute accuracy to which the roots
of the system of equations are required. The default value for Method is 0 ('hybrids'
algorithm) and the default for Epsabs is 1e-3.

=for usage

   $res = gslmroot_fsolver($init, $function_ref,
                           [{Method => $method, Epsabs => $epsabs}]);

=for bad

gslmroot_fsolver does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

=cut




sub gslmroot_fsolver {
	my ($x, $f_vect) = @_;
        my $opt = ref($_[-1]) eq 'HASH' ? pop @_ : {Method => 0, EpsAbs => 1e-3};
        if( (ref($x) ne 'PDL')){
           barf("Have to pass ndarray as first argument to fsolver\n");
        }
	my $res = $x->copy;
	_gslmroot_fsolver_int($res, $$opt{'EpsAbs'}, $$opt{'Method'}, $f_vect);
	return $res;
}



*gslmroot_fsolver = \&PDL::GSL::MROOT::gslmroot_fsolver;







#line 118 "lib/PDL/GSL/MROOT.pd"

=head1 SEE ALSO

L<PDL>

The GSL documentation is online at

  http://www.gnu.org/software/gsl/manual/

=head1 AUTHOR

This file copyright (C) 2006 Andres Jordan <ajordan@eso.org>
and Simon Casassus <simon@das.uchile.cl>
All rights reserved. There is no warranty. You are allowed to redistribute this
software/documentation under certain conditions. For details, see the file
COPYING in the PDL distribution. If this file is separated from the
PDL distribution, the copyright notice should be included in the file.

=cut
#line 161 "lib/PDL/GSL/MROOT.pm"

# Exit with OK status

1;