MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/integrate_function_adapt_simp_ex.cpp:57–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57int main()
58{
59 // We first define a tolerance parameter. Roughly speaking, a lower tolerance will
60 // result in a more accurate approximation of the true integral. However, there are
61 // instances where too small of a tolerance may yield a less accurate approximation
62 // than a larger tolerance. We recommend taking the tolerance to be in the
63 // [1e-10, 1e-8] region.
64
65 double tol = 1e-10;
66
67
68 // Here we compute the integrals of the five functions defined above using the same
69 // tolerance level for each.
70
71 double m1 = integrate_function_adapt_simp(&gg1, 0.0, 1.0, tol);
72 double m2 = integrate_function_adapt_simp(&gg2, 0.0, 1.0, tol);
73 double m3 = integrate_function_adapt_simp(&gg3, 0.0, pi, tol);
74 double m4 = integrate_function_adapt_simp(&gg4, -pi, pi, tol);
75 double m5 = integrate_function_adapt_simp(&gg5, 0.0, 2.0, tol);
76
77 // We finally print out the values of each of the approximated integrals to ten
78 // significant digits.
79
80 cout << "\nThe integral of exp(x) for x in [0,1] is " << std::setprecision(10) << m1 << endl;
81 cout << "The integral of x^2 for in [0,1] is " << std::setprecision(10) << m2 << endl;
82 cout << "The integral of 1/(x^2 + cos(x)^2) for in [0,pi] is " << std::setprecision(10) << m3 << endl;
83 cout << "The integral of sin(x) for in [-pi,pi] is " << std::setprecision(10) << m4 << endl;
84 cout << "The integral of 1/(1+x^2) for in [0,2] is " << std::setprecision(10) << m5 << endl;
85 cout << endl;
86
87 return 0;
88}
89

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected