diff options
Diffstat (limited to 'tutorials/module_3/4_numerical_integration.md')
| -rw-r--r-- | tutorials/module_3/4_numerical_integration.md | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/tutorials/module_3/4_numerical_integration.md b/tutorials/module_3/4_numerical_integration.md index 0c2e755..4448985 100644 --- a/tutorials/module_3/4_numerical_integration.md +++ b/tutorials/module_3/4_numerical_integration.md @@ -145,7 +145,7 @@ while (iter_ < iter_max) and (err > tol): ``` ### Gaussian Quadrature -Gaussian quadrature chooses evaluation points and weights optimally (based on Legendre polynomials) to maximize accuracy. With $n$ evaluation points, Gaussian quadrature is exact for polynomials of degree up to $2n-1$. This makes it extremely efficient for smooth integrands. +Gaussian quadrature chooses evaluation points and weights optimally to maximize accuracy. With $n$ evaluation points, Gaussian quadrature is exact for polynomials of degree up to $2n-1$. This makes it extremely efficient for smooth integrands. ```python import numpy as np @@ -205,29 +205,40 @@ print(f"Error (3-point): {err3:.2e}") - - - - ---- - - ## More integral ### Newton-Cotes Algorithms for Equations ### Adaptive Quadrature - - # Problems ## Numerical Integration to Compute Work - +In physics we've learned that work is computed +$$ +Work = force * distance +$$ +This can be written in int's integral form: +$$ +W = \int{F(x)dx} +$$ +If F(x) is easy to integrate, we could solve this problem analytically. However, a realistic problem the force may not be available to you as a function, but rather, tabulated data. Suppose some measurements were take of when a weighted box was pulled with a wire. If we data of the force on the wire and the angle of the wire from the horizontal plane. + +| x (ft) | F(x) (lb) | θ (rad) | F(x) cos θ | +| ------ | --------- | ------- | ---------- | +| 0 | 0.0 | 0.50 | 0.0000 | +| 5 | 9.0 | 1.40 | 1.5297 | +| 10 | 13.0 | 0.75 | 9.5120 | +| 15 | 14.0 | 0.90 | 8.7025 | +| 20 | 10.5 | 1.30 | 2.8087 | +| 25 | 12.0 | 1.48 | 1.0881 | +| 30 | 5.0 | 1.50 | 0.3537 | +| | | | | +Use the trapezoidal rule to compute the work done on the box. ## Implementing the Composite Trapezoidal Rule -**Objective:** Implement a Python function to approximate integrals using the trapezoidal rule. +Implement a Python function to approximate integrals using the trapezoidal rule. ```python import numpy as np @@ -245,17 +256,4 @@ for n in [4, 8, 16, 32]: print(n, trapz(f1, 0, np.pi, n)) ``` -Students should compare results for increasing $n$ and observe how the error decreases with $O(h^2$). - ---- -## Gaussian Quadrature - -Write a Python function for two-point and three-point Gauss–Legendre quadrature over an arbitrary interval $[a,b]$. Verify exactness for polynomials up to the appropriate degree and compare performance against the trapezoidal rule on oscillatory test functions. - ---- - -## Simpson’s 1/3 Rule - -Code the composite Simpson’s 1/3 rule. Test its accuracy on smooth functions and compare its performance to the trapezoidal rule and Gaussian quadrature. Document error trends and discuss cases where Simpson’s method is preferable. - ---- +Compare the results for increasing $n$ and observe how the error decreases with $O(h^2$). |
