# File: dftBvp.py # Author: Ian May # Purpose: Define a brief spectral collocation method for the # shifted Poisson equation. Written primarily to # showcase basic numpy usage import numpy as np # Define spatial grid def grid(N): return np.linspace(0,2*np.pi,N,endpoint=False) # Define wavenumbers and forward transform def transMat(x): N = len(x) dx = x[1]-x[0] om = 2*np.pi/(N*dx) # Set wavenumbers and transformation matrix k = np.zeros(N) T = np.zeros([N,N]) T[0,:] = 1./N for i in np.arange(1,N,2): k[i] = (i+1)*om/2 T[i,:] = 2*np.cos(k[i]*x)/N if(i+1