Computational Fluid Dynamics - Elementary (b)


Interpolation is a process of defining a function to find new point(s) within the range of a discrete set of known data points. Using interpolation, we can describe or at least approximate the function at every point in space.

Linear interpolation

Linear interpolation is obtained by passing a straight line between 2 data points. Fig. c.1 illustrates the linear interpolation between the data points $ x_0 $ and $ x_1 $ of a function $ f(x) $ and $ g(x) $ is the linearly interpolated approximation to $ f(x) $.

Fig. c.1: Linear interpolation.

If $ g(x) $ is a linear function, then:
\begin{equation} g(x) = Ax + B; \end{equation} where $ A $ and $ B $ are unknown coefficients. To pass through points $(x_0, f(x_0))$ and $(x_1, f(x_1))$ we should have:
\begin{equation} \begin{aligned} & Ax_0 + B = f(x_0); \\ & Ax_1 + B = f(x_1). \end{aligned} \end{equation} Solving this system of equations leads to the following results:
\begin{equation} \begin{aligned} & A = \frac{f(x_1) - f(x_0)}{x_1 - x_0}; \\ & B = \frac{f(x_0)x_1 - f(x_1)x_0}{x_1 - x_0}. \end{aligned} \end{equation} Substituting for $ A $ and $ B $ into the Eq. (1), we have:
\begin{equation} g(x) = f(x_0)\frac{x_1 - x}{x_1 - x_0} + f(x_1)\frac{x - x_0}{x_1 - x_0}. \end{equation} This is the formula for linear interpolation.

Other types of interpolations can be found as follows:

(1) Lagrange interpolation;
(2) Spline interpolation;
(3) Least squares method.

The relevant Matlab codes can be downloaded using the following link:
Matlab Codes Bank

No comments:

Post a Comment