def test_HermiteCubic2(self):
     t = [1, 2, 4, 5]
     y = [2, 1, 4, 3]
     interp = Interpolation(t, y)
     exp_coeff = [[1.0, 1.0, 1.38888889, 2.0], [4.0, 4.0, 1.0, 1.0],
                  [3.0, 3.61111111, 4.0, 4.0]]
     exp_interval = [1, 2, 4, 5]
     act_coeff1, act_interval = interp.interpHermiteCubic(t, y)
     #This is done for arranging the coefficients in proper order
     act_coeff = []
     act_coeff.append([])
     act_coeff.append([])
     act_coeff.append([])
     act_coeff[0] = list(np.flip((act_coeff1[:, 0])))
     act_coeff[1] = list(np.flip((act_coeff1[:, 1])))
     act_coeff[2] = list(np.flip((act_coeff1[:, 2])))
     #Checking coefficients
     for i in range(0, len(act_coeff)):
         for j in range(0, len(act_coeff[i])):
             a = exp_coeff[i][j] - act_coeff[i][j]
             b = exp_coeff[i][j]
             assert (div(a, b) <= ADMISS_REL_ERR)
     #checking interval
     for i in range(0, len(act_interval)):
         a = exp_interval[i] - act_interval[i]
         b = exp_interval[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
 def test_Newton1(self):
     t = [0, 1, 2]
     y = [0, 1, 2]
     interp = Interpolation(t, y)
     exp_coeff = [0, 1, 0]
     act_coeff = interp.interpNewton(t, y)
     for i in range(0, len(act_coeff)):
         a = exp_coeff[i] - act_coeff[i]
         b = exp_coeff[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
 def test_Newton2(self):
     t = [-2, 0, 1]
     y = [-27, -1, 0]
     interp = Interpolation(t, y)
     exp_coeff = [-27, 13.0, -4.0]
     act_coeff = interp.interpNewton(t, y)
     for i in range(0, len(act_coeff)):
         a = exp_coeff[i] - act_coeff[i]
         b = exp_coeff[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
 def test_Lagrange2(self):
     t = [-2, 0, 1]
     y = [-27, -1, 0]
     interp = Interpolation(t, y)
     exp_coeff = [-27, -1, 0]
     act_coeff = interp.interpLagrange(t, y)
     print(act_coeff)
     for i in range(0, len(act_coeff)):
         a = exp_coeff[i] - act_coeff[i]
         b = exp_coeff[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
 def test_Monomial2(self):
     t = [-2, 0, 1]
     y = [-27, -1, 0]
     interp = Interpolation(t, y)
     exp_coeff = [-1, 5, -4]
     act_coeff = np.flip(interp.interpMonomial(t, y))
     print(act_coeff)
     for i in range(0, len(act_coeff)):
         a = exp_coeff[i] - act_coeff[i]
         b = exp_coeff[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
    def test_Monomial1(self):

        t = [0, 1, 2]
        y = [0, 1, 2]
        interp = Interpolation(t, y)
        exp_coeff = [0, 1, 0]
        act_coeff = np.flip(interp.interpMonomial(t, y))
        for i in range(0, len(act_coeff)):
            a = exp_coeff[i] - act_coeff[i]
            b = exp_coeff[i]
            assert (div(a, b) <= ADMISS_REL_ERR)
 def test_BSpline(self):
     t = [0.0, 1.2, 1.9, 3.2, 4.0, 6.5]
     y = [0.0, 2.3, 3.0, 4.3, 2.9, 3.1]
     exp_coeff = [0, 2.987, -0.574, 14.670, -10.325, 3.1, 0, 0, 0, 0, 0]
     interp = Interpolation(t, y)
     act_coeff = interp.interpBSpline(t, y)
     #Checking the coefficients
     for i in range(0, len(act_coeff)):
         a = exp_coeff[i] - act_coeff[i]
         b = exp_coeff[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
Ejemplo n.º 8
0
 def test_evalNewton2(self):
     t = [-2, 0, 1]
     y = [-27, -1, 0]
     interp = Interpolation(t, y)
     #From Matlab
     MatlabC = [-27, 13.0, -4.0]
     #Tests coefficients of Newton Polynomial
     PythonC = interp.interpNewton(t, y)
     for i in range(0, len(PythonC)):
         a = PythonC[i] - MatlabC[i]
         b = PythonC[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
 def test_HermiteCubic1(self):
     t = [1, 3]
     y = [2, 1]
     interp = Interpolation(t, y)
     exp_coeff = [2, 1.67, 1.33, 1.0]
     exp_interval = [1, 3]
     act_coeff, act_interval = interp.interpHermiteCubic(t, y)
     #Checking the coefficients
     for i in range(0, len(act_coeff)):
         a = exp_coeff[i] - act_coeff[i]
         b = exp_coeff[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
     #Checking interval information
     for i in range(0, len(act_interval)):
         a = exp_interval[i] - act_interval[i]
         b = exp_interval[i]
         assert (div(a, b) <= ADMISS_REL_ERR)
Ejemplo n.º 10
0
    def test_evalLagrange1(self):

        t = [0, 1, 2]
        y = [0, 1, 2]
        interp = Interpolation(t, y)
        exp_coeff = interpolate.lagrange(t, y)
        act_coeff = np.flip(interp.interpLagrange(t, y))

        # evaluating python object
        yfit_P = exp_coeff(t)

        # evaluating CFS
        yfit = interp.evalLagrange(y, t, t)

        for i in range(0, len(yfit_P)):
            a = yfit[i] - yfit_P[i]
            b = yfit[i]
            assert (div(a, b) <= ADMISS_REL_ERR)
Ejemplo n.º 11
0
    def test_evalMonomial2(self):

        t = [-2, 0, 1]
        y = [-27, -1, 0]
        interp = Interpolation(t, y)
        exp_coeff = interpolate.interp1d(t, y)
        act_coeff = np.flip(interp.interpMonomial(t, y))

        # evaluating python object
        yfit_P = exp_coeff(t)

        # evaluating CFS
        yfit = interp.evalMonomial(np.flip(act_coeff), t)

        for i in range(0, len(yfit_P)):
            a = yfit[i] - yfit_P[i]
            b = yfit[i]
            assert (div(a, b) <= ADMISS_REL_ERR)
Ejemplo n.º 12
0
    def test_HermiteCubic(self):

        t = [1, 2, 4, 5]
        y = [2, 1, 4, 3]
        interp = Interpolation(t, y)
        #This is from Matlab
        exp_coeff = [[0.1667, 0.6667, -1.8333, 2.0000],
                     [-0.7500, 2.2500, 0, 1.0000],
                     [0.1667, -1.1667, 0, 4.0000]]
        act_coeff1, act_interval = interp.interpHermiteCubic(t, y)
        # This is done for arranging the coefficients in proper order
        act_coeff = []
        act_coeff.append([])
        act_coeff.append([])
        act_coeff.append([])
        act_coeff[0] = list(np.flip((act_coeff1[:, 0])))
        act_coeff[1] = list(np.flip((act_coeff1[:, 1])))
        act_coeff[2] = list(np.flip((act_coeff1[:, 2])))

        for i in range(0, len(act_coeff)):
            for j in range(0, len(act_coeff[i])):
                a = act_coeff[i][j] - exp_coeff[i][j]
                b = act_coeff[i][j]
                assert (div(a, b) <= ADMISS_REL_ERR)
Ejemplo n.º 13
0
#         Most of them are implemented from scratch, so they are compared against python.
#         Some of them use python libraries, for which Matlab is used to verify correctness.
#  @date 22/12/2018

from scipy import interpolate
import numpy as np
from pytest import *
from src.Interpolation import Interpolation
from src.Regression import Regression
from src.Input import Input

ADMISS_REL_ERR = 1e-1

t = [0, 1, 2, 3]
y = [0, 1, 2, 3]
interp = Interpolation(t, y)


## @brief This method takes care of division by zero
#  @details If denominator is 0, we assume div(a/b) = 0
def div(a, b):
    if b == 0:
        ans = 0
    else:
        ans = a / b
    return ans


## @brief This gives the list of test cases for Correctness.
#  @see {test_interpolation.py}
#  @return none