Numerical integration/Gauss-Legendre Quadrature: Difference between revisions
Content added Content deleted
m (→{{header|C++}}: includes added) |
|||
Line 175: | Line 175: | ||
Does not quite perform the task quite as specified since the node count, N, is set at compile time (to avoid heap allocation) so cannot be passed as a parameter. |
Does not quite perform the task quite as specified since the node count, N, is set at compile time (to avoid heap allocation) so cannot be passed as a parameter. |
||
<lang cpp> |
<lang cpp>#include <iostream> |
||
#include <iomanip> |
|||
#include <cmath> |
|||
namespace Rosetta { |
namespace Rosetta { |
||
Line 217: | Line 220: | ||
out << ' ' << legpoly.root(i); |
out << ' ' << legpoly.root(i); |
||
} |
} |
||
out << |
out << std::endl; |
||
out << "Weights:"; |
out << "Weights:"; |
||
for (int i = 0; i <= eDEGREE; ++i) { |
for (int i = 0; i <= eDEGREE; ++i) { |
||
out << ' ' << legpoly.weight(i); |
out << ' ' << legpoly.weight(i); |
||
} |
} |
||
out << |
out << std::endl; |
||
} |
} |
||
private: |
private: |
||
Line 309: | Line 312: | ||
gl5.print_roots_and_weights(std::cout); |
gl5.print_roots_and_weights(std::cout); |
||
std::cout << "Integrating Exp(X) over [-3, 3]: " << gl5.integrate(-3., 3., RosettaExp) << |
std::cout << "Integrating Exp(X) over [-3, 3]: " << gl5.integrate(-3., 3., RosettaExp) << std::endl; |
||
std::cout << "Actual value: " << RosettaExp(3) - RosettaExp(-3) << |
std::cout << "Actual value: " << RosettaExp(3) - RosettaExp(-3) << std::endl; |
||
⚫ | |||
} |
|||
⚫ | |||
{{out}} |
{{out}} |