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

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


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

ขั้นตอน

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

import numpy as np
from numpy.polynomial import chebyshev as C

ในการสร้างชุด Chebyshev ด้วยรากที่กำหนด ให้ใช้วิธีการ chebyshev.chebfromroots() ในPython Numpy -

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

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

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

รับรูปร่าง -

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

ตัวอย่าง

import numpy as np
from numpy.polynomial import chebyshev as C

# To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy.
print("Result...\n",C.chebfromroots((-1,0,1)))

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

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

ผลลัพธ์

Result...
   [ 0. -0.25 0. 0.25]

Type...
float64

Shape...
(4,)