source: trunk/source/global/HEPNumerics/test/testGaussianQuadrature.cc@ 1340

Last change on this file since 1340 was 1315, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 4.6 KB
RevLine 
[1199]1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: testGaussianQuadrature.cc,v 1.6 2006/06/29 19:00:37 gunter Exp $
[1315]28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
[1199]29//
30// Test program for G4GaussianQuadrature class. The function std::exp(-x)*std::cos(x) is
31// integrated between zero and two pi. The true result is 0.499066278634
32//
33
34#include "G4ios.hh"
35#include "globals.hh"
36// #include "G4VGaussianQuadrature.hh"
37#include "G4GaussChebyshevQ.hh"
38#include "G4GaussHermiteQ.hh"
39#include "G4GaussJacobiQ.hh"
40#include "G4GaussLaguerreQ.hh"
41#include "G4GaussLegendreQ.hh"
42
43G4double TestChebyshev(G4double x)
44{
45 return std::sqrt(1-x*x)*std::cos(x) ;
46}
47
48G4double TestFunction(G4double x)
49{
50 return std::exp(-x)*std::cos(x) ;
51}
52
53G4double TestHermite(G4double x)
54{
55 return x*x*std::cos(x) ;
56}
57
58G4double CosFunction(G4double x)
59{
60 return std::cos(x) ;
61}
62
63int main()
64{
65 G4int i, n = 20;
66 // G4double pTolerance ;
67 G4double a = -1.0 ;
68 G4double b = 1.0 ;
69 // G4double true = pi*0.4400505857 ;
70 for(i=1;i<20;i++)
71 {
72 n = 1*i ;
73 G4GaussChebyshevQ myChebyshev(TestChebyshev,n) ;
74 G4cout<<"n = "<<n<<"\t"<<"true = "<<true<<" and n-point Gauss-Chebyshev = "
75 <<myChebyshev.Integral(a,b)<<G4endl ;
76 }
77 // G4double true = pi*0.4400505857 ;
78 for(i=1;i<20;i++)
79 {
80 n = 1*i ;
81 G4GaussJacobiQ myJacobi(CosFunction,0.5,0.5,n) ;
82 G4cout<<"n = "<<n<<"\t"<<"true = "<<true<<" and n-point Gauss-Jacobi = "
83 <<myJacobi.Integral()<<G4endl ;
84 }
85 G4double true = 2*0.125*std::sqrt(pi)*std::exp(-0.25) ;
86 for(i=1;i<20;i++)
87 {
88 n = 1*i ;
89 G4GaussHermiteQ myHermite(TestHermite,n) ;
90 G4cout<<"n = "<<n<<"\t"<<"true = "<<true<<" and n-point GaussHermite = "
91 <<myHermite.Integral()<<G4endl ;
92 }
93 /* *******************
94 G4GaussianQuadrature myHermite(n) ;
95 for(i=0;i<(n+1)/2;i++)
96 {
97 G4cout<<i<<"\t"<<myHermite.GetAbscissa(i)<<"\t"
98 <<myHermite.GetWeight(i)<<G4endl ;
99 }
100 G4GaussianQuadrature myLaguerre(0.0,n) ;
101 for(i=0;i<n;i++)
102 {
103 G4cout<<i<<"\t"<<myLaguerre.GetAbscissa(i)<<"\t"
104 <<myLaguerre.GetWeight(i)<<G4endl ;
105 }
106 */ /////////////////////////////////////
107 for(i=1;i<20;i++)
108 {
109 n = 1*i ;
110 G4GaussLaguerreQ myLaguerre(CosFunction,0.0,n) ;
111 G4cout<<"n = "<<n<<"\t"<<"true = 0.5 "<<" and n-point GaussLaguerre = "
112 <<myLaguerre.Integral()<<G4endl ;
113 }
114 G4GaussLegendreQ myIntegrand(TestFunction) ;
115 G4cout<<"true is 0.499066278634 "<<" and QuickGaussLegendre is "<<
116 myIntegrand.QuickIntegral(0,2*pi)<<G4endl ;
117 G4cout<<"true is 0.499066278634 "<<" and AccurateGaussLegendre is "<<
118 myIntegrand.AccurateIntegral(0,2*pi)<<G4endl ;
119
120
121 for(i=1;i<20;i++)
122 {
123 n = 8*i ;
124 G4GaussLegendreQ myLegendre(TestFunction, n) ;
125 G4cout<<myLegendre.GetNumber()<<
126 "true is 0.5 "<<" and n-point GaussLegendre is "
127 <<myLegendre.Integral(0,200*pi)<<G4endl ;
128 }
129 /* **************************************************
130
131 */ /////////////////////////////////////
132 return 0;
133}
Note: See TracBrowser for help on using the repository browser.