প্রদত্ত জটিল রুট সহ একটি monic বহুপদী তৈরি করতে, Python Numpy-এ polynomial.polyfromroots() পদ্ধতি ব্যবহার করুন। পদ্ধতিটি বহুপদী সহগগুলির 1-D অ্যারে প্রদান করে যদি সমস্ত শিকড় বাস্তব হয়, তবে আউটটিও বাস্তব, অন্যথায় এটি জটিল। পরামিতি শিকড় হল শিকড় ধারণকারী ক্রম।
পদক্ষেপ
প্রথমে, প্রয়োজনীয় লাইব্রেরি আমদানি করুন -
from numpy.polynomial import polynomial as P
দেওয়া জটিল শিকড় −
j = complex(0,1)
print("Result...\n",P.polyfromroots((-j,j))) ডেটাটাইপ −
পানprint("\nType...\n",P.polyfromroots((-j, j)).dtype)
আকৃতি −
পানprint("\nShape...\n",P.polyfromroots((-j, j)).shape) উদাহরণ
from numpy.polynomial import polynomial as P
# To generate a monic polynomial with given roots, use the polynomial.polyfromroots() method in Python Numpy.
# The method returns the 1-D array of the polynomial’s coefficients If all the roots are real, then out is also real, otherwise it is complex.
# The parameter roots are the sequence containing the roots.
j = complex(0,1)
print("Result...\n",P.polyfromroots((-j,j)))
# Get the datatype
print("\nType...\n",P.polyfromroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",P.polyfromroots((-j, j)).shape) আউটপুট
Result... [1.+0.j 0.+0.j 1.+0.j] Type... complex128 Shape... (3,)