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: testChebyshev.cc,v 1.6 2006/06/29 19:00:28 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
29 | // |
---|
30 | // Test program for G4ChebyshevApproximation 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 "G4ChebyshevApproximation.hh" |
---|
37 | |
---|
38 | G4double TestChebyshev(G4double x) |
---|
39 | { |
---|
40 | return std::sqrt(1-x*x)*std::cos(x) ; |
---|
41 | } |
---|
42 | |
---|
43 | G4double TestFunction(G4double x) |
---|
44 | { |
---|
45 | return std::exp(-x)*std::cos(x) ; |
---|
46 | } |
---|
47 | |
---|
48 | G4double TestHermite(G4double x) |
---|
49 | { |
---|
50 | return x*x*std::cos(x) ; |
---|
51 | } |
---|
52 | |
---|
53 | G4double ExpFunction(G4double x) |
---|
54 | { |
---|
55 | return std::exp(x) ; |
---|
56 | } |
---|
57 | |
---|
58 | G4double SinFunction(G4double x) |
---|
59 | { |
---|
60 | return std::sin(x) ; |
---|
61 | } |
---|
62 | |
---|
63 | main() |
---|
64 | { |
---|
65 | G4int i, k, m, n = 30; |
---|
66 | G4double x = 3.0 ; |
---|
67 | G4double a = 0.0 ; |
---|
68 | G4double b = 10.0 ; |
---|
69 | |
---|
70 | G4double test, tolerance, true = ExpFunction(x) - 1.0 ; |
---|
71 | for(i=5;i<=n;i++) |
---|
72 | { |
---|
73 | G4ChebyshevApproximation myChebyshev(ExpFunction,a,b,i) ; // integral |
---|
74 | test = myChebyshev.ChebyshevEvaluation(x) ; |
---|
75 | tolerance = 2*(true-test)/(true+test) ; |
---|
76 | G4cout<<"n = "<<i<<"\t"<<"true = "<<true |
---|
77 | <<" and n-point ChebEval = " |
---|
78 | <<test<<"\t"<<tolerance<<G4endl ; |
---|
79 | } |
---|
80 | /* ******************************************************** |
---|
81 | n = k*m + 10 ; |
---|
82 | |
---|
83 | G4double x = 3.0 ; |
---|
84 | G4double delta = m*0.1*x ; |
---|
85 | G4double a = x - delta ; |
---|
86 | G4double b = x + delta ; |
---|
87 | |
---|
88 | G4double test, tolerance, true = SinFunction(x) ; |
---|
89 | for(i=1+m;i<=n;i++) |
---|
90 | { |
---|
91 | G4ChebyshevApproximation myChebyshev(SinFunction,i,m,a,b) ; // m-derivative |
---|
92 | test = myChebyshev.ChebyshevEvaluation(x) ; |
---|
93 | tolerance = 2*(true-test)/(true+test) ; |
---|
94 | G4cout<<"n = "<<i<<"\t"<<"true = "<<true |
---|
95 | <<" and n-point ChebEval = " |
---|
96 | <<test<<"\t"<<tolerance<<G4endl ; |
---|
97 | } |
---|
98 | G4double test, tolerance, true = TestFunction(x) ; |
---|
99 | for(i=1;i<n;i++) |
---|
100 | { |
---|
101 | G4ChebyshevApproximation myChebyshev(TestFunction,i,a,b) ; |
---|
102 | test = myChebyshev.ChebyshevEvaluation(x) ; |
---|
103 | tolerance = 2*(true-test)/(true+test) ; |
---|
104 | G4cout<<"n = "<<i<<"\t"<<"true = "<<true |
---|
105 | <<" and n-point ChebEval = " |
---|
106 | <<test<<"\t"<<tolerance<<G4endl ; |
---|
107 | } |
---|
108 | */ /////////////////////////////////////////////////// |
---|
109 | return 0; |
---|
110 | } |
---|