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

Last change on this file since 3947 was 3805, checked in by cmv, 15 years ago

Refonte totale de la structure des classes InitialSpectrum, TransfertFunction, GrowthFactor, PkSpectrum et classes tabulate pour lecture des fichiers CAMB, cmv 24/07/2010

File size: 1.4 KB
RevLine 
[3115]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
[3196]12#include "geneutils.h"
[3115]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 cout<<"n="<<n<<" xmin="<<xmin<<" xmax="<<xmax<<" npt="<<npt<<endl;
47
48 MyFunc myfunc(n);
49
50 double integ = IntegrateFunc(myfunc,xmin,xmax,perc,dxinc,dxmax,glorder);
51 cout<<"IntegrateFunc() = "<<integ<<endl;
52
53 double integlog = IntegrateFuncLog(myfunc,lxmin,lxmax,perc,dlxinc,dlxmax,glorder);
54 cout<<"IntegrateFuncLog() = "<<integlog<<endl;
55
56 cout<<"Integrate() = "<<myfunc.integ(xmin,xmax)<<endl;
57
58 return 0;
59}
Note: See TracBrowser for help on using the repository browser.