Esempio n. 1
0
def bessi(n, x):
    """Modified Bessel function I-sub-n(x). 
    @see: NRP 6.5
    
    @param n: integer, more than 1 - modified n-th Bessel function 
    @param x: positive integer
    @return: modified n-th Bessel function of x
    """
    iacc = 40.0
    bigno = 1.0e10
    bigni = 1.0e-10
    if n < 2:
        raise FunctionParameterValueError('n must be more than 1 - use \
            bessi0 or bessi1 for n = 0 or 1 respectively')
    else:
        if x == 0.0: ans = 0.0
        else:
            ans = 0.0
            tox = 2.0 / float((x))
            bip = 0.0
            bi = 1.0
            m = 2 * (n + math.floor(math.sqrt(iacc * n)))
            for j in range(int(m), 1, -1):
                bim = bip + j * tox * bi
                bip = bi
                bi = bim
                if abs(bi) > bigno:
                    ans = ans * bigni
                    bi = bi * bigni
                    bip = bip * bigni
                if j == n: ans = bip
            if x < 0.0 and (n % 2) == 1: ans = -ans
            return ans * bessi0(x) / (float(bi))
Esempio n. 2
0
 def changeDatum(self, name, observation, newvalue):
     '''
     Change the value of a datum in a data series.
     
     @param name: Name of data series
     @type name: string
     @param observation: Observation number to change (starting count = 1)
     @type observation: integer
     @param newvalue: new value for the observation
     '''
     observation = int(observation)
     if not self.has_series(name):
         raise FunctionParameterValueError('Unknown data series: ' +
                                           str(name))
     if observation > len(self.data[name]):
         raise FunctionParameterValueError('Unknown observation: ' + \
                                           str(observation))
     self.data[name][observation - 1] = newvalue
Esempio n. 3
0
 def getSeries(self, name):
     '''
     Get values of a data series.
     
     @param name: Name of data series
     @type name: string
     @return: List of data
     '''
     if self.has_series(name):
         return self.data[name]
     else:
         raise FunctionParameterValueError('Unknown data series: ' +
                                           str(name))
Esempio n. 4
0
def bessj(n, x):
    """Bessel function J-sub-n(x). 
    @see: NRP 6.5
    
    @param x: float number
    @return: float number 
    """
    iacc = 40.0
    bigno = 1.0e10
    bigni = 1.0e-10
    if n < 2:
        raise FunctionParameterValueError('n must be more than 1 - use \
            bessj0 or bessj1 for n = 0 or 1 respectively')
    if x == 0.0: ans = 0.0
    else:
        if abs(x) > 1.0 * n:
            tox = 2.0 / abs(x)
            bjm = bessj0(abs(x))
            bj = bessj1(abs(x))
            for j in range(1, n):
                bjp = j * tox * bj - bjm
                bjm = bj
                bj = bjp
            ans = bj
        else:
            tox = 2.0 / abs(x)
            m = int(2 * ((n + math.floor(math.sqrt(1.0 * (iacc * n)))) % 2))
            ans = 0.0
            jsum = 0.0
            sum = 0.0
            bjp = 0.0
            bj = 1.0
            for j in range(m, 1, -1):
                bjm = j * tox * bj - bjp
                bjp = bj
                bj = bjm
                if abs(bj) > bigno:
                    bj = bj * bigni
                    bjp = bjp * bigni
                    ans = ans * bigni
                    sum = sum * bigni
                if jsum <> 0: sum = sum + bj
                jsum = 1 - jsum
                if j == n: ans = bjp
            sum = 2.0 * sum - bj
            print sum, ans
            ans = ans / sum
        if x < 0.0 and (n % 2) == 1: ans = -ans
        return ans
Esempio n. 5
0
def bessk(n, x):
    """Bessel function K-sub-n(x). @see: NRP 6.5
    
    @param n: integer, more than 1 - modified n-th Bessel function 
    @param x: positive integer
    @return: modified n-th Bessel function of x
    """
    if n < 2:
        raise FunctionParameterValueError('''n must be more than 1 - \
            use bessk0 or bessk1 for n = 0 or 1 respectively''')
    else:
        tox = 2.0 / x
        bkm = bessk0(x)
        bk = bessk1(x)
        for j in range(1, n):
            bkp = bkm * j * tox * bk
            bkm = bk
            bk = bkp
        return bk
Esempio n. 6
0
 def changeDataType(self, name, type='float'):
     '''
     Change the data type for a data series
     
     @param name: Name of data series
     @type name: string
     @param type: Type of data to cast data series into. Allowable = {float |
     integer | string | long}. Default = float
     '''
     if type == 'float':
         self.data[name] = [float(x) for x in self.data[name]]
     elif type == 'integer':
         self.data[name] = [int(x) for x in self.data[name]]
     elif type == 'string':
         self.data[name] = [str(x) for x in self.data[name]]
     elif type == 'long':
         self.data[name] = [long(x) for x in self.data[name]]
     else:
         raise FunctionParameterValueError('Unknown data type: ' +
                                           str(type))
Esempio n. 7
0
def bessy(n, x):
    """Bessel function Y-sub-n(x). 
    @see: NRP 6.4
    
    @param n: integer, more than 1 - n-th Bessel function 
    @param x: positive integer
    @return: n-th Bessel function of x
    """
    if n < 2:
        raise FunctionParameterValueError('n must be more than 1 - \
            use bessy0 or bessy1 for n = 0 or 1 respectively')
    else:
        tox = 2.0 / x
        by = bessy1(x)
        bym = bessy0(x)
        for j in range(1, n):
            byp = j * tox * by - bym
            bym = by
            by = byp
        return by
Esempio n. 8
0
 def addData(self, data, label=[]):
     '''
     Method to add data into the data series. If provided, the number 
     of elements in data and label have to be the same. However, the 
     labels need not be unique (duplicated labels are allowed) but this 
     is highly undesirable as it can cause issues which requires unique 
     labels.
     
     @param data: list of data values.
     @type data: list
     @param label: list of labels for the data values. If not given, 
     a sequential number will be given as label but this does not ensure 
     uniqueness in label names across the entire series.
     @type label: list
     '''
     if len(label) == 0:
         label = range(len(data))
     if len(data) != len(label):
         raise FunctionParameterValueError()
     for i in range(len(data)):
         self.data.append(data[i])
         self.label.append(label[i])
Esempio n. 9
0
def chebev(a, b, c, m, x):
    """Chebyshev evaluation.
    @see: NRP 5.6
    
    @param a: float number
    @param b: float number
    @param c: list of Chebyshev coefficients produced by chebft with the 
    same 'a' and 'b'
    @param m:
    @param x: 
    @return: float number - function value   
    """
    if (x - a) * (x - b) > 0.0:
        raise FunctionParameterValueError('x must be between a and b')
    else:
        d, dd = 0.0, 0.0
        y = (2.0 * x - a - b) / (b - a)
        y2 = 2.0 * y
        for i in range(m, 0, -1):
            sv = d
            d = y2 * d - dd + c[i]
            dd = sv
        return y * d - dd + 0.5 * c[0]