Computer >> Máy Tính >  >> Lập trình >> Python

Tạo ma trận Vandermonde của đa thức Chebyshev bằng Python

Để tạo ma trận Vandermonde của đa thức Chebyshev, hãy sử dụng chebyshev.chebvander () trong Python Numpy. Phương thức này trả về ma trận Vandermonde. Hình dạng của ma trận được trả về làx.shape + (deg + 1,), trong đó Chỉ số cuối cùng là bậc của đa thức Chebyshev tương ứng. Loại sẽ giống như x được chuyển đổi.

Tham số, a là Mảng điểm. Loại dtype được chuyển đổi thành float64 hoặc complex128 tùy thuộc vào bất kỳ phần tử nào có phức tạp hay không. Nếu x là vô hướng, nó được chuyển đổi thành mảng 1-D. Tham số, deg là bậc của ma trận kết quả.

Các bước

Đầu tiên, hãy nhập thư viện được yêu cầu -

import numpy as np
from numpy.polynomial import chebyshev as C

Tạo một mảng -

x = np.array([0, 1, -1, 2])

Hiển thị mảng -

print("Our Array...\n",x)

Kiểm tra các thứ nguyên -

print("\nDimensions of our Array...\n",x.ndim)

Lấy Datatype -

print("\nDatatype of our Array object...\n",x.dtype)

Lấy hình dạng -

print("\nShape of our Array object...\n",x.shape)

Để tạo ma trận Vandermonde của đa thức Chebyshev, hãy sử dụng chebyshev.chebvander () trong Python -

print("\nResult...\n",C.chebvander(x, 2))

Ví dụ

import numpy as np
from numpy.polynomial import chebyshev as C

# Create an array
x = np.array([0, 1, -1, 2])

# Display the array
print("Our Array...\n",x)

# Check the Dimensions
print("\nDimensions of our Array...\n",x.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",x.dtype)

# Get the Shape
print("\nShape of our Array object...\n",x.shape)

# To generate a Vandermonde matrix of the Chebyshev polynomial, use the chebyshev.chebvander() in Python Numpy
print("\nResult...\n",C.chebvander(x, 2))

Đầu ra

Our Array...
   [ 0 1 -1 2]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(4,)

Result...
   [[ 1. 0. -1.]
   [ 1. 1. 1.]
   [ 1. -1. 1.]
   [ 1. 2. 7.]]