CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

MathsInterpolation

Akima

Only available under a commercial licence
COST (GBP)
this unit 7.80
sub units 0.00
add a commercial licence to your cart
0
viewed 6270 times and licensed 21 times

Interpolates a given set of points using Akima spline fitting.

Controller: CodeCogs  Contact Controller
+View other versions (4)
Contents hide toc
buy now     add cart

Interface

#include <codecogs/maths/interpolation/akima.h>

using namespace Maths::Interpolation;

class Akima
Interpolates a given set of points using Akima spline fitting.
[constructor]Akima (int n, double *x, double *y)
Class constructor
[destructor]~Akima ()
Class destructor
doublegetValue (double x)
Returns an interpolated value.
double*m_x
double Akima_once (int N, double *x, double *y, double a)
A static function implementing the Akima Class for one off calculations

Class Documentation

 
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:

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/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:

To view or download source code you need to buy a Commercial licence.

buy now     add cart

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

Members of Akima

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

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


Function Documentation

Akima Once Calculator
  
Add calculator to website or email
 
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:
reveal hidden layerThe following graph is constructed from interpolating the following values:

\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:

To view or download source code you need to buy a Commercial licence.

buy now     add cart

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


Page Comments

apertosa\′s Photo
22 Apr 08, 11:10PM
(1 reply)
linear extrapolation
A suggestion would be to linearly extrapolate when the abscissa point is out of bounds (< first point or > last point). Can this module be modified to include that? I can post a suggestion if someone is willing to code review it. Thanks, Andrea.
will\′s Photo
23 Apr 08, 11:41PM
Technically this is an interpolation function; so shouldn't be used out of bounds. Thats what the regression functions are used for - i.e. make a prediction beyond existing data range.

That said, I personally feel these distinctions are blurred anyway, so you idea to use linear extrapolate (presumably based on the nearest two points at the gradient formed) would be a good idea. So long as the checks don't severely retard performance.

I'll be very happy to review your code.
apertosa\′s Photo
18 Apr 08, 8:48PM
(1 reply)
issue with x=0?
Hello, looking at the code I see the following:

double getValue(double x) { if (x == 0.0) return 0.0; ....

Now it seems that if the desired X is zero then the returned interpolated value will also be zero. That is not necessarily true, it depends on the input entries. If the x-y curve does not go through zero then that answer will be incorrect. Can someone verify that? I used the calc applet on this page and with my simple example I see that a value of 0.0 always returns 0.0 even when it is clearly wrong.

Please let me know. Thanks, Andrea.

will\′s Photo
19 Apr 08, 11:37AM
I agree. This first line isn't necessary. I've taken it out. The calc aplet will recompile in the next 12hrs.

Thanks for picking this up.
Format Excel Equations

  You must login to leave a messge


Last Modified: 19 Apr 08 @ 19:53     Page Rendered: 2010-03-11 17:38:59

Valid CSS!   Valid XHTML 1.0 Transitional