Function Interpolation with known
Function interpolation with known piecewise averages
In a typical interpolation problem, values are estimated within a discrete set of known data points. Recently, we had to “interpolate” a function from which we only knew the averages at certain time intervals. A set of known data points was not available and regular interpolation techniques could not be applied. This post explains the solution that we implemented by way of an example.
Solution outline for function interpolation with known piecewise averages
The example used to illustrate the interpolation methodology is based on a small photovoltaic power plant. The hourly average generation for a given day is shown in Table 1.
|Hour of the day||Average generation (kW)|
The target function is the power plant’s production curve on a minute-by-minute resolution. Note that the measured power curve is only available on an hourly basis.
The subsequent steps are followed to interpolate the power generation data:
- Calculate the cumulative function. This is equivalent to cumulative generation in our example (see Table 2). Note that 1 kWh is the energy generated by a power plant producing 1 kW during 1 hour. For example, the total generation until 10am was 2.5kWh (0.5kWh generated between 8:00 and 9:00 and 2.0kWh generated between 9:00 and 10:00am).
- Interpolate the cumulative function. Standard interpolation techniques can be applied to the cumulative function as a set of data points are known. For example, we know that the cumulative generation equals 0.5kWh at 9:00.
- Differentiate the interpolated cumulative function to obtain the target function. As the cumulative function is the integral (or sum) of the target function, the target function is the derivative of the cumulative function.
|Time of the day||Cumulative generation (kWh)|
A third-order spline interpolation was applied to the solar PV cumulative values in Table 2. Given that a third order Spline interpolation is twice differentiable, its derivative, the target function of our example, is continuous and differentiable. The result for the target function compared to the original hour-by-hour data can be seen in the figure below.
Example code implementation in Python
An example code implementation in Python is as follows.
# 0. Start by importing Numpy and interpolate from Scipy import numpy as np from scipy import interpolate # 1. Get cumulative function cumulative_generation = np.array([0, 0.5, 2.5, 7.5, 15.5, 25.5, 35.5, 45, 53.5, 60.5, 65.5, 67.5]) hours = np.arange(8, 20) # 2. Interpolate the cumulative function (Spline interpolation) interpolator = interpolate.CubicSpline(hours, cumulative_generation) # 3. Differentiate and substitute. # For example, differentiate and interpolate the power at 10am: print(interpolator(10, 1)) # 3.37 is the output of the interpolation at 10am.
Check out some of our other blogs. At Evergreen Innovations , we have extensive experience in data analytics and numerical analysis. If you have any questions or there any data analytics topic that you would like us to cover, just contact us.