I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
COST (GBP)
this unit 6.00
sub units 0.00
+
0

Akima

Interpolates a given set of points using Akima spline fitting.
Controller: CodeCogs

add cart

Interface

C++
HTML

Class Akima

The original algorithm is based on a piecewise function composed of a set of polynomials, each of degree three, at most,and applicable to successive interval of the given points. In this method, the slope of the curve is determined at each given point locally, and each polynomial representing a portion of the curve between a pair of given points is determined by the coordinates of and the slopes at the points. For more information concerning the algorithm, see references. An important detail when using this class is that the abscissas array given as argument to the constructor needs to be sorted in ascending order.

If you initial data represents maximum and minimums and you are concerned about overshoot (or spurious oscillations) then the Akima method is highly recommended. However it is worth noting that if your data points change abruptly then some small overshoot will still arise.

Below you will find the interpolation graphs for a set of points obtained by evaluating the function f(x) = \sin(2x) / x, displayed in light blue, at particular abscissas. The spline fitting curve, displayed in red, has been calculated using this class. In the first graph there had been chosen a number of 12 points, while in the second 36 points were considered. You may notice the root mean squared error in each of the cases.

1/akima-378.png
+
While the first case, with 12 initial points may be a bad fit to the original signal, this fitting illustrates just how carefully the Akima method tries to avoid overshoot. So in many situation where you have a corse set of data points, the Akima method may provide the best fit. Its important to be aware of the nature of the data you analyzing and how likely sudden changes are.

References:

  • Hiroshi Akima, "A Method of Bivariate Interpolation and Smooth Surface Fitting for Irregularly Distributed Data Points", ACM Transactions on Mathematical Software, Vol. 4, No. 2, June 1978, pp. 148-159. Copyright 1978, Association for Computing Machinery, Inc., reprinted by permission.
  • F.R. Ruckdeschel, "BASIC Scientific Subroutines, Vol. II, BYTE/McGRAWW-HILL, 1981.
  • For a general overview of different approaches see: http://www.kxcad.net/CINEMA_4D/help/US/html/OSPLINEFORMULA-ID_OBJECTPROPERTIES.html

Example 1

The following example displays 20 interpolated values (you may change this amount through the N_out variable) for the given function f(x) with abscissas equally spaced in the [ \pi, 3\pi] interval. The X and Y coordinate arrays are initialized by evaluating this function for N = 12 points equally spaced in the domain from \pi to 5 \pi.
#include <codecogs/maths/approximation/interpolation/akima.h>
 
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;
 
#define PI  3.1415
#define N   12
 
int main()  
{
    // Declare and initialize two arrays to hold the coordinates of the initial data points
    double x[N], y[N];
 
    // Generate the points
    double xx = PI, step = 4 * PI / (N - 1);
    for (int i = 0; i < N; ++i, xx += step) {
        x[i] = xx;
        y[i] = sin(2 * xx) / xx;
    }
 
    // Initialize the Akima spline interpolation routine with known data points
    Maths::Interpolation::Akima A(N, x, y);
 
    // Interrogate spline curve to find interpolated values
    int N_out = 20;
    xx = PI, step = (3 * PI) / (N_out - 1);
    for (int i = 0; i < N_out; ++i, xx += step) {
        cout << "x = " << setw(7) << xx << "  y = ";
        cout << setw(13) << A.getValue(xx) << endl;
  }
    return 0;
}
Output:
x =  3.1415  y = -5.89868e-005
x = 3.63753  y =      0.140177
x = 4.13355  y =      0.181798
x = 4.62958  y =     0.0850367
x = 5.12561  y =     -0.129668
x = 5.62163  y =     -0.157484
x = 6.11766  y =   -0.00477961
x = 6.61368  y =     0.0819989
x = 7.10971  y =     0.0712833
x = 7.60574  y =     0.0445423
x = 8.10176  y =   -0.00985429
x = 8.59779  y =    -0.0801354
x = 9.09382  y =     -0.087151
x = 9.58984  y =     0.0367525
x = 10.0859  y =      0.086111
x = 10.5819  y =     0.0312046
x = 11.0779  y =    -0.0221298
x = 11.5739  y =      -0.04029
x =   12.07  y =    -0.0462165
x =  12.566  y =    -0.0233795

See Also

Also consider the regression methods: Regression/Discrete, Regression/Forsythe, Regression/Orthogonal, Regression/Stiefel

Authors

Lucian Bentea (August 2005)
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

Members of Akima

Akima

 
Akimaintn
double*x
double*y )[constructor]
Initializes the necessary data for following evaluations of the spline.
nThe number of points
xThe x-coordinates of the points
yThe y-coordinates of the points

GetValue

 
doublegetValuedoublex )
Returns the approximated ordinate at the given abscissa.
xThe abscissa of the interpolation point


Akima Once

 
doubleAkima_onceintN
double*x
double*y
doublea )
This function implements the Akima class for one off calculations, thereby avoid the need to instantiate the Akima class yourself.

Example 2

x =  3.1415  y = -5.89868e-005
x = 3.63753  y =      0.140177
x = 4.13355  y =      0.181798
x = 4.62958  y =     0.0850367
x = 5.12561  y =     -0.129668
x = 5.62163  y =     -0.157484
x = 6.11766  y =   -0.00477961
x = 6.61368  y =     0.0819989
x = 7.10971  y =     0.0712833
x = 7.60574  y =     0.0445423
x = 8.10176  y =   -0.00985429
x = 8.59779  y =    -0.0801354
x = 9.09382  y =     -0.087151
x = 9.58984  y =     0.0367525
x = 10.0859  y =      0.086111
x = 10.5819  y =     0.0312046
x = 11.0779  y =    -0.0221298
x = 11.5739  y =      -0.04029
x =   12.07  y =    -0.0462165
x =  12.566  y =    -0.0233795

\graph  N=20, x="3.1 3.6 4.1 4.6 5.1 5.6 6.1 6.6 7.1 7.6 8.1 8.5 9.0 9.5 10 10.5 11 11.5 12 12.5", y="0 0.14 0.18 0.09 -0.12 -0.15 -0.004 0.082 0.7 0.45 -0.009 -0.08 -0.087 0.036 0.86 0.0312 -0.022 -0.04 -0.046 -0.02", a=2:12.5

Parameters

NThe number of initial points
xThe x-coordinates for the initial points (evenly spaced!)
yThe y-coordinates for the initial points
aThe x-coordinate for the output point

Returns

the interpolated y-coordinate that corresponds to a.
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.