python print Detailed Explanation of Conjugate Complex Numbers

  • 2021-07-01 08:02:56
  • OfStack

The complex number is composed of a real number and an imaginary number, which is expressed as x+yj

One complex number is a pair of ordered floating-point numbers (x, y), where x is the real part and y is the imaginary part.

Concepts of plural numbers in Python language:

1. Imaginary numbers cannot exist alone, and they always form a complex number with a real number part 1 with a value of 0.0

2. Complex numbers are composed of real numbers and imaginary numbers

3. Syntax for imaginary numbers: real+imagej

4. Both the real part and the imaginary part are floating-point numbers

5. The imaginary part must have the suffix j or J

Built-in properties of complex numbers:

Complex objects have data attributes, which are the real part and imaginary part of the complex number.

The complex number also has the conjugate method, which is called to return the complex conjugate object of the complex number.

Complex properties: real (real part of complex number), imag (imaginary part of complex number), conjugate () (returns conjugate complex number of complex number)


class Complex(object):

  ''' Create 1 Static attributes are used to record the class version number '''

  version=1.0

  ''' Create a complex number class for manipulating and initializing complex numbers '''

  def __init__(self,rel=15,img=15j):

    self.realPart=rel

    self.imagPart=img

    

  # Create a complex number 

  def creatComplex(self):

    return self.realPart+self.imagPart

  # Gets the imaginary part of the input numeric part 

  def getImg(self):

    # Convert imaginary parts into strings 

    img=str(self.imagPart)

    # Slice the string to get the numeric part 

    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

  # Original complex number 

  print "the religion complex is :",Cplex

  # Find conjugate complex number 

  print "the conjugate complex is :",Cplex.conjugate()

   

if __name__=="__main__":

  test()

Complex instance code:


#coding=utf8
'''
复数是由1个实数和1个虚数组合构成,表示为:x+yj
1个负数时1对有序浮点数(x,y),其中x是实数部分,y是虚数部分。
Python语言中有关负数的概念:
1、虚数不能单独存在,它们总是和1个值为0.0的实数部分1起构成1个复数
2、复数由实数部分和虚数部分构成
3、表示虚数的语法:real+imagej
4、实数部分和虚数部分都是浮点数
5、虚数部分必须有后缀j或J
复数的内建属性:
复数对象拥有数据属性,分别为该复数的实部和虚部。
复数还拥有conjugate方法,调用它可以返回该复数的共轭复数对象。
复数属性:real(复数的实部)、imag(复数的虚部)、conjugate()(返回复数的共轭复数)
'''
class Complex(object):
  '''创建1个静态属性用来记录类版本号'''
  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()


Related articles: