diff --git a/Vectors_of_Polynomials.py b/Vectors_of_Polynomials.py new file mode 100644 index 0000000000000000000000000000000000000000..4301f4b4ac5be7952cdd4d37fae7d37dd30f1c40 --- /dev/null +++ b/Vectors_of_Polynomials.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- +""" +@author: Laura C. Kühle + +""" +import numpy as np + +class Vector(object): + + def __init__(self, polynom_degree): + self.polynom_degree = polynom_degree + pass + + def get_vector(self): + pass + + +class Legendre(Vector): + + def get_vector(self, eval_point): + vector = self._calculate_legendre_vector(eval_point) + return vector + + def _calculate_legendre_vector(self, eval_point): + vector = [] + for degree in range(self.polynom_degree+1): + if (degree == 0): + vector.append(1.0 + 0*eval_point) + else: + if (degree == 1): + vector.append(eval_point) + else: + poly = (2.0*degree - 1) / degree\ + * eval_point * vector[len(vector)-1]\ + - (degree-1) / degree * vector[len(vector)-2] + vector.append(poly) + return vector + + +class OrthonormalLegendre(Legendre): + + def get_vector(self, eval_point): + leg_vector = self._calculate_legendre_vector(eval_point) + vector = [leg_vector[degree] * np.sqrt(degree+0.5) + for degree in range(len(leg_vector))] + return vector + + +class AlpertsWavelet(Vector): + + def get_vector(self, eval_point): + degree = self.polynom_degree + + if (degree == 0): + return [np.sqrt(0.5) + eval_point*0] + if (degree == 1): + return [np.sqrt(1.5) * (-1 + 2*eval_point), + np.sqrt(0.5) * (-2 + 3*eval_point)] + if (degree == 2): + return [1/3 * np.sqrt(0.5) + * (1 - 24*eval_point + 30*(eval_point**2)), + 1/2 * np.sqrt(1.5) + * (3 - 16*eval_point + 15*(eval_point**2)), + 1/3 * np.sqrt(2.5) + * (4 - 15*eval_point + 12*(eval_point**2))] + if (degree == 3): + return [np.sqrt(15/34) * (1 + 4*eval_point + - 30*(eval_point**2) + 28*(eval_point**3)), + np.sqrt(1/42) * (-4 + 105 * eval_point + - 300*(eval_point**2) + 210*(eval_point**3)), + 1/2 * np.sqrt(35/34) * (-5 + 48*eval_point + - 105*(eval_point**2) + 64*(eval_point**3)), + 1/2 * np.sqrt(5/34) * (-16 + 105*eval_point + - 192*(eval_point**2) + 105*(eval_point**3))] + if (degree == 4): + return [np.sqrt(1/186) * (1 + 30*eval_point + 210*(eval_point**2) + - 840*(eval_point**3) + 630*(eval_point**4)), + 0.5 * np.sqrt(1/38) * (-5 - 144*eval_point + + 1155*(eval_point**2) - 2240*(eval_point**3) + + 1260*(eval_point**4)), + np.sqrt(35/14694) * (22 - 735*eval_point + + 3504*(eval_point**2) - 5460*(eval_point**3) + + 2700*(eval_point**4)), + 1/8 * np.sqrt(21/38) * (35 - 512*eval_point + + 1890*(eval_point**2) - 2560*(eval_point**3) + + 1155*(eval_point**4)), + 0.5 * np.sqrt(7/158) * (32 - 315*eval_point + + 960*(eval_point**2) - 1155*(eval_point**3) + + 480*(eval_point**4))] + + raise ValueError('Invalid value: Albert\'s wavelet is only available \ + up to degree 4 for this application') + return 0