source: Sophya/trunk/Cosmo/SimLSS/cmvtintfun.cc@ 3792

Last change on this file since 3792 was 3196, checked in by cmv, 18 years ago

les AGN selon C.Jackson, une premiere approche simplifiee, recodage from Jim Rich. cmv 03/04/2007

File size: 1.5 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <iostream>
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <math.h>
8#include <unistd.h>
9#include "timing.h"
10#include "ntuple.h"
11
12#include "geneutils.h"
13
14// cmvtintfun [n] [xmin,xmax,npt]
15
16class MyFunc : public GenericFunc {
17public:
18 MyFunc(double n) {n_=n;}
19 virtual ~MyFunc(void) {};
20 virtual double operator() (double x)
21 {return (n_>=0.) ? pow(x,n_) : exp(n_*x);}
22 double integ(double xmin,double xmax) {
23 return (n_>=0.) ? (pow(xmax,n_+1.)-pow(xmin,n_+1.))/(n_+1.)
24 : (exp(n_*xmax)-exp(n_*xmin))/n_;
25 }
26protected:
27 double n_;
28};
29
30
31int main(int narg,char *arg[])
32{
33
34 double n=3.;
35 if(narg>1) sscanf(arg[1],"%lf",&n);
36 double xmin=1., xmax=10.;
37 int npt = 100;
38 if(narg>2) sscanf(arg[2],"%lf,%lf,%d",&xmin,&xmax,&npt);
39
40 double lxmin=log10(xmin), lxmax=log10(xmax);
41 double perc=0.01;
42 double dxinc=(xmax-xmin)/npt, dxmax=-1.;
43 double dlxinc=(lxmax-lxmin)/npt, dlxmax=-1.;
44 unsigned short glorder=4;
45
46 if(narg>1) sscanf(arg[1],"%lf",&n);
47 if(narg>2) sscanf(arg[2],"%lf,%lf,%d",&xmin,&xmax,&npt);
48 cout<<"n="<<n<<" xmin="<<xmin<<" xmax="<<xmax<<" npt="<<npt<<endl;
49
50 MyFunc myfunc(n);
51
52 double integ = IntegrateFunc(myfunc,xmin,xmax,perc,dxinc,dxmax,glorder);
53 cout<<"IntegrateFunc() = "<<integ<<endl;
54
55 double integlog = IntegrateFuncLog(myfunc,lxmin,lxmax,perc,dlxinc,dlxmax,glorder);
56 cout<<"IntegrateFuncLog() = "<<integlog<<endl;
57
58 cout<<"Integrate() = "<<myfunc.integ(xmin,xmax)<<endl;
59
60 return 0;
61}
Note: See TracBrowser for help on using the repository browser.