用 Python 計算具有給定複數根的勒讓德級數根
為計算勒讓德級數的根,可在 Python 中使用 polynomial.legendre.lagroots() 方法。此方法返回一個級數根陣列。如果所有根都是實數,則 out 也是實數,否則就是複數。引數 c 是一個一維繫數陣列。
步驟
首先,匯入所需的庫 −
from numpy.polynomial import legendre as L
計算勒讓德級數的根 −
j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))獲取資料型別 −
print("\nType...\n",L.legroots((-j, j)).dtype)獲取形狀 −
print("\nShape...\n",L.legroots((-j, j)).shape)舉例
from numpy.polynomial import legendre as L
# To compute the roots of a Legendre series, use the polynomial.legendre.lagroots() method in Python
# The method returns an array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex.
# The parameter c is a 1-D array of coefficients.
j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))
# Get the datatype
print("\nType...\n",L.legroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",L.legroots((-j, j)).shape)輸出
Result... [1.+0.j] Type... complex128 Shape... (1,)
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP