Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การสร้างเมทริกซ์ Vandermonde แบบปลอมของพหุนาม Laguerre และจุด x, y ทศนิยมใน Python


บทนำ

ในการสร้างเมทริกซ์ Vandermonde แบบปลอมของพหุนาม Laguerre 2 มิติ สามารถใช้ laguerre.lagvander2d() จาก NumPy เมทอดนี้คืนค่าเมทริกซ์ที่มีรูปร่าง x.shape + (deg + 1,) พารามิเตอร์ deg เป็นลิสต์ขององศาสูงสุดในรูป [x_deg, y_deg]

ขั้นตอนการทำงาน

1. นำเข้าไลบรารี

import numpy as np
from numpy.polynomial import laguerre as L

2. สร้างอาเรย์พิกัดจุด

x = np.array([0.1, 1.4])
y = np.array([1.7, 2.8])

3. แสดงอาเรย์และตรวจสอบคุณสมบัติ

print("Array1...\n", x)
print("\nArray2...\n", y)
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)

4. สร้างเมทริกซ์ Vandermonde 2 มิติ

x_deg, y_deg = 2, 3
print("\nResult...\n", L.lagvander2d(x, y, [x_deg, y_deg]))

ตัวอย่างโค้ดสมบูรณ์

import numpy as np
from numpy.polynomial import laguerre as L

# สร้างอาเรย์พิกัดจุด
x = np.array([0.1, 1.4])
y = np.array([1.7, 2.8])

# แสดงอาเรย์
print("Array1...\n", x)
print("\nArray2...\n", y)

# แสดงชนิดข้อมูล
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)

# ตรวจสอบมิติ
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)

# ตรวจสอบรูปร่าง
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)

# สร้างเมทริกซ์ Vandermonde 2 มิติ
x_deg, y_deg = 2, 3
print("\nResult...\n", L.lagvander2d(x, y, [x_deg, y_deg]))

ผลลัพธ์ที่คาดหวัง

Array1...   [0.1 1.4]
Array2...   [1.7 2.8]
Array1 datatype... float64
Array2 datatype... float64
Dimensions of Array1... 1
Dimensions of Array2... 1
Shape of Array1... (2,)
Shape of Array2... (2,)
Result...   [[ 1. -0.7 -0.955 -0.58383333 0.9 -0.63 -0.8595 -0.52545 0.805 -0.5635 -0.768775 -0.46998583]
             [ 1. -1.8 -0.68 0.70133333 -0.4 0.72 0.272 -0.28053333 -0.82 1.476 0.5576 -0.57509333]]