Numerical integration/Gauss-Legendre Quadrature: Difference between revisions

m
added whitespace to the task's preamble, used a larger font for the last forumula.
m (added whitespace to the task's preamble, used a larger font for the last forumula.)
Line 1:
{{Task|Arithmetic operations}}[[Category:Arithmetic]][[Category:Mathematics]]
[[Category:Arithmetic]]
[[Category:Mathematics]]
 
{|border=1 cellspacing=0 cellpadding=3
Line 11 ⟶ 13:
|<math>\int_{-1}^1 f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)</math>
|}
 
 
For this, we first need to calculate the nodes and the weights, but after we have them, we can reuse them for numerious integral evaluations, which greatly speeds up the calculation compared to more [[Numerical Integration|simple numerical integration methods]].
Line 35 ⟶ 38:
|<math>\int_a^b f(x)\,dx \approx \frac{b-a}{2} \sum_{i=1}^n w_i f\left(\frac{b-a}{2}x_i + \frac{a+b}{2}\right)</math>
|}
 
 
'''Task description'''
Line 40 ⟶ 44:
Similar to the task [[Numerical Integration]], the task here is to calculate the definite integral of a function <math>f(x)</math>, but by applying an n-point Gauss-Legendre quadrature rule, as described [[wp:Gaussian Quadrature|here]], for example. The input values should be an function f to integrate, the bounds of the integration interval a and b, and the number of gaussian evaluation points n. An reference implementation in Common Lisp is provided for comparison.
 
To demonstrate the calculation, compute the weights and nodes for an 5-point quadrature rule and then use them to compute:
:: <big><big><math> \int_{-3}^{3} \exp(x) \, dx \approx \sum_{i=1}^5 w_i \; \exp(x_i) \approx 20.036 </math></big></big>
 
<br><br>
::<math>\int_{-3}^{3} \exp(x) \, dx \approx \sum_{i=1}^5 w_i \; \exp(x_i) \approx 20.036</math>
 
=={{header|Axiom}}==