]> www.ginac.de Git - ginac.git/blob - doc/examples/compile1.cpp
Patches by Vladimir.
[ginac.git] / doc / examples / compile1.cpp
1 #include <iostream>
2 using namespace std;
3 #include <ginac/ginac.h>
4 using namespace GiNaC;
5 // Yes, we are using CUBA (should be installed on the system!)
6 #include "cuba.h"
7
8 int main()
9 {
10         // Let the user enter a expression
11         symbol x("x"), y("y");
12         string s;
13         cout << "Enter an expression containing 'x' and/or 'y': ";
14         cin >> s;
15         // Expression now in expr
16         ex expr(s, lst(x,y));
17  
18         cout << "start integration of " << expr << " ..." << endl;
19
20         // Some definitions for VEGAS 
21         #define NDIM 2
22         #define NCOMP 1
23         #define EPSREL 1e-3
24         #define EPSABS 1e-12
25         #define VERBOSE 0
26         #define MINEVAL 0
27         #define MAXEVAL 50000
28         #define NSTART 1000
29         #define NINCREASE 500
30
31         // Some variables for VEGAS
32         int comp, nregions, neval, fail;
33         double integral[NCOMP], error[NCOMP], prob[NCOMP];
34
35         // Starting VEGAS
36         // By invocation of compile() the expression in expr is converted into the
37         // appropriate function pointer
38         Vegas(NDIM, NCOMP, compile(lst(expr), lst(x,y)), EPSREL, EPSABS, VERBOSE,
39               MINEVAL, MAXEVAL, NSTART, NINCREASE, &neval, &fail, integral, error, prob);
40
41         // Show the result
42         cout << "result: " << integral[0] << endl;
43
44         return 0;
45 }