Example #1
0
def roots(coeffs):
    '''Find roots of polynomial specified by coefficients
    '''
    poly = _poly(_asDS(
        coeffs, _dnp.float64)._jdataset().data)  # static method call fails
    return _asDS(poly.findRoots()
                 )  # cannot rely on general wrapper with arrays of stuff
Example #2
0
def polyval(p, x):
    '''Evaluate polynomial at given points
    If p is of length N, this function returns the value:
    p[0]*(x**N-1) + p[1]*(x**N-2) + ... + p[N-2]*x + p[N-1]
    '''
    poly = _poly(_asDS(p, _dnp.float64)._jdataset().data)
    d = _asDS(x, _dnp.float, force=True)._jdataset()
    return poly.calculateValues([d])
Example #3
0
def polyval(p, x):
    '''Evaluate polynomial at given points
    If p is of length N, this function returns the value:
    p[0]*(x**N-1) + p[1]*(x**N-2) + ... + p[N-2]*x + p[N-1]
    '''
    poly = _poly(_asDS(p, _dnp.float64)._jdataset().data)
    d = _asDS(x, _dnp.float, force=True)._jdataset()
    return poly.calculateValues([d])
Example #4
0
 def __init__(self, c_or_r, r=False, variable=None):
     if variable:
         self.variable = variable
     else:
         self.variable = 'x'
     if r:
         self.order = len(c_or_r)
         # expansion of factors
         self.c = _polycoeff(c_or_r)
         self.roots = c_or_r
     else:
         self.order = len(c_or_r) - 1
         self.c = c_or_r
         self.roots = None
     self._poly = _poly(self.c)
Example #5
0
 def __init__(self, c_or_r, r=False, variable=None):
     if variable:
         self.variable = variable
     else:
         self.variable = 'x'
     if r:
         self.order = len(c_or_r)
         # expansion of factors
         self.c = _polycoeff(c_or_r)
         self.roots = c_or_r
     else:
         self.order = len(c_or_r) - 1
         self.c = c_or_r
         self.roots = None
     self._poly = _poly(self.c)
Example #6
0
def polyfit(x, y, deg, rcond=None, full=False):
    '''Linear least squares polynomial fit

    Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of order deg to points (x, y).
    Arguments:
    x   -- x-coordinates of sample points
    y   -- y-coordinates of sample points
    deg -- order of fitting polynomial
    
    Returns:
    a vector of coefficients p that minimises the squared error and
    a fitresult object
    '''
    poly = _poly(deg)
    x = _asIterable(x)
    if rcond is None:
        rcond = 2e-16 * y.size
    _fitter.polyFit(x, y, rcond, poly)
    fr = fitresult(poly, x, y)
    if full:
        return fr.parameters, fr
    else:
        return fr.parameters
Example #7
0
def polyfit(x, y, deg, rcond=None, full=False):
    '''Linear least squares polynomial fit

    Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of order deg to points (x, y).
    Arguments:
    x   -- x-coordinates of sample points
    y   -- y-coordinates of sample points
    deg -- order of fitting polynomial
    
    Returns:
    a vector of coefficients p that minimises the squared error and
    a fitresult object
    '''
    poly = _poly(deg)
    x = _asIterable(x)
    if rcond is None:
        rcond = 2e-16*y.size
    _fitter.polyFit(x, y, rcond, poly)
    fr = fitresult(poly, x, y)
    if full:
        return fr.parameters, fr
    else:
        return fr.parameters
Example #8
0
def roots(coeffs):
    '''Find roots of polynomial specified by coefficients
    '''
    poly = _poly(_asDS(coeffs, _dnp.float64)._jdataset().data) # static method call fails
    return _asDS(poly.findRoots()) # cannot rely on general wrapper with arrays of stuff