source: Sophya/trunk/Cosmo/SimLSS/cmvsinxsx.cc@ 3500

Last change on this file since 3500 was 3500, checked in by cmv, 17 years ago

fct sin(x)/x et sin(n*x)/sin(x) cmv 18/06/2008

File size: 4.3 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
10#include "ntuple.h"
11#include "geneutils.h"
12/*
13...Check autour de zero
14> cmvsinxsx -n 4 1e-6,-0.1,0.1
15> cmvsinxsx -n 5 1e-6,-0.1,0.1
16...Check autour de Pi
17> cmvsinxsx -n 4 1e-6,3.041592659,3.241592659
18> cmvsinxsx -n 5 1e-6,3.041592659,3.241592659
19...Check autour de -Pi
20> cmvsinxsx -n 4 1e-6,-3.241592659,-3.041592659
21> cmvsinxsx -n 5 1e-6,-3.241592659,-3.041592659
22
23...Check longue echelle
24> cmvsinxsx -n 10 0.0001,-6.5,6.5
25> cmvsinxsx -n 11 0.0001,-6.5,6.5
26
27...Check sans plot
28> cmvsinxsx -n 100 0.00001,-6.5,6.5
29> cmvsinxsx -n 1000 0.00001,-6.5,6.5
30 */
31
32
33int main(int narg,char *arg[])
34{
35 double dt = 0.000001;
36 //double tmin = -0.1, tmax = 0.1;
37 double tmin = M_PI-0.1, tmax = M_PI+0.1;
38 unsigned long N = 4;
39 bool only_test = false;
40 double pr_test = 1.e99;
41
42 char c;
43 while((c = getopt(narg,arg,"htp:n:")) != -1) {
44 switch (c) {
45 case 'n' :
46 sscanf(optarg,"%lu",&N);
47 break;
48 case 't' :
49 only_test = true;
50 break;
51 case 'p' :
52 sscanf(optarg,"%lf",&pr_test);
53 break;
54 case 'h' :
55 default :
56 cout<<"cmvsinxsx [-t] [-p eps_print] [-n N] [dt,tmin,tmax (rad)]"<<endl;
57 return -1;
58 }
59 }
60 if(optind<narg) sscanf(arg[optind],"%lf,%lf,%lf",&dt,&tmin,&tmax);
61
62 cout<<"N="<<N<<" dt="<<dt<<" tmin="<<tmin<<" tmax="<<tmax<<" rad"<<endl;
63 cout<<"only_test="<<only_test<<" pr_test="<<pr_test<<endl;
64 if(tmax<=tmin) return -1;
65
66 const int nvar = 11;
67 char *vname[nvar] = {"t","s","sn","sx","sx2","snx","snx2","asx","asx2","asnx","asnx2"};
68 double xnt[nvar];
69 NTuple nt(nvar,vname);
70
71 long n = 0;
72 double diffsx=0., diffsx2=0., diffsnx=0., diffsnx2=0.;
73 for(double t=tmin; t<tmax+dt/3.; t+=dt) {
74 xnt[0] = t;
75 xnt[1] = sin(t);
76 xnt[2] = sin(N*t);
77 xnt[3] = SinXsX(t);
78 xnt[4] = SinXsX_Sqr(t);
79 xnt[5] = SinNXsX(t,N);
80 xnt[6] = SinNXsX_Sqr(t,N);
81 xnt[7] = SinXsX(t,true);
82 xnt[8] = SinXsX_Sqr(t,true);
83 xnt[9] = SinNXsX(t,N,true);
84 xnt[10] = SinNXsX_Sqr(t,N,true);
85 if(!only_test) nt.Fill(xnt);
86
87 // les tests de difference maxi
88 double av;
89 if(xnt[0]>1e-15) {
90 double ref = xnt[1]/xnt[0];
91 av = fabs(xnt[3]-ref);
92 if(av>pr_test) printf("t=%.15e sx/x=%.15e, %.15e d=%g\n",t,xnt[3],ref,av);
93 if(av>diffsx) diffsx = av;
94 av = fabs(xnt[4]-ref*ref);
95 if(av>pr_test) printf("t=%.15e (sx/x)^2=%.15e, %.15e d=%g\n",t,xnt[4],ref*ref,av);
96 if(av>diffsx2) diffsx2 = av;
97 }
98 if(fabs(xnt[1])>1e-15) {
99 double ref = xnt[2]/xnt[1];
100 av = fabs(xnt[5]-ref);
101 if(av>pr_test) printf("t=%.15e snx/sx=%.15e, %.15e d=%g\n",t,xnt[5],ref,av);
102 if(fabs(av)>diffsnx) diffsnx = av;
103 av = fabs(xnt[6]-ref*ref);
104 if(av>pr_test) printf("t=%.15e (snx/sx)^2=%.15e, %.15e d=%g\n",t,xnt[6],ref*ref,av);
105 if(fabs(av)>diffsnx2) diffsnx2 = av;
106 }
107
108 n++;
109 }
110 cout<<"Number of entries = "<<n<<endl;
111 cout<<"Diff sx/x = "<<diffsx<<endl;
112 cout<<" (sx/x)^2 = "<<diffsx2<<endl;
113 //Attention, vers Pi c'est la precision machine sur sin(N*x)/sin(x) qui donne l'erreur
114 cout<<" sNx/x = "<<diffsnx<<" = "<<diffsnx/N<<" * "<<N<<endl;
115 cout<<" (sNx/x)^2 = "<<diffsnx2<<" = "<<diffsnx2/(N*N)<<" * "<<N<<" * "<<N<<endl;
116
117 if(!only_test) {
118 cout<<"writing ppf"<<endl;
119 POutPersist pos("cmvsinxsx.ppf");
120 pos.PutObject(nt,"nt");
121 }
122
123 return 0;
124}
125
126/*
127openppf cmvsinxsx.ppf
128
129zone
130n/plot nt.s%t ! ! "connectpoints"
131n/plot nt.sn%t ! ! "connectpoints same red"
132
133#-------
134zone 1 3
135n/plot nt.sx%t ! ! "connectpoints"
136n/plot nt.asx%t ! ! "connectpoints same green"
137n/plot nt.sx-s/t%t fabs(t)>1e-15 ! "connectpoints"
138n/plot nt.sx-asx%t ! ! "connectpoints"
139
140#-------
141zone 1 3
142n/plot nt.sx2%t ! ! "connectpoints"
143n/plot nt.sx*sx%t ! ! "connectpoints same red"
144n/plot nt.asx2%t ! ! "connectpoints same green"
145n/plot nt.sx2-pow(s/t,2.)%t fabs(t)>1e-15 ! "connectpoints"
146n/plot nt.sx2-asx2%t ! ! "connectpoints"
147
148#-------
149zone 1 3
150n/plot nt.snx%t ! ! "connectpoints"
151n/plot nt.asnx%t ! ! "connectpoints same green"
152n/plot nt.snx-sn/s%t fabs(s)>1e-15 ! "connectpoints"
153n/plot nt.snx-asnx%t ! ! "connectpoints"
154
155#-------
156zone 1 3
157n/plot nt.snx2%t ! ! "connectpoints"
158n/plot nt.snx*snx%t ! ! "connectpoints same red"
159n/plot nt.asnx2%t ! ! "connectpoints same green"
160n/plot nt.snx2-pow(sn/s,2.)%t fabs(s)>1e-15 ! "connectpoints"
161n/plot nt.snx2-asnx2%t ! ! "connectpoints"
162
163*/
Note: See TracBrowser for help on using the repository browser.