在Python中使用NumPy对切比雪夫级数进行积分并设置积分顺序

在Python中使用NumPy对切比雪夫级数进行积分并设置积分顺序

在这篇文章中,我们将讨论如何在Python和NumPy中对切比雪夫级数进行积分并设置积分的顺序。

chebyshev.chebint 方法

切比雪夫多项式在近似理论中意义重大,因为切比雪夫节点被用作优化多项式插值的匹配点。为了进行切比雪夫积分,NumPy提供了一个名为Chebyshev.chebint()方法的函数,用于对给定阶数的切比雪夫数列进行积分。它需要两个参数,第一个是c,需要一个数组,第二个是m,用来设置积分顺序。

语法: chebyshev.chebint(c,m)

参数:

  • c: 一个数组
  • m:整合的顺序。

返回:积分的切比雪夫级数系数。

示例 1:

在这个例子中,我们将创建一个有6个元素的一维NumPy系数数组,并通过设置3,4,1,和6的阶数来进行积分。

# import the numpy module
import numpy
  
# import chebyshev
from numpy.polynomial import chebyshev
  
# Create an array of Chebyshev series 
# coefficients with 6 elements
coefficient_array = numpy.array([1,2,3,4,3,5])
  
# display array
print("Coefficient array: ", coefficient_array)
  
# display the dimensions
print("Dimensions: ", coefficient_array.ndim)
  
# integrate chebyshev series with order 3
print("\nChebyshev series with order 3", 
      chebyshev.chebint(coefficient_array, m = 3))
  
# integrate chebyshev series with order 4
print("\nChebyshev series with order 4",
      chebyshev.chebint(coefficient_array, m = 4))
  
# integrate chebyshev series with order 1
print("\nChebyshev series with order 1",
      chebyshev.chebint(coefficient_array, m = 1))
  
# integrate chebyshev series with order 6
print("\nChebyshev series with order 6",
      chebyshev.chebint(coefficient_array, m = 6))

输出 :

Coefficient array: [1 2 3 4 3 5]

Dimensions: 1

Chebyshev series with order 3 [ 0.08072917 0. 0.08854167 -0.01458333 -0.00104167 -0.00625

-0.00699405 0.00178571 0.00186012]

Chebyshev series with order 4 [ 0.00390625 0.03645833 0.00364583 0.01493056 -0.00104167 0.00059524

-0.00066964 -0.00063244 0.00011161 0.00010334]

Chebyshev series with order 1 [ 0.04166667 -0.5 -0.5 0. -0.125 0.3

0.41666667]

Chebyshev series with order 6 [ 2.28949653e-04 1.05251736e-03 3.25520833e-04 5.98338294e-04

1.02306548e-04 1.68960813e-04 1.55009921e-06 1.05923446e-05

-3.87524802e-06 -2.84184854e-06 3.10019841e-07 2.34863516e-07]

示例 2:

在这个例子中,我们将创建一个二维的NumPy系数数组,其中有6个元素,形状为2×2,并通过设置3、4、1和6的阶数来进行积分。

# import the numpy module
import numpy
  
# import chebyshev
from numpy.polynomial import chebyshev
  
# Create an 2 D array of Chebyshev series 
# coefficients with 6 elements
coefficient_array = numpy.array([[1, 2, 3, 4, 3, 5], [5, 6, 8, 9, 0, 0]])
  
# display array
print("Coefficient array: ", coefficient_array)
  
# display the dimensions
print("Dimensions: ", coefficient_array.ndim)
  
# integrate chebyshev series with order 3
print("\nChebyshev series with order 3",
      chebyshev.chebint(coefficient_array, m=3))
  
# integrate chebyshev series with order 4
print("\nChebyshev series with order 4",
      chebyshev.chebint(coefficient_array, m=4))
  
# integrate chebyshev series with order 1
print("\nChebyshev series with order 1",
      chebyshev.chebint(coefficient_array, m=1))
  
# integrate chebyshev series with order 6
print("\nChebyshev series with order 6",
      chebyshev.chebint(coefficient_array, m=6))

输出:

Coefficient array: [[1 2 3 4 3 5]

[5 6 8 9 0 0]]

Dimensions: 2

Chebyshev series with order 3 [[0.078125 0.09375 0.125 0.140625 0. 0. ]

[0.125 0.25 0.375 0.5 0.375 0.625 ]

[0.10416667 0.125 0.16666667 0.1875 0. 0. ]

[0.04166667 0.08333333 0.125 0.16666667 0.125 0.20833333]

[0.02604167 0.03125 0.04166667 0.046875 0. 0. ]]

Chebyshev series with order 4 [[0.015625 0.03125 0.046875 0.0625 0.046875 0.078125 ]

[0.02604167 0.03125 0.04166667 0.046875 0. 0. ]

[0.02083333 0.04166667 0.0625 0.08333333 0.0625 0.10416667]

[0.01302083 0.015625 0.02083333 0.0234375 0. 0. ]

[0.00520833 0.01041667 0.015625 0.02083333 0.015625 0.02604167]

[0.00260417 0.003125 0.00416667 0.0046875 0. 0. ]]

Chebyshev series with order 1 [[1.25 1.5 2. 2.25 0. 0. ]

[1. 2. 3. 4. 3. 5. ]

[1.25 1.5 2. 2.25 0. 0. ]]

Chebyshev series with order 6 [[4.34027778e-04 8.68055556e-04 1.30208333e-03 1.73611111e-03

1.30208333e-03 2.17013889e-03]

[5.42534722e-04 6.51041667e-04 8.68055556e-04 9.76562500e-04

0.00000000e+00 0.00000000e+00]

[6.51041667e-04 1.30208333e-03 1.95312500e-03 2.60416667e-03

1.95312500e-03 3.25520833e-03]

[3.25520833e-04 3.90625000e-04 5.20833333e-04 5.85937500e-04

0.00000000e+00 0.00000000e+00]

[2.60416667e-04 5.20833333e-04 7.81250000e-04 1.04166667e-03

7.81250000e-04 1.30208333e-03]

[1.08506944e-04 1.30208333e-04 1.73611111e-04 1.95312500e-04

0.00000000e+00 0.00000000e+00]

[4.34027778e-05 8.68055556e-05 1.30208333e-04 1.73611111e-04

1.30208333e-04 2.17013889e-04]

[1.55009921e-05 1.86011905e-05 2.48015873e-05 2.79017857e-05

0.00000000e+00 0.00000000e+00]]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Numpy 多项式