def coeffmult(fc, gc): """Coefficient-Space multiplication of equal-length first-kind Chebyshev series.""" Fc = np.append(2. * fc[:1], (fc[1:], fc[:0:-1])) Gc = np.append(2. * gc[:1], (gc[1:], gc[:0:-1])) ak = ifft(fft(Fc) * fft(Gc)) ak = np.append(ak[:1], ak[1:] + ak[:0:-1]) * .25 ak = ak[:fc.size] inputcfs = np.append(fc, gc) out = np.real(ak) if np.isreal(inputcfs).all() else ak return out
def coeffmult(fc, gc): """Coefficient-Space multiplication of equal-length first-kind Chebyshev series.""" Fc = np.append( 2.*fc[:1], (fc[1:], fc[:0:-1]) ) Gc = np.append( 2.*gc[:1], (gc[1:], gc[:0:-1]) ) ak = ifft( fft(Fc) * fft(Gc) ) ak = np.append( ak[:1], ak[1:] + ak[:0:-1] ) * .25 ak = ak[:fc.size] inputcfs = np.append(fc, gc) out = np.real(ak) if np.isreal(inputcfs).all() else ak return out
def coeffs2vals2(coeffs): """Map first-kind Chebyshev polynomial coefficients to function values at Chebyshev points of 2nd kind""" n = coeffs.size if n <= 1: vals = coeffs return vals coeffs = coeffs.copy() coeffs[1:n - 1] = .5 * coeffs[1:n - 1] tmp = np.append(coeffs, coeffs[n - 2:0:-1]) if np.isreal(coeffs).all(): vals = fft(tmp) vals = np.real(vals) elif np.isreal(1j * coeffs).all(): vals = fft(np.imag(tmp)) vals = 1j * np.real(vals) else: vals = fft(tmp) vals = vals[n - 1::-1] return vals
def coeffs2vals2(coeffs): """Map first-kind Chebyshev polynomial coefficients to function values at Chebyshev points of 2nd kind""" n = coeffs.size if n <= 1: vals = coeffs return vals coeffs = coeffs.copy() coeffs[1:n-1] = .5 * coeffs[1:n-1] tmp = np.append( coeffs, coeffs[n-2:0:-1] ) if np.isreal(coeffs).all(): vals = fft(tmp) vals = np.real(vals) elif np.isreal(1j*coeffs).all(): vals = fft(np.imag(tmp)) vals = 1j * np.real(vals) else: vals = fft(tmp) vals = vals[n-1::-1] return vals