0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

No.015【Python】 「実部と虚部の取得」/共役な複素数・複素数の絶対値について

Posted at

python-logo-master-v3-TM-flattened.png

今回は、「実部と虚部の取得」について書いていきます。
I'll write about " to acquire real and imaginary parts " on this blog.

##■実部と虚部の取得について
About "real and imaginary parts"

####・複素数complex型の実部は"real "、 虚部は"imag"属性で取得ができる。
 You can acquire the complex type of real part by "real ";
 on the other hand, you do the type of imaginary part by "img" in python.

>>> a = 2 + 6j
>>> 
>>> print(a.real)
2.0
>>> print(type(a.real))
<class 'float'>
>>> 
>>> print(a.imag)
6.0
>>> print(type(a.imag))
<class 'float'>

ただし、読み込みのみだけなので、
変更することが不可能であることは覚えておいてほしい。
However, I'd like you to remember that this is "reading only "; hence, it can't be changed after you printed.

>>> a.real = 7.5
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    a.real = 7.5
AttributeError: readonly attribute

###■共役な複素数の取得について
About conjugated complex numbers

####・共役な複素数を取得する際は、conjugateメソッドを利用する。
  When you acquire conjugated complex numbers, we use "conjugate method" in Python.

>>> a = 2 + 5j
>>> 
>>> print(a.conjugate())
(2-5j)

####■複素数の絶対値の取得について
About absolute value of complex numbers

####・複素数の絶対値を取得する際は、組み込み関数 ”abs( )"を利用する。
  When you get the absolute value of complex numbers, you would use an abs function
  as a built-in function.

>>> a = 6 + 8j
>>> 
>>> print(abs(a))
10.0
>>> 
>>> a = 2 + 1j
>>> 
>>> print(abs(a))
2.23606797749979

いかがでしたでしょうか。
How was my post?

次回も引き続き「複素数」に関する内容について書いていこうと思います。
I'll write about "complex numbers" on the next blog.

本ブログは、随時に更新していきますので、
定期的な購読をよろしくお願いします。
I'll update my blogs at all times.
So, please subscribe my blogs from now on.

また、本ブログについて、
何か要望等ありましたら、気軽にメッセージをください!
If you have some requests, please leave some messages! by You-Tarin

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?