Numerical integration/Gauss-Legendre Quadrature: Difference between revisions

m
→‎{{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 << '\n'std::endl;
out << "Weights:";
for (int i = 0; i <= eDEGREE; ++i) {
out << ' ' << legpoly.weight(i);
}
out << '\n'std::endl;
}
private:
Line 309 ⟶ 312:
 
gl5.print_roots_and_weights(std::cout);
std::cout << "Integrating Exp(X) over [-3, 3]: " << gl5.integrate(-3., 3., RosettaExp) << '\n'std::endl;
std::cout << "Actual value: " << RosettaExp(3) - RosettaExp(-3) << '\n'std::endl;
}</lang>
}
</lang>
 
{{out}}
Anonymous user