Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19244852
test_gegenbauerSeriesSum.cc
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
test_gegenbauerSeriesSum.cc
View Options
#include
<cmath>
#include
"UnitTest++.h"
#include
"test_utils.hh"
#include
"npstat/nm/MathUtils.hh"
using
namespace
npstat
;
using
namespace
std
;
namespace
{
double
poly0
(
const
double
/* x */
,
double
/* lambda */
)
{
return
1.0
;
}
double
poly1
(
const
double
x
,
const
double
lambda
)
{
return
2.0
*
lambda
*
x
;
}
double
poly2
(
const
double
x
,
const
double
lambda
)
{
return
-
lambda
+
2
*
lambda
*
(
1
+
lambda
)
*
x
*
x
;
}
double
poly3
(
const
double
x
,
const
double
lambda
)
{
return
-
2
*
lambda
*
(
1
+
lambda
)
*
x
+
(
4
*
lambda
*
(
1
+
lambda
)
*
(
2
+
lambda
)
*
x
*
x
*
x
)
/
3.0
;
}
double
poly4
(
const
double
x
,
const
double
lambda
)
{
const
double
xsq
=
x
*
x
;
return
(
lambda
*
(
1
+
lambda
))
/
2.
-
2
*
lambda
*
(
1
+
lambda
)
*
(
2
+
lambda
)
*
x
*
x
+
(
2
*
lambda
*
(
1
+
lambda
)
*
(
2
+
lambda
)
*
(
3
+
lambda
)
*
xsq
*
xsq
)
/
3.0
;
}
TEST
(
gegenbauerSeriesSum_1
)
{
typedef
double
(
*
Poly
)(
double
,
double
);
const
unsigned
nscan
=
100
;
Poly
polys
[]
=
{
poly0
,
poly1
,
poly2
,
poly3
,
poly4
};
double
coeffs
[
sizeof
(
polys
)
/
sizeof
(
polys
[
0
])]
=
{
0.0
,};
const
unsigned
nset
[]
=
{
1
,
2
,
3
,
4
};
for
(
unsigned
in
=
0
;
in
<
sizeof
(
nset
)
/
sizeof
(
nset
[
0
]);
++
in
)
{
const
double
lambda
=
nset
[
in
]
+
0.5
;
for
(
unsigned
icycle
=
0
;
icycle
<
sizeof
(
polys
)
/
sizeof
(
polys
[
0
]);
++
icycle
)
{
for
(
unsigned
i
=
0
;
i
<
icycle
;
++
i
)
coeffs
[
i
]
=
0.0
;
coeffs
[
icycle
]
=
1.0
;
for
(
unsigned
i
=
0
;
i
<
nscan
;
++
i
)
{
const
double
x
=
-
1.0
+
(
i
+
0.5
)
*
2.0
/
nscan
;
const
double
vexpected
=
polys
[
icycle
](
x
,
lambda
);
const
double
vcalc
=
gegenbauerSeriesSum
(
coeffs
,
icycle
,
lambda
,
x
);
CHECK_CLOSE
(
vexpected
,
vcalc
,
1.0e-12
);
}
}
coeffs
[
0
]
=
2.0
;
coeffs
[
1
]
=
3.0
;
coeffs
[
2
]
=
5.0
;
coeffs
[
3
]
=
7.0
;
coeffs
[
4
]
=
11.0
;
double
xset
[]
=
{
0.0
,
0.1
,
0.2
,
0.3
,
0.4
,
0.5
};
for
(
unsigned
icycle
=
0
;
icycle
<
sizeof
(
xset
)
/
sizeof
(
xset
[
0
]);
++
icycle
)
{
const
double
x
=
xset
[
icycle
];
const
double
vcalc
=
gegenbauerSeriesSum
(
coeffs
,
4
,
lambda
,
x
);
long
double
sum
=
0.0
L
;
for
(
unsigned
i
=
0
;
i
<
5
;
++
i
)
sum
+=
coeffs
[
i
]
*
polys
[
i
](
x
,
lambda
);
const
double
vexpected
=
sum
;
CHECK_CLOSE
(
vexpected
,
vcalc
,
1.0e-12
);
}
}
}
TEST
(
gegenbauerSeriesSum_2
)
{
// Test that Gegenbauer series are reduced to Legendre
// series for lambda = 1/2
const
unsigned
ncycles
=
100
;
const
unsigned
degree
=
10
;
const
unsigned
nintervals
=
51
;
const
double
eps
=
1.0e-12
;
const
double
step
=
2.0
/
nintervals
;
double
coeffs
[
degree
+
1
];
for
(
unsigned
icycle
=
0
;
icycle
<
ncycles
;
++
icycle
)
{
for
(
unsigned
i
=
0
;
i
<=
degree
;
++
i
)
coeffs
[
i
]
=
2.0
*
test_rng
()
-
1.0
;
for
(
unsigned
i
=
0
;
i
<
nintervals
;
++
i
)
{
const
double
x
=
-
1.0
+
(
i
+
0.5
)
*
step
;
const
double
gsum
=
gegenbauerSeriesSum
(
coeffs
,
degree
,
0.5
,
x
);
const
double
lsum
=
legendreSeriesSum
(
coeffs
,
degree
,
x
);
CHECK_CLOSE
(
lsum
,
gsum
,
eps
);
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Sep 30, 4:45 AM (15 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6540737
Default Alt Text
test_gegenbauerSeriesSum.cc (3 KB)
Attached To
Mode
rNPSTATSVN npstatsvn
Attached
Detach File
Event Timeline
Log In to Comment