Anonymous user
Numerical integration/Gauss-Legendre Quadrature: Difference between revisions
Numerical integration/Gauss-Legendre Quadrature (view source)
Revision as of 11:02, 5 August 2020
, 3 years ago→{{header|C++}}: includes added
m (→{{header|C++}}: includes added) |
|||
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.
<lang cpp>#include <iostream>
#include <iomanip>
#include <cmath>
namespace Rosetta {
Line 217 ⟶ 220:
out << ' ' << legpoly.root(i);
}
out <<
out << "Weights:";
for (int i = 0; i <= eDEGREE; ++i) {
out << ' ' << legpoly.weight(i);
}
out <<
}
private:
Line 309 ⟶ 312:
gl5.print_roots_and_weights(std::cout);
std::cout << "Integrating Exp(X) over [-3, 3]: " << gl5.integrate(-3., 3., RosettaExp) <<
std::cout << "Actual value: " << RosettaExp(3) - RosettaExp(-3) <<
}</lang>▼
▲</lang>
{{out}}
|