简体   繁体   English

Python 中的移位切比雪夫多项式

[英]Shifted Chebyshev polynomials in Python

I am trying to extract the coefficients of a shifted Chebyshev Polynomial in Python, but I couldn't find the function to do that.我试图在 Python 中提取移位切比雪夫多项式的系数,但我找不到 function 来做到这一点。

There is this function:有这个function:

scipy.special.eval_sh_chebyt

scipy.special.eval_sh_chebyt(n, x, out=None) = <ufunc 'eval_sh_chebyt'>

but I can't extract only the coefficients.但我不能只提取系数。

The shifted Chebyshev polynomials are: T^{*}_n(x) = T_n (2x -1)移位的切比雪夫多项式为: T^{*}_n(x) = T_n (2x -1)

and then:接着:

T_1^{*}(x) = 2x - 1 T_1^{*}(x) = 2x - 1

T_2^{*}(x) = 8x^2 - 8x -1 T_2^{*}(x) = 8x^2 - 8x -1

I would like to extract a matrix only with the coefficients, like 2 and 1 or 8,8 and 1.我想仅使用系数提取矩阵,例如 2 和 1 或 8,8 和 1。

scipy.special.eval_sh_chebyt evaluates the function T* at a given point x . scipy.special.eval_sh_chebyt在给定点x评估 function T* Unless you are very smart in choosing your arguments, this is not an appropriate way to get the coeffcients.除非您在选择 arguments 时非常聪明,否则这不是获取系数的合适方法。

You can instead calculate the coefficients directly from the recurrence formula T0 = 1, T1 = x, T{n} = 2xT{n-1} - T{n-2} .您可以直接从递归公式T0 = 1, T1 = x, T{n} = 2xT{n-1} - T{n-2}计算系数。 And then calculate the shifted polynomials from _T*{n} = T{n}(2x - 1).然后从 _T*{n} = T{n}(2x - 1) 计算移位多项式。

degree = 10

coeffs = []
# for T_0
coeffLine = [1]
coeffs.append(coeffLine)
# for T_1
coeffLine = [0, 1]
coeffs.append(coeffLine)

for i in range(2, degree + 1):
    coeffLine = [0] * (1 + i)
    coeffLine[0] = -coeffs[i - 2][0]
    for j in range(1, i - 1):
        coeffLine[j] = 2 * coeffs[i - 1][j - 1] - coeffs[i - 2][j]
    coeffLine[-2] = 2 * coeffs[i - 1][-2]
    coeffLine[-1] = 2 * coeffs[i - 1][-1]
    coeffs.append(coeffLine)        

print("T_%d" % degree, coeffs[-1])

shiftedCoeffs = [0] * (degree + 1);
for i in range(degree + 1):
    binom = 1
    for j in range(i + 1):
        shiftedCoeffs[i - j] += coeffs[-1][i] * 2 ** (i - j) * (-1) ** j * binom
        binom *= (i - j) / (j + 1)


print("T*_%d" % degree, shiftedCoeffs)

Edit: I originally misread the formula for T*{n} as _T{n}(x) * (2x - 1).编辑:我最初将T*{n}的公式误读为 _T{n}(x) * (2x - 1)。 However it is T*{n} = T{n}(2x - 1) .但是它是T*{n} = T{n}(2x - 1) We therefore need to calculate the binomial coefficients sum them up depending on the order of x .因此,我们需要根据x的阶数计算二项式系数的总和。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM