1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| from numpy.linalg import solve import numpy as np
def Normal_Grid_Coefficients(N, diff_order = 2): """ Coefficients of arbitrary even order Taylor expansion when the discrete values are at integral grid point. Such as for normal grid second-order acoustic forward modeling. Parameters: ---------- N : Half-order of Taylor expansion or the length of unilateral operator. diff_order : Not used in this method. Just for notice. Returns: ---------- out : 1-D ndarray. The length of output is (2*N+1) with the first coefficient is C0. """ holder = [] for i in range(N): matrix = [] for j in range(N): matrix.append(np.power((i+1)**j, 2)) holder.append(matrix) holder = np.array(holder).T constant = np.zeros(N) constant[0] = 1.0 x = solve(holder, constant) t1 = 0 for i in range(N): x[i] = x[i]/np.power(i+1, 2) t1+=x[i] coes = np.zeros(N+1) coes[0] = -2*t1 coes[1:len(coes)] = x return coes
|