WhatsApp Image 2025-03-06 at 12.23.09 PM.jpeg

Full Transcript

# Lecture 14 ## Numerical Differentiation and Integration ### Review Lecture 13 * Ordinary Differential Equations * Euler's Method * Improved Euler's Method * Runge-Kutta Methods ### Lecture 14 Contents * Numerical Differentiation * Numerical Integration * Newton-Cotes Inte...

# Lecture 14 ## Numerical Differentiation and Integration ### Review Lecture 13 * Ordinary Differential Equations * Euler's Method * Improved Euler's Method * Runge-Kutta Methods ### Lecture 14 Contents * Numerical Differentiation * Numerical Integration * Newton-Cotes Integration Formulas * Trapezoidal rule * Simpson's rules ## Numerical Differentiation ### Numerical Differentiation * Differentiation of a function $f(x)$ is to find its rate of change $f'(x)$. * Based on the definition of derivative $f'(x) = \lim_{\Delta x \to 0} \frac{f(x + \Delta x) - f(x)}{\Delta x}$ * For numerical differentiation, we use a small $\Delta x$ to approximate $f'(x)$ $f'(x) \approx \frac{f(x + \Delta x) - f(x)}{\Delta x}$ * This approximation is called *forward difference approximation*. ## Numerical Differentiation Cont. * *Backward difference approximation*. $f'(x) \approx \frac{f(x) - f(x - \Delta x)}{\Delta x}$ * *Central difference approximation*. $f'(x) \approx \frac{f(x + \Delta x) - f(x - \Delta x)}{2 \Delta x}$ ### Example * Use forward and backward difference approximations to estimate the derivative of $f(x) = e^x$ at $x = 2$ using a step size of $\Delta x = 0.1$. Compare with the true solution. * **Solution:** * The true solution is $f'(x) = e^x$, so $f'(2) = e^2 = 7.389056099...$ ## Example Cont. * Forward difference approximation $\frac{f(x + \Delta x) - f(x)}{\Delta x} = \frac{e^{2.1} - e^2}{0.1} = 7.707426066$ * Absolute error $ = |7.707426066 - 7.389056099| = 0.318369967$ * Relative error $ = |\frac{0.318369967}{7.389056099}| = 0.0430869$ * Backward difference approximation $\frac{f(x) - f(x - \Delta x)}{\Delta x} = \frac{e^{2} - e^{1.9}}{0.1} = 7.081880265$ * Absolute error $ = |7.081880265 - 7.389056099| = 0.307175834$ * Relative error $ = |\frac{0.307175834}{7.389056099}| = 0.0415713$ ## Example Cont. * Use central difference approximation to estimate the derivative of $f(x) = e^x$ at $x = 2$ using a step size of $\Delta x = 0.1$. Compare with the true solution. * **Solution:** * Central difference approximation $\frac{f(x + \Delta x) - f(x - \Delta x)}{2 \Delta x} = \frac{e^{2.1} - e^{1.9}}{0.2} = 7.394653166$ * Absolute error $ = |7.394653166 - 7.389056099| = 0.005597067$ * Relative error $ = |\frac{0.005597067}{7.389056099}| = 0.0007575$ ## Higher-Order Derivatives * We can also approximate higher-order derivatives using difference approximations. * For example, the second derivative $f''(x)$ can be approximated as: $f''(x) \approx \frac{f'(x + \Delta x) - f'(x - \Delta x)}{2 \Delta x}$ * Using central difference approximation for $f'(x + \Delta x)$ and $f'(x - \Delta x)$, we get $f''(x) \approx \frac{f(x + 2\Delta x) - 2f(x) + f(x - 2\Delta x)}{(2 \Delta x)^2}$ ## Numerical Integration ### Numerical Integration * Integration of a function $f(x)$ is to find the area under the curve of $f(x)$. $\int_a^b f(x) dx$ * Numerical integration is to approximate the definite integral of a function using numerical methods. * The idea is to divide the interval $[a, b]$ into smaller subintervals and approximate the area under the curve in each subinterval. ## Newton-Cotes Integration Formulas ### Newton-Cotes Integration Formulas * Newton-Cotes formulas are a family of numerical integration methods based on approximating the integrand $f(x)$ with a polynomial. * The integral of the polynomial is then used to approximate the integral of $f(x)$. * The Newton-Cotes formulas are named after Isaac Newton and Roger Cotes. * The most common Newton-Cotes formulas are the trapezoidal rule and Simpson's rule. ### Trapezoidal Rule * The trapezoidal rule approximates the integral of $f(x)$ by dividing the area under the curve into trapezoids. * The area of each trapezoid is given by: $A_i = \frac{f(x_i) + f(x_{i+1})}{2} \Delta x$ * The integral is approximated by the sum of the areas of the trapezoids: $\int_a^b f(x) dx \approx \frac{\Delta x}{2} [f(x_1) + 2f(x_2) + 2f(x_3) +... + 2f(x_{n-1}) + f(x_n)]$ ### Example * Use the trapezoidal rule to approximate the integral of $f(x) = x^2$ from $a = 0$ to $b = 2$ using $n = 4$ subintervals. Compare with the true solution. * **Solution:** * The width of each subinterval is $\Delta x = \frac{b - a}{n} = \frac{2 - 0}{4} = 0.5$ * The $x$ values are $x_1 = 0, x_2 = 0.5, x_3 = 1, x_4 = 1.5, x_5 = 2$ $\int_0^2 x^2 dx \approx \frac{0.5}{2} [0^2 + 2(0.5)^2 + 2(1)^2 + 2(1.5)^2 + 2^2] = 2.75$ * The true solution is $\int_0^2 x^2 dx = \frac{x^3}{3} |_0^2 = \frac{8}{3} = 2.666666667$ ## Simpson's Rules ### Simpson's Rules * Simpson's rules are a family of numerical integration methods based on approximating the integrand $f(x)$ with quadratic polynomials. * Simpson's 1/3 rule approximates the integral of $f(x)$ by dividing the area under the curve into parabolas. * The integral is approximated by: $\int_a^b f(x) dx \approx \frac{\Delta x}{3} [f(x_1) + 4f(x_2) + 2f(x_3) + 4f(x_4) +... + 2f(x_{n-1}) + 4f(x_n) + f(x_{n+1})]$ * where $n$ is even. ### Simpson's 3/8 Rule * Simpson's 3/8 rule approximates the integral of $f(x)$ by dividing the area under the curve into cubic polynomials. * The integral is approximated by: $\int_a^b f(x) dx \approx \frac{3\Delta x}{8} [f(x_1) + 3f(x_2) + 3f(x_3) + 2f(x_4) + 3f(x_5) + 3f(x_6) + 2f(x_7) +... + f(x_n)]$ * where $n$ is a multiple of 3. ### Example * Use Simpson's 1/3 rule to approximate the integral of $f(x) = x^2$ from $a = 0$ to $b = 2$ using $n = 4$ subintervals. Compare with the true solution. * **Solution:** * The width of each subinterval is $\Delta x = \frac{b - a}{n} = \frac{2 - 0}{4} = 0.5$ * The $x$ values are $x_1 = 0, x_2 = 0.5, x_3 = 1, x_4 = 1.5, x_5 = 2$ $\int_0^2 x^2 dx \approx \frac{0.5}{3} [0^2 + 4(0.5)^2 + 2(1)^2 + 4(1.5)^2 + 2^2] = 2.666666667$ * The true solution is $\int_0^2 x^2 dx = \frac{x^3}{3} |_0^2 = \frac{8}{3} = 2.666666667$ ## Summary ### Lecture 14 Summary * Numerical Differentiation * Approximation of derivatives using difference formulas * Numerical Integration * Newton-Cotes Integration Formulas * Trapezoidal rule * Simpson's rules

Use Quizgecko on...
Browser
Browser