Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19251877
test_chebyshevSeriesSum.cc
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
test_chebyshevSeriesSum.cc
View Options
#include
<cmath>
#include
"UnitTest++.h"
#include
"test_utils.hh"
#include
"npstat/nm/MathUtils.hh"
#include
"npstat/nm/SimpleFunctors.hh"
using
namespace
npstat
;
using
namespace
std
;
namespace
{
double
poly0
(
const
double
/* x */
)
{
return
1.0
;
}
double
poly1
(
const
double
x
)
{
return
x
;
}
double
poly2
(
const
double
x
)
{
return
2.0
*
x
*
x
-
1.0
;
}
double
poly3
(
const
double
x
)
{
return
4.0
*
x
*
x
*
x
-
3.0
*
x
;
}
double
poly4
(
const
double
x
)
{
const
double
xsq
=
x
*
x
;
return
8.0
*
xsq
*
xsq
-
8.0
*
xsq
+
1.0
;
}
TEST
(
chebyshevSeriesSum
)
{
typedef
double
(
*
Poly
)(
double
);
const
unsigned
nscan
=
100
;
Poly
polys
[]
=
{
poly0
,
poly1
,
poly2
,
poly3
,
poly4
};
double
coeffs
[
sizeof
(
polys
)
/
sizeof
(
polys
[
0
])]
=
{
0.0
,};
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
);
const
double
vcalc
=
chebyshevSeriesSum
(
coeffs
,
icycle
,
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
=
chebyshevSeriesSum
(
coeffs
,
4
,
x
);
long
double
sum
=
0.0
L
;
for
(
unsigned
i
=
0
;
i
<
5
;
++
i
)
sum
+=
coeffs
[
i
]
*
polys
[
i
](
x
);
const
double
vexpected
=
sum
;
CHECK_CLOSE
(
vexpected
,
vcalc
,
1.0e-12
);
}
}
TEST
(
chebyshevSeriesCoeffs
)
{
const
unsigned
deg
=
20
;
double
coeffs
[
deg
+
1
];
double
xmin
=
0.0
;
double
xmax
=
2.0
*
M_PI
;
const
unsigned
nscan
=
100
;
chebyshevSeriesCoeffs
(
FcnFunctor1
<
long
double
,
long
double
>
(
sinl
),
xmin
,
xmax
,
deg
,
coeffs
);
double
h
=
(
xmax
-
xmin
)
/
nscan
;
for
(
unsigned
i
=
0
;
i
<
nscan
;
++
i
)
{
double
x
=
xmin
+
i
*
h
;
const
double
ref
=
sin
(
x
);
x
=
2.0
*
(
x
-
xmin
)
/
(
xmax
-
xmin
)
-
1.0
;
double
fval
=
chebyshevSeriesSum
(
coeffs
,
deg
,
x
);
CHECK_CLOSE
(
ref
,
fval
,
1.0e-15
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Sep 30, 6:12 AM (15 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6552596
Default Alt Text
test_chebyshevSeriesSum.cc (2 KB)
Attached To
Mode
rNPSTATSVN npstatsvn
Attached
Detach File
Event Timeline
Log In to Comment