3.6小节start

This commit is contained in:
XiongNeng
2014-09-11 12:04:06 +08:00
parent 0aacdb1bd2
commit f4d2e45753
2 changed files with 57 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Topic: sample
Desc :
"""
def complex_math():
a = complex(2, 4)
b = 3 - 5j
if __name__ == '__main__':
complex_math()

View File

@@ -5,12 +5,51 @@
----------
问题
----------
todo...
你写的最新的网络认证方案代码遇到了一个难题,并且你唯一的解决办法就是使用复数空间。
再或者是你仅仅需要使用复数来执行一些计算操作。
|
----------
解决方案
----------
todo...
复数可以用使用函数complex(real, imag)或者是带有后缀j的浮点数来指定。比如
.. code-block:: python
>>> a = complex(2, 4)
>>> b = 3 - 5j
>>> a
(2+4j)
>>> b
(3-5j)
>>>
对应的实部、虚部和共轭复数可以很容易的获取。就像下面这样:
.. code-block:: python
>>> a.real
2.0
>>> a.imag
4.0
>>> a.conjugate()
(2-4j)
>>>
In addition, all of the usual mathematical operators work:
.. code-block:: python
>>> a + b
(5-1j)
>>> a * b
(26+2j)
>>> a / b
(-0.4117647058823529+0.6470588235294118j)
>>> abs(a)
4.47213595499958
>>>
----------
讨论