ในการสร้างเมทริกซ์ Vandermonde หลอกของพหุนาม Legendre ให้ใช้วิธี thepolynomial.legvander() ใน Python Numpy
เมธอดจะคืนค่าเมทริกซ์เทียม-Vandermonde รูปร่างของเมทริกซ์ที่ส่งคืนคือ x.shape +(deg + 1,) โดยที่ดัชนีสุดท้ายคือระดับของพหุนาม Legendre ที่สอดคล้องกัน dtype จะเหมือนกับ x ที่แปลงแล้ว
พารามิเตอร์ x ส่งกลับ Array of points dtype ถูกแปลงเป็น float64 หรือ complex128 ขึ้นอยู่กับว่าองค์ประกอบใดที่ซับซ้อน ถ้า x เป็นสเกลาร์ จะถูกแปลงเป็นอาร์เรย์ 1 มิติ พารามิเตอร์ deg คือระดับของเมทริกซ์ผลลัพธ์
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np from numpy.polynomial import legendre as L
สร้างอาร์เรย์ -
x = np.array([0, 1, -1, 2])
แสดงอาร์เรย์ -
print("Our Array...\n",c) ตรวจสอบขนาด -
print("\nDimensions of our Array...\n",c.ndim) รับประเภทข้อมูล -
print("\nDatatype of our Array object...\n",c.dtype) รับรูปร่าง -
print("\nShape of our Array object...\n",c.shape) ในการสร้างเมทริกซ์ Vandermonde เทียมของพหุนาม Legendre ให้ใช้วิธี thepolynomial.legvander() ใน Python -
print("\nResult...\n",L.legvander(x, 2)) ตัวอย่าง
import numpy as np
from numpy.polynomial import legendre as L
# 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 pseudo Vandermonde matrix of the Legendre polynomial, use the polynomial.legvander() method in Python Numpy
print("\nResult...\n",L.legvander(x, 2)) ผลลัพธ์
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. -0.5] [ 1. 1. 1. ] [ 1. -1. 1. ] [ 1. 2. 5.5]]