Python中的复数用法 [英] Complex numbers usage in python

查看:122
本文介绍了Python中的复数用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是数学新手。现在,我将更深入地了解Python数据类型。我不明白如何使用复数。请给我示例在Python中使用复数的示例。

I'm a math newbie. Now I'm getting deeper into Python data types. I can't understand how to use a complex number. Please give me examples of usage of complex numbers in Python.

推荐答案

在python中,您可以输入'j'或'J'在数字后加一个虚构的数字,因此您可以轻松地编写复杂的文字:

In python, you can put ‘j’ or ‘J’ after a number to make it imaginary, so you can write complex literals easily:

>>> 1j
1j
>>> 1J
1j
>>> 1j * 1j
(-1+0j)

后缀'j'来自电子工程,其中变量 i通常用于当前。 (在此处找到原因。

The ‘j’ suffix comes from electrical engineering, where the variable ‘i’ is usually used for current. (Reasoning found here.)

复数的类型为 complex ,并且您可以根据需要将类型用作构造函数:

The type of a complex number is complex, and you can use the type as a constructor if you prefer:

>>> complex(2,3)
(2+3j)

有一个复数-访问者中:

A complex number has some built-in accessors:

>>> z = 2+3j
>>> z.real
2.0
>>> z.imag
3.0
>>> z.conjugate()
(2-3j)

多个内置函数支持复杂数字:

Several built-in functions support complex numbers:

>>> abs(3 + 4j)
5.0
>>> pow(3 + 4j, 2)
(-7+24j)

标准模块 cmath 具有更多处理功能

The standard module cmath has more functions that handle complex numbers:

>>> import cmath
>>> cmath.sin(2 + 3j)
(9.15449914691143-4.168906959966565j)

这篇关于Python中的复数用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆