在复数平面上绘制虚数。

huangapple go评论59阅读模式
英文:

Plotting imaginary numbers on a complex plane

问题

我正在尝试在复平面上绘制欧拉公式的图形(e^(ix)),最好使用matplotlib来实现圆形图形(半径为i)。
是否有一种方法可以做到这一点?

到目前为止,我只能在实平面上绘制它,以获得以下代码形式的图形e^(kx):

import math
import numpy as np
import matplotlib.pyplot as plt

i = np.emath.sqrt(-1).imag
e = math.e

x = np.linspace(0, 10, 1000)
plt.scatter(x, (e**(i*x)))
# plt.scatter(x, (np.cos(x) + (i*np.sin(x))))
plt.show()
英文:

I'm trying to plot the graph of Euler's formula (e^(ix)) on a complex plane (preferably with matplotlib) to achieve the circular graph (radius i).
Is there a way I can do this?

So far I've only managed to plot it on a real plane to get a graph in the form e^(kx) with the following code:

import numpy as np
import matplotlib.pyplot as plt

i = np.emath.sqrt(-1).imag
e = math.e

x = np.linspace(0, 10, 1000)
plt.scatter(x, (e**(i*x)))
# plt.scatter(x, (np.cos(x) + (i*np.sin(x))))
plt.show()

答案1

得分: 4

你可以计算一些x的复数函数值,然后在x轴和y轴上分别绘制实部和虚部。请确保不要混淆你所命名的变量x和图表上的x轴。我会使用t来避免混淆。

import numpy as np
import matplotlib.pyplot as plt

# 输入参数。
n = 9
t = 2 * np.pi * np.arange(n) / n
# 复数结果。
z = np.exp(1j * t)

fig, ax = plt.subplots()
ax.scatter(np.real(z), np.imag(z))
ax.set_aspect("equal")

绘图结果:

在复数平面上绘制虚数。

英文:

You can compute the complex-valued function for some values of x and then plot the real and imaginary components on the x- and y-axes, respectively. Make sure not to mix up the variable you're naming x and the x-axis on the plot. I'll use t to avoid that confusion.

import numpy as np
import matplotlib.pyplot as plt

# Input parameter.
n = 9
t = 2 * np.pi * np.arange(n) / n
# Complex valued result.
z = np.exp(1j * t)

fig, ax = plt.subplots()
ax.scatter(np.real(z), np.imag(z))
ax.set_aspect("equal")

Plot result:

在复数平面上绘制虚数。

huangapple
  • 本文由 发表于 2023年7月14日 04:01:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682868.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定