forked from Prad-R/DiceForge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_2D.cpp
55 lines (42 loc) · 1.5 KB
/
test_2D.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
#include "diceforge.h"
#include <iomanip>
template <typename Type>
void test_double_integral_1()
{
auto f = [](auto x, auto y)
{
return std::sin(x) * std::cos(y * y);
};
auto pi = std::asin(1) * 2;
auto bound_x = std::tuple<Type, Type>{0.0, pi / 2};
auto bound_y = std::tuple<Type, Type>{0.0, pi / 2};
auto int_x_y = DiceForge::integrate(f, bound_x, bound_y, DiceForge::dy_dx);
auto int_y_x = DiceForge::integrate(f, bound_y, bound_x, DiceForge::dx_dy);
std::cout << std::setprecision(17) << "int_x_y = " << int_x_y << std::endl;
std::cout << std::setprecision(17) << "int_y_x = " << int_y_x << std::endl;
}
template <typename Type>
void test_double_integral_2()
{
auto z = [](auto x, auto y)
{
return 16 - x * x - y * y;
};
auto bound_y = std::make_tuple(Type{0}, Type{2});
auto lower = [](auto y)
{ return y * y / 4; };
auto upper = [](auto y)
{ return (y + 2) / 4; };
auto bound_x = std::make_tuple(lower, upper);
auto calculated_answer = DiceForge::integrate(z, bound_y, bound_x, DiceForge::dx_dy);
auto actual_answer = 20803.0 / 1680.0;
std::cout << std::setprecision(17) << "calculated_answer = " << calculated_answer << std::endl;
std::cout << std::setprecision(17) << "actual_answer = " << actual_answer << std::endl;
}
int main()
{
std::cout<<"for test case one :"<<std::endl;
test_double_integral_1<double>();
std::cout<<"for test case two :"<<std::endl;
test_double_integral_2<double>();
}