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

สร้างชุด Chebyshev ด้วยรากที่ซับซ้อนที่กำหนดใน Python


ในการสร้างชุด Chebyshev ด้วยรูทที่กำหนด ให้ใช้เมธอด chebyshev.chebfromroots() ในPython Numpy วิธีการส่งกลับอาร์เรย์ 1-D ของสัมประสิทธิ์ ถ้ารากทั้งหมดเป็นของจริง ค่าที่ออกมาจะเป็นเรียลอาร์เรย์ ถ้ารากบางส่วนนั้นซับซ้อน ค่าที่ออกมาจะซับซ้อนแม้ว่าสัมประสิทธิ์ทั้งหมดในผลลัพธ์จะเป็นจำนวนจริงก็ตาม พารามิเตอร์รากคือลำดับที่มีราก

ขั้นตอน

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

from numpy.polynomial import chebyshev as C

ให้รากที่ซับซ้อน -

j = complex(0,1)

สร้างซีรีส์ −

print("Result...\n",C.chebfromroots((-j, j)))

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

print("\nType...\n",C.chebfromroots((-j, j)).dtype)

รับรูปร่าง -

print("\nShape...\n",C.chebfromroots((-j, j)).shape)

ตัวอย่าง

from numpy.polynomial import chebyshev as C

# To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy.

# The method returns 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

# The parameter roots are the sequence containing the roots.
j = complex(0,1)
print("Result...\n",C.chebfromroots((-j, j)))

# Get the datatype
print("\nType...\n",C.chebfromroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",C.chebfromroots((-j, j)).shape)

ผลลัพธ์

Result...
   [1.5+0.j 0. +0.j 0.5+0.j]

Type...
complex128

Shape...
(3,)