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

สร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e พร้อมอาร์เรย์ของจุดที่ซับซ้อนใน Python


ในการสร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e ให้ใช้ hermite_e.hermvander() ใน Python Numpy เมธอดจะคืนค่าเมทริกซ์เทียม-Vandermonde รูปร่างของเมทริกซ์ที่ส่งคืนคือ x.shape + (deg + 1,) โดยที่ดัชนีสุดท้ายคือดีกรีของ Hermitepolynomial ที่สอดคล้องกัน dtype จะเหมือนกับ x ที่แปลงแล้ว

พารามิเตอร์ x ส่งกลับ Array of points dtype ถูกแปลงเป็น float64 หรือ complex128 ขึ้นอยู่กับว่าองค์ประกอบใดที่ซับซ้อน ถ้า x เป็นสเกลาร์ จะถูกแปลงเป็นอาร์เรย์ 1 มิติ พารามิเตอร์ deg คือระดับของเมทริกซ์ผลลัพธ์

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

นำเข้า numpy เป็น npfrom numpy.polynomial นำเข้า hermite_e เป็น H

สร้างอาร์เรย์ -

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

แสดงอาร์เรย์ -

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

ตรวจสอบขนาด -

print("\nDimensions of our Array...\n",c.dim)

รับประเภทข้อมูล -

print("\nประเภทข้อมูลของวัตถุ Array...\n",c.dtype)

รับรูปร่าง -

print("\nรูปร่างของวัตถุ Array...\n",c.shape)

ในการสร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e ให้ใช้ hermite_e.hermvander() ใน Python Numpy -

พิมพ์("\nผลลัพธ์...\n",H.hermevander(x, 2))

ตัวอย่าง

นำเข้า numpy เป็น npfrom numpy.polynomial นำเข้า hermite_e เป็น H# สร้าง arrayx =np.array([-2.+2.j, -1.+2.j, 0.+2.j, 1.+ 2.j, 2.+2.j])# แสดง arrayprint("Our Array...\n",x)# Check the Dimensionsprint("\nDimensions of our Array...\n",x.nim )# รับ Datatypeprint("\nประเภทข้อมูลของวัตถุ Array ของเรา...\n",x.dtype)# รับ Shapeprint("\nรูปร่างของวัตถุ Array ของเรา...\n",x.shape)# เพื่อสร้าง เมทริกซ์ Vandermonde ของพหุนาม Hermite_e ใช้ hermite_e.hermvander() ใน Python Numpyprint("\nResult...\n",H.hermevander(x, 2))

ผลลัพธ์

Our Array... [-2.+2.j -1.+2.j 0.+2.j 1.+2.j 2.+2.j]Dimensions of our Array...1ประเภทข้อมูล ของ Array object...complex128Shape of our Array object...(5,)ผลลัพธ์... [[ 1.+0.j -2.+2.j -1.-8.j] [ 1.+ 0.j -1.+2.j -4.-4.j] [ 1.+0.j 0.+2.j -5.+0.j] [ 1.+0.j 1.+2 .j -4.+4.j] [ 1.+0.j 2.+2.j -1.+8.j]]