logo

الأعداد المركبة في بايثون | المجموعة 1 (مقدمة)

ليس فقط الأعداد الحقيقية، بل يمكن لبيثون أيضًا التعامل مع الأعداد المركبة والوظائف المرتبطة بها باستخدام الملف 'cmath'. أرقام معقدة لها استخداماتها في العديد من التطبيقات المتعلقة بالرياضيات وتوفر لغة بايثون أدوات مفيدة للتعامل معها ومعالجتها. تحويل الأعداد الحقيقية إلى أعداد مركبة يتم تمثيل العدد المركب بـ " س + يي '. تقوم بايثون بتحويل الأعداد الحقيقية x وy إلى أرقام معقدة باستخدام الدالة مجمع (س ص) . يمكن الوصول إلى الجزء الحقيقي باستخدام الوظيفة حقيقي() ويمكن تمثيل الجزء التخيلي بواسطة الصورة ()

Python
# Python code to demonstrate the working of # complex() real() and imag() # importing 'cmath' for complex number operations import cmath # Initializing real numbers x = 5 y = 3 # converting x and y into complex number z = complex(x y) # printing real and imaginary part of complex number print('The real part of complex number is:' z.real) print('The imaginary part of complex number is:' z.imag) 

الإخراج
The real part of complex number is: 5.0 The imaginary part of complex number is: 3.0 

طريقة بديلة لتهيئة رقم مركب  



وفيما يلي تنفيذ كيف يمكننا أن نجعل رقما معقدا. دون استخدام وظيفة معقدة (). .

Python
# An alternative way to initialize complex numbers' # importing 'cmath' for complex number operations import cmath # Initializing complex number z = 5+3j # Print the parts of Complex No. print('The real part of complex number is : ' end='') print(z.real) print('The imaginary part of complex number is : ' end='') print(z.imag) 

الإخراج
The real part of complex number is : 5.0 The imaginary part of complex number is : 3.0 

توضيح: مرحلة العدد المركب هندسيا مرحلة العدد المركب هي الزاوية المحصورة بين المحور الحقيقي الموجب والمتجه الذي يمثل عددًا مركبًا . يُعرف هذا أيضًا باسم الحجة من عدد معقد. يتم إرجاع المرحلة باستخدام مرحلة() والذي يأخذ رقمًا معقدًا كوسيطة. نطاق المرحلة يقع من -pi يعني +pi. أي من -3.14 إلى +3.14 .

Python
# importing 'cmath' for complex number operations import cmath # Initializing real numbers x = -1.0 y = 0.0 # converting x and y into complex number z = complex(x y) # printing phase of a complex number using phase() print('The phase of complex number is:' cmath.phase(z)) 

الإخراج
The phase of complex number is: 3.141592653589793 

التحويل من الشكل القطبي إلى الشكل المستطيل وبالعكس يتم التحويل إلى القطبية باستخدام القطبية () الذي يعود أ زوج (رف) مما يدل على معامل ص والمرحلة زاوية الرقم الهيدروجيني . يمكن عرض المعامل باستخدام القيمة المطلقة () والمرحلة باستخدام مرحلة() . يتم تحويل العدد المركب إلى إحداثيات مستطيلة باستخدام مستقيم (ص فتاه) أين r هو المعامل و ph هي زاوية الطور . تقوم بإرجاع قيمة تساوي عدديا ص * (math.cos(ph) + math.sin(ph)*1j)  



Python
# importing 'cmath' for complex number operations import cmath import math # Initializing real numbers x = 1.0 y = 1.0 # converting x and y into complex number z = complex(x y) # converting complex number into polar using polar() w = cmath.polar(z) # printing modulus and argument of polar complex number print('The modulus and argument of polar complex number is:' w) # converting complex number into rectangular using rect() w = cmath.rect(1.4142135623730951 0.7853981633974483) # printing rectangular form of complex number print('The rectangular form of complex number is:' w) 

الإخراج
The modulus and argument of polar complex number is: (1.4142135623730951 0.7853981633974483) The rectangular form of complex number is: (1.0000000000000002+1j) 


الأعداد المركبة في بايثون | المجموعة 2 (الوظائف والثوابت المهمة)