~ubuntu-branches/ubuntu/trusty/gsl-ref-html/trusty

« back to all changes in this revision

Viewing changes to Monte-Carlo-Interface.html

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2006-04-12 19:46:32 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060412194632-c9lodpl075pv9si3
Tags: 1.8-1
* New upstream release 1.8
* As with previous releases, the sources were obtained from the FSF web 
  pages by means of a wget call (c.f. the debian/rules target 'upstream')

* debian/control: Standards-Version increased to 3.6.2
* debian/copyright: Updated FSF address
* debian/rules: Set DH_COMPAT=4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html lang="en">
 
2
<head>
 
3
<title>Monte Carlo Interface - GNU Scientific Library -- Reference Manual</title>
 
4
<meta http-equiv="Content-Type" content="text/html">
 
5
<meta name="description" content="GNU Scientific Library -- Reference Manual">
 
6
<meta name="generator" content="makeinfo 4.8">
 
7
<link title="Top" rel="start" href="index.html#Top">
 
8
<link rel="up" href="Monte-Carlo-Integration.html#Monte-Carlo-Integration" title="Monte Carlo Integration">
 
9
<link rel="next" href="PLAIN-Monte-Carlo.html#PLAIN-Monte-Carlo" title="PLAIN Monte Carlo">
 
10
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
 
11
<!--
 
12
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 The GSL Team.
 
13
 
 
14
Permission is granted to copy, distribute and/or modify this document
 
15
under the terms of the GNU Free Documentation License, Version 1.2 or
 
16
any later version published by the Free Software Foundation; with the
 
17
Invariant Sections being ``GNU General Public License'' and ``Free Software
 
18
Needs Free Documentation'', the Front-Cover text being ``A GNU Manual'',
 
19
and with the Back-Cover Text being (a) (see below).  A copy of the
 
20
license is included in the section entitled ``GNU Free Documentation
 
21
License''.
 
22
 
 
23
(a) The Back-Cover Text is: ``You have freedom to copy and modify this
 
24
GNU Manual, like GNU software.''-->
 
25
<meta http-equiv="Content-Style-Type" content="text/css">
 
26
<style type="text/css"><!--
 
27
  pre.display { font-family:inherit }
 
28
  pre.format  { font-family:inherit }
 
29
  pre.smalldisplay { font-family:inherit; font-size:smaller }
 
30
  pre.smallformat  { font-family:inherit; font-size:smaller }
 
31
  pre.smallexample { font-size:smaller }
 
32
  pre.smalllisp    { font-size:smaller }
 
33
  span.sc    { font-variant:small-caps }
 
34
  span.roman { font-family:serif; font-weight:normal; } 
 
35
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
 
36
--></style>
 
37
</head>
 
38
<body>
 
39
<div class="node">
 
40
<p>
 
41
<a name="Monte-Carlo-Interface"></a>
 
42
Next:&nbsp;<a rel="next" accesskey="n" href="PLAIN-Monte-Carlo.html#PLAIN-Monte-Carlo">PLAIN Monte Carlo</a>,
 
43
Up:&nbsp;<a rel="up" accesskey="u" href="Monte-Carlo-Integration.html#Monte-Carlo-Integration">Monte Carlo Integration</a>
 
44
<hr>
 
45
</div>
 
46
 
 
47
<h3 class="section">23.1 Interface</h3>
 
48
 
 
49
<p>All of the Monte Carlo integration routines use the same general form of
 
50
interface.  There is an allocator to allocate memory for control
 
51
variables and workspace, a routine to initialize those control
 
52
variables, the integrator itself, and a function to free the space when
 
53
done.
 
54
 
 
55
   <p>Each integration function requires a random number generator to be
 
56
supplied, and returns an estimate of the integral and its standard
 
57
deviation.  The accuracy of the result is determined by the number of
 
58
function calls specified by the user.  If a known level of accuracy is
 
59
required this can be achieved by calling the integrator several times
 
60
and averaging the individual results until the desired accuracy is
 
61
obtained.
 
62
 
 
63
   <p>Random sample points used within the Monte Carlo routines are always
 
64
chosen strictly within the integration region, so that endpoint
 
65
singularities are automatically avoided.
 
66
 
 
67
   <p>The function to be integrated has its own datatype, defined in the
 
68
header file <samp><span class="file">gsl_monte.h</span></samp>.
 
69
 
 
70
<div class="defun">
 
71
&mdash; Data Type: <b>gsl_monte_function</b><var><a name="index-gsl_005fmonte_005ffunction-1870"></a></var><br>
 
72
<blockquote>
 
73
<p>This data type defines a general function with parameters for Monte
 
74
Carlo integration.
 
75
 
 
76
          <dl>
 
77
<dt><code>double (* f) (double * </code><var>x</var><code>, size_t </code><var>dim</var><code>, void * </code><var>params</var><code>)</code><dd>this function should return the value
 
78
<!-- {$f(x,\hbox{\it params})$} -->
 
79
f(x,params) for the argument <var>x</var> and parameters <var>params</var>,
 
80
where <var>x</var> is an array of size <var>dim</var> giving the coordinates of
 
81
the point where the function is to be evaluated.
 
82
 
 
83
          <br><dt><code>size_t dim</code><dd>the number of dimensions for <var>x</var>.
 
84
 
 
85
          <br><dt><code>void * params</code><dd>a pointer to the parameters of the function. 
 
86
</dl>
 
87
        </p></blockquote></div>
 
88
 
 
89
<p class="noindent">Here is an example for a quadratic function in two dimensions,
 
90
with a = 3, b = 2, c = 1.  The following code
 
91
defines a <code>gsl_monte_function</code> <code>F</code> which you could pass to an
 
92
integrator:
 
93
 
 
94
<pre class="example">     struct my_f_params { double a; double b; double c; };
 
95
     
 
96
     double
 
97
     my_f (double x[], size_t dim, void * p) {
 
98
        struct my_f_params * fp = (struct my_f_params *)p;
 
99
     
 
100
        if (dim != 2)
 
101
           {
 
102
             fprintf (stderr, "error: dim != 2");
 
103
             abort ();
 
104
           }
 
105
     
 
106
        return  fp-&gt;a * x[0] * x[0]
 
107
                  + fp-&gt;b * x[0] * x[1]
 
108
                    + fp-&gt;c * x[1] * x[1];
 
109
     }
 
110
     
 
111
     gsl_monte_function F;
 
112
     struct my_f_params params = { 3.0, 2.0, 1.0 };
 
113
     
 
114
     F.f = &amp;my_f;
 
115
     F.dim = 2;
 
116
     F.params = &amp;params;
 
117
</pre>
 
118
   <p class="noindent">The function f(x) can be evaluated using the following macro,
 
119
 
 
120
<pre class="example">     #define GSL_MONTE_FN_EVAL(F,x)
 
121
         (*((F)-&gt;f))(x,(F)-&gt;dim,(F)-&gt;params)
 
122
</pre>
 
123
   </body></html>
 
124