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

Tạo ma trận Vandermonde của đa thức Hermite với mảng điểm thực trong Python

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

Tham số, x trả về một Mảng điểm. Loại dtype được chuyển đổi thành float64 hoặc complex128 tùy thuộc vào việc liệu bất kỳ phần tử nào có phức tạp hay không. Nếu x là vô hướng, nó sẽ đượ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 hermite as H

Tạo một mảng -

x = np.array([0, 3.5, -1.4, 2.5])

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 Hermite, hãy sử dụng chebyshev.hermvander () -

print("\nResult...\n",H.hermvander(x, 2))

Ví dụ

import numpy as np
from numpy.polynomial import hermite as H

# Create an array
x = np.array([0, 3.5, -1.4, 2.5])

# 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 Hermite polynomial, use the chebyshev.hermvander() in Python Numpy
print("\nResult...\n",H.hermvander(x, 2))

Đầu ra

Our Array...
   [ 0. 3.5 -1.4 2.5]

Dimensions of our Array...
1

Datatype of our Array object...
float64

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

Result...
   [[ 1. 0. -2. ]
   [ 1. 7. 47. ]
   [ 1. -2.8 5.84]
   [ 1. 5. 23. ]]