Home>Article>Backend Development> How to print conjugate complex numbers in python
A complex number is composed of a real number and an imaginary number, expressed as: x yj
A negative number is a pair of ordered floating point numbers (x, y), where x is the real part and y is the imaginary part.
The concept of negative numbers in the Python language:
1. Imaginary numbers cannot exist alone. They always form a complex number together with a real number part with a value of 0.0
2. A complex number consists of a real part and an imaginary part
3. The syntax for expressing an imaginary number: real imagej
4. The real part and the imaginary part are both floating point numbers
5. The imaginary part Must have suffix j or J
Built-in properties of plurals:
Plural objects have data properties, respectively part and imaginary part.
Complex numbers also have the conjugate method, which can be called to return the conjugate complex object of the complex number.
Related recommendations: "Python Video Tutorial"
Complex number attributes: real (real part of complex number), imag (imaginary part of complex number), conjugate() (return Complex conjugate of a complex number)
class Complex(object): '''创建一个静态属性用来记录类版本号''' version=1.0 '''创建个复数类,用于操作和初始化复数''' def __init__(self,rel=15,img=15j): self.realPart=rel self.imagPart=img #创建复数 def creatComplex(self): return self.realPart+self.imagPart #获取输入数字部分的虚部 def getImg(self): #把虚部转换成字符串 img=str(self.imagPart) #对字符串进行切片操作获取数字部分 img=img[:-1] return float(img) def test(): print "run test..........." com=Complex() Cplex= com.creatComplex() if Cplex.imag==com.getImg(): print com.getImg() else: pass if Cplex.real==com.realPart: print com.realPart else: pass #原复数 print "the religion complex is :",Cplex #求取共轭复数 print "the conjugate complex is :",Cplex.conjugate() if __name__=="__main__": test()
The above is the detailed content of How to print conjugate complex numbers in python. For more information, please follow other related articles on the PHP Chinese website!