学習Python -中級コース:日10、複素数パート2


昨日、我々は複雑な数字で操作の基本を学んだ。今日、複素数に関連する多くの異なる機能をカバーします。


複素数


複素数の位相や引数は、phase() 関数.
import cmath
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

複素数の極形式。


複素数を極形式に変換することができますpolar() そして、rect() 関数.
import cmath
z = complex(1,1)
a = cmath.polar(z)
print ("The polar complex number is : ",end="")
print (a) # returns a tuple
z2= cmath.rect(a[0],a[1])
print ("The rectangular form of complex number is : ",end="")
print (z2)
The polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)

Note the return types for the functions

  • polar() returns a tuple.
  • rect() returns a complex number.

関数はcmathモジュール


よく使われているcmathモジュールの関数を調べましょう.以下の例では、最もよく使われる関数の使用方法を説明します.ドキュメントを持つ関数のリスト全体を見つけることができますhere
>>> import cmath
>>> z=complex(-2,1)
#make a complex number.
>>> cmath.exp(z)
# Raise z to a complex power.
(0.07312196559805963+0.1138807140643681j)
>>> cmath.exp(z.real)
# the cmath module takes in real as well as complex parameters.
(0.1353352832366127+0j)
>>> cmath.log(z,10)
#logarithm of z to the base 10
(0.3494850021680094+1.1630167557051545j)
>>> cmath.log(10,z)
# logarithm of 10 to  the base z
(0.2369795135136017-0.7886208085195003j)
>>> cmath.log(z,z)
#alogarithm of z to the base z
(1+0j)
>>> cmath.sqrt(z)
# square root of z
(0.34356074972251244+1.455346690225355j)
>>> cmath.acos(z)
# arccos of z
(2.6342363503726487-1.4693517443681852j)
>>> cmath.atan(z)
# arctan of z
(-1.1780972450961724+0.17328679513998632j)
>>> cmath.sin(z)
# arc sine of z
(-1.4031192506220405-0.4890562590412937j)
>>> cmath.acosh(z)
# hyperbolic inverse cosine
(1.4693517443681852+2.6342363503726487j)
>>> cmath.tanh(z)
# hyperbolic tangent
(-1.0147936161466335+0.0338128260798967j)
>>> cmath.pi
# The usual pi constant
3.141592653589793
>>> pow(z,z)
# z raised to the power z.(note that this is not from the cmath module.
(-0.00220568464655929+0.013562654681556313j)

Note- j is often used in electronics instead of i, hence in Python expressions like 1+1i are written as 1+ij


計算機科学への複素数の応用


よく、私はあなたが世界でなぜ複雑な数字について学んでいるか疑問に思わなければなりません.さて、これは複雑な数字は、多くの現実世界の問題を解決する非常に便利なツールですので.彼らは座標系に格納する素晴らしい方法です.我々がちょうど見たように、彼らはベクトルと比較されるとき、実装するのが非常に簡単です.Pythonでは、複雑な数字は、普通の古い実数のように自然に操作できます.
複素数の他の用途は
  • 信号処理
  • 画像処理
  • 科学計算
  • グラフィックス
  • コンピュータビジョン
  • データ圧縮
  • 読もう
  • What are some applications of complex numbers in computer science?
  • complex numbers in programming?
  • 複雑な数字の概念に新しい人は以下のビデオが好きかもしれません。


    あなたはコンテンツが好きでしたか?😎 以下のコメント欄でお知らせください👇. そして、あなたがしたならば、ポストが好きであるのを忘れないでください.😍 私はどんな提案や疑問にも賛成です.🤠 ちょうど以下のコメントまたはGmail MEでポストしてください.😉
    どうもありがとう👍
    また、訪問してくださいLearning-Python repo 特にこのコースのために作られ、それも星を忘れないでください!