CACS252 Numerical Method

Numerical MethodUnit 49 min read

Numerical Differentiation & Integration: Rules, Errors & Applications

Unit 4 of Numerical Method covers numerical differentiation (forward/backward/central difference methods) and integration (Trapezoidal, Simpson’s 1/3, and Simpson’s 3/8 rules), error analysis, and real-world applications in finance, physics, and engineering—with visual step-byys and exam-focused worked examples.

TAKEAWAYS:

  • Numerical differentiation approximates derivatives using finite differences (forward, backward, central) with error bounds or .
  • Integration rules (Trapezoidal, Simpson’s) convert continuous functions into discrete sums, with Simpson’s 1/3 rule offering accuracy for smooth functions.
  • Error analysis distinguishes truncation, rounding, and propagation errors, critical for validating computational results.
  • Real-world applications include calculating loan interest (integration), optimizing traffic routes (differentiation), and modeling stock prices (ODEs).
  • Trapezoidal rule is simple but less accurate () than Simpson’s rules for smooth functions.
  • Always check function smoothness and step size () when choosing a method—smaller reduces error but increases computation time.

Core Concepts: Why Numerical Methods?

Numerical methods solve mathematical problems approximately when exact solutions are impossible or impractical. For differentiation and integration:

  • Differentiation: Finds the rate of change of a function (e.g., velocity from position, slope of a curve).
  • Integration: Computes areas under curves (e.g., total distance traveled, accumulated interest).

Why not exact methods?

  • Some functions (e.g., ) have no closed-form antiderivative.
  • Real-world data is often discrete (e.g., sensor readings), not continuous.

1. Numerical Differentiation: Finite Difference Methods

Key Idea

Approximate the derivative using function values at nearby points. The error depends on the step size and the method used.

Three Methods

Method Formula Error Order When to Use
Forward Difference When only and are known.
Backward Difference When only and are known.
Central Difference Best accuracy; requires and .

Visual: Error vs. Step Size Key Insight: Central difference is twice as accurate for the same because its error term is .


Worked Example: Loan Interest Rate Calculation (Real-World Tie-In)

Problem: A bank offers a loan with monthly interest calculated as , where is time in years. Estimate the interest rate of change at year using:

  1. Forward difference (),
  2. Central difference ().

Solution:

  1. Forward Difference:
  2. Central Difference: (Exact value: .)

Visual: Interest Growth Curve Exam Tip: Always compare methods! Central difference is preferred unless data is limited.


2. Numerical Integration: Rules for Area Under Curves

Key Idea

Approximate by dividing into subintervals and summing areas of simple shapes (rectangles, trapezoids, parabolas).

Three Rules

Rule Formula Error Order When to Use
Trapezoidal Quick estimates; moderate accuracy.
Simpson’s 1/3 Smooth functions; high accuracy.
Simpson’s 3/8 Uses 3 subintervals per segment; error but more complex. Rarely used; niche applications.

Visual: Rule Comparison


Worked Example: Daraz Order Processing Time (Real-World Tie-In)

Problem: Daraz’s order processing time (in minutes) follows for hours. Estimate the total processing time for 5 hours using:

  1. Trapezoidal rule (),
  2. Simpson’s 1/3 rule ().

Solution:

  1. Trapezoidal Rule:

    • Divide into 5 subintervals: .
    • Values: , , , , , .
    • Sum:
  2. Simpson’s 1/3 Rule:

    • Same , but weights: .
    • Sum:
    • Exact integral: .

Visual: Order Processing Curve


3. Error Analysis in Numerical Methods

Types of Errors

Error Type Cause Example Mitigation
Truncation Error Approximation (e.g., finite differences) Using instead of exact . Reduce or use higher-order methods.
Rounding Error Limited precision (e.g., 64-bit floats) (should be 2.000000200000002). Use higher precision (e.g., double instead of float).
Propagation Error Errors compound in iterations. Repeated subtraction in floating-point. Reorder operations; use stable algorithms.

Visual: Error Propagation

flowchart TD
    A["Initial Error"] --> B["Step 1\n(Addition)"]
    B --> C["Step 2\n(Multiplication)"]
    C --> D["Step 3\n(Division)"]
    D --> E["Final Error\n(Grows with steps)"]

Worked Example: Ncell Data Usage Calculation

Problem: Ncell’s daily data usage (in GB) follows for hours. Estimate the total data used in a day using:

  1. Trapezoidal rule (),
  2. Simpson’s 1/3 rule (), and compare to the exact integral.

Solution:

  1. Exact Integral:

  2. Trapezoidal Rule ():

    • Values: , , , , .
    • Sum:
    • Error: GB.
  3. Simpson’s 1/3 Rule ():

    • Sum:
    • Error: (exact for this case).

Visual: Data Usage Curve


## In the Real World

  1. eSewa/Khalti Payments:

    • Idea Used: Numerical integration calculates total transaction fees over time for dynamic pricing models.
    • How: If fee (in NPR), the total fee for a month is , approximated using Simpson’s rule for efficiency.
  2. Pathao Driver Earnings:

    • Idea Used: Numerical differentiation estimates instantaneous demand growth (e.g., ) to optimize driver dispatch.
    • How: If demand (rides/hour), is approximated using central differences to predict peak times.
  3. NTC Electricity Billing:

    • Idea Used: Trapezoidal rule approximates energy consumption for time-of-use tariffs.
    • How: For a household with usage (kWh), monthly consumption is (720 hours), computed via trapezoidal rule for billing.

## Exam Tip: How to Score Full Marks

  1. For Differentiation:

    • Always state the method (forward/backward/central) and step size .
    • Show the formula and substitute values clearly.
    • Compare with exact value if possible (e.g., has ).
  2. For Integration:

    • Label subintervals and compute .
    • For Simpson’s 1/3, alternate weights (4, 2, 4, 2, ...) and include endpoints.
    • Verify with exact integral if the function is simple (e.g., polynomials).
  3. Error Analysis:

    • Distinguish truncation (method error) vs. rounding (precision error).
    • For integration, state the error order (e.g., "Trapezoidal rule has error").
  4. Real-World Applications:

    • Tie examples to Nepal: Use Ncell, NTC, or Daraz in problems.
    • Show units: If integrating time, answer should be in "hours" or "minutes," not just numbers.
  5. Algorithm Questions:

    • Write pseudo-code with steps like:
      1. Input: f(x), a, b, n
      2. h = (b - a)/n
      3. sum = f(a) + f(b)
      4. For i = 1 to n-1:
             sum += 2*f(a + i*h)  [Trapezoidal]
             OR sum += 4*f(a + i*h) if i odd, 2*f(...) if i even  [Simpson’s]
      5. Return (h/2)*sum  [Trapezoidal] or (h/3)*sum  [Simpson’s]
      

Final Visual: Method Selection Guide

mindmap
  root((Choose Method))
    Differentiation
      Forward: Limited data
      Backward: Past data only
      Central: Best accuracy
    Integration
      Trapezoidal: Quick estimate
      Simpson’s 1/3: Smooth functions
      Simpson’s 3/8: Rare cases
    Error
      Small h: Higher accuracy
      Large h: Faster but less precise

Based on the TU BCA syllabus for Numerical Method (CACS252), unit 4.

Discussion

Loading…