Technology

Approximation of derivatives using finite difference methods

2025-05-09 03:40:39


This post is part of a series of articles on the Finite Difference Method, with other posts in the series focusing on solving the heat equation/diffusion equation explicitly, the implicit Crank-Nicolson method, and solving tridiagonal matrix systems using Thomas's algorithm.

  • Approximation of derivatives using finite difference methods
  • Explicit method for solving the diffusion equation
  • Implicit Crank-Nicolson method
  • Solving a tridiagonal matrix system using Thomas's algorithm


This is the first part of a multi-part series of articles on using the Finite Difference Method (FDM) to solve parabolic partial differential equations numerically. Specifically, it will focus on solving the heat equation, as the Black-Scholes pricing equation can be transformed into the form of the heat equation. These methods can therefore be used to numerically solve the aforementioned equation.

If we define

fff is a continuous function of real numbers that has a second derivative. The heat equation of f will be:

∂t∂u​=α∂x2∂2uIt seems your message is empty. Could you please provide the text you'd like me to translate?



Discretising Derivatives

The finite difference method provides a numerical alternative for solving this equation by discretizing the derivative. The Taylor series will be used to approximate the derivative.

Consider that the Taylor series provides the value of the function

f when the variable is changed by an amount Δx as follows:

f(x+Δx)=f(x)+Δxf′(x)+2!Δx²f′′(x)+3!Δx³f(3)(x)+⋯


Where

... substitute the additional term limited by a constant multiplied by Δxn in the same manner, you can find the value

f(x−Δx) can be obtained from:

f(x−Δx)=f(x)−Δxf′(x)+2!Δx²f''(x)−3!Δx³f(3)(x)+⋯


When rearranged, these two equations yield the first derivative approximation of f:

f′(x)≈Δxf(x+Δx)−f(x)​(Forward Difference)

f′(x)≈Δxf(x)−f(x−Δx)​(Backward Difference)


Furthermore, when the equation at the back is subtracted from the equation at the front, it yields a second-order approximation of the first derivative of fff:

f′(x)≈2Δxf(x+Δx)−f(x−Δx) (Centered Difference)


If you want to approximate the second derivative of f, which is f′′(x), you can add the two Taylor equations together. You will get:

f′′(x)≈(Δx)²f(x+Δx)−2f(x)+f(x−Δx) (Centered Second Difference)



Domain Discretisation

After making the derivative discontinuous in the one-dimensional context, the next step is to make the domain of the heat equation discontinuous.

The function u is now a function of two real variables, x and t, which represent position and time, respectively. Therefore, the function u(x,t) can be interpreted as the amount of heat at a specific point along a one-dimensional steel rod.

We can divide the one-dimensional steel bar into N points xi and the time into M points tn, using a constant time interval Δt between each time period.

The approximation uin of u(xi​,tn) is given by:

uin​≈u(xi​,tn)


where the index on n does not mean the power of u or the nth derivative, but rather the value of the function u at time tn

Therefore, the aforementioned derivative approximation can be expressed in the form of a finite difference as:

Forward difference (time):

 ∂t∂u​≈Δtuin+1​−uin​


Backward difference (time):

∂t∂u​≈Δtuin​−uin−1​​


Centered difference (area):

 ∂x∂u​≈2Δxui+1n​−ui−1n​​


Centered second difference (area):

 ∂x2∂2u​≈(Δx)2ui+1n​−2uin​+ui−1n​​



Errors and Conclusion

When these differences are natural approximations, we should question how errors might occur in the overall answer.

Generally, the errors that occur can be divided into two types:

  • Truncation Error – The error that occurs from truncating higher-order derivative terms in a Taylor expansion
  • Roundoff Error – The error from rounding or the precision of the computer. Typically, double precision floating-point numbers are used, which can store 16 digits.This error can accumulate, especially if using single precision, which only stores 8 digits.



In the next article, the heat equation will be solved using numerical methods, and we will see that truncation errors can accumulate rapidly if appropriate conditions are not set.




Reference: Derivative Approximation via Finite Difference Methods

From https://www.quantstart.com/articles/Derivative-Approximation-via-Finite-Difference-Methods/

Leave a comment :