def init(D, N, M):

    # D-dimensional nodes for interval [-1,1]

    nu = np.empty(M)
    for k, nuk in enumerate(nu):
        nuk = -math.cos((2 * k - 1) * math.pi / (2 * M))

    # create a matrix that contains all possible length D product of nodes in each row

    prod = itertools.product(nu, repeat=D)

    X = np.empty(pow(M, D) * D)
    X.shape = (pow(M, D), D)
    for i, row in enumerate(prod):
        X[i] = row

    # create a matrix B, which contains vector of polynomials in each row

    B = chebypol(N, nu)

    # create a matrix T, where each row represents all possible tensor products

    T = B
    for i in range(D - 1):
        T = np.kron(T, B)

    return [X, T]
示例#2
0
def approx(x,f,D,N,M,a,b):
    
    theta = coef(f,D,N,M,a,b)
    norm_x = - 1 + 2 * (x - a) / (b - a)
    B = chebypol(N, x)
    
    T = B
    for i in range(D - 1):
        T = np.kron(T, B)
        
    p =  np.dot(T, theta)
    return p
def approx(x,f,D,N,M,a,b):
    
    theta = coef(f,D,N,M,a,b)
    norm_x = - 1 + 2 * (x - a) / (b - a)
    B = chebypol(N, norm_x)
    
    T = B
    for i in range(D - 1):
        T = np.kron(B, T)
    
    if D == 1:
        j = 1
    else:
        k = 1
        A = []    
        while k <= D - 2:
            A.append(k * pow(D, D - k - 1))
            k = k + 1
        j = sum(A) + D
        
    t = T[j - 1]
        
    p =  np.dot(t, theta)
    return p