-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcircle_rule_prb.cpp
153 lines (131 loc) · 2.63 KB
/
circle_rule_prb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <cmath>
using namespace std;
# include "circle_rule.hpp"
int main ( );
void test01 ( int nt );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for CIRCLE_RULE_PRB.
//
// Discussion:
//
// CIRCLE_RULE_PRB tests the CIRCLE_RULE library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 06 April 2014
//
// Author:
//
// John Burkardt
//
{
int nt;
timestamp ( );
cout << "\n";
cout << "CIRCLE_RULE:\n";
cout << " C++ version\n";
cout << " Test the CIRCLE_RULE library.\n";
nt = 8;
test01 ( nt );
nt = 32;
test01 ( nt );
//
// Terminate.
//
cout << "\n";
cout << "CIRCLE_RULE:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void test01 ( int nt )
//****************************************************************************80
//
// Purpose:
//
// TEST01 tests CIRCLE_RULE.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 06 April 2014
//
// Author:
//
// John Burkardt
//
{
int e[2];
int e1;
int e2;
double exact;
int i;
double q;
double r8_pi = 3.141592653589793;
double *t;
double *w;
double x;
double y;
cout << "\n";
cout << "TEST01\n";
cout << " CIRCLE_RULE can compute a rule Q(f) for the unit circle\n";
cout << " using NT equally spaced angles.\n";
cout << " Estimate integrals I(f) where f = x^e(1) * y^e(2)\n";
cout << " using " << nt << " points.\n";
//
// Compute the quadrature rule.
//
w = new double[nt];
t = new double[nt];
circle_rule ( nt, w, t );
//
// Apply it to integrands.
//
cout << "\n";
cout << " E(1) E(2) I(f) Q(f)\n";
cout << "\n";
//
// Specify a monomial.
//
for ( e1 = 0; e1 <= 6; e1 = e1 + 2 )
{
e[0] = e1;
for ( e2 = e1; e2 <= 6; e2 = e2 + 2 )
{
e[1] = e2;
q = 0.0;
for ( i = 0; i < nt; i++ )
{
x = cos ( t[i] );
y = sin ( t[i] );
q = q + w[i] * pow ( x, e[0] ) * pow ( y, e[1] );
}
q = 2.0 * r8_pi * q;
exact = circle01_monomial_integral ( e );
cout << " " << setw(2) << e[0]
<< " " << setw(2) << e[1]
<< " " << setw(14) << exact
<< " " << setw(14) << q << "\n";
}
}
delete [] t;
delete [] w;
return;
}