在复数平面上绘制虚数。

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

Plotting imaginary numbers on a complex plane

问题

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

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

  1. import math
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. i = np.emath.sqrt(-1).imag
  5. e = math.e
  6. x = np.linspace(0, 10, 1000)
  7. plt.scatter(x, (e**(i*x)))
  8. # plt.scatter(x, (np.cos(x) + (i*np.sin(x))))
  9. 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:

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. i = np.emath.sqrt(-1).imag
  4. e = math.e
  5. x = np.linspace(0, 10, 1000)
  6. plt.scatter(x, (e**(i*x)))
  7. # plt.scatter(x, (np.cos(x) + (i*np.sin(x))))
  8. plt.show()

答案1

得分: 4

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

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. # 输入参数。
  4. n = 9
  5. t = 2 * np.pi * np.arange(n) / n
  6. # 复数结果。
  7. z = np.exp(1j * t)
  8. fig, ax = plt.subplots()
  9. ax.scatter(np.real(z), np.imag(z))
  10. 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.

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. # Input parameter.
  4. n = 9
  5. t = 2 * np.pi * np.arange(n) / n
  6. # Complex valued result.
  7. z = np.exp(1j * t)
  8. fig, ax = plt.subplots()
  9. ax.scatter(np.real(z), np.imag(z))
  10. 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:

确定