使用arctan/arctan2绘制从0到2π的a [英] using arctan / arctan2 to plot a from 0 to 2π

查看:420
本文介绍了使用arctan/arctan2绘制从0到2π的a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制柯蒂斯的《轨道力学》中的图,但我只是不太明白.但是,我已经从np.arctan切换到np.arctan2了.

I am trying to replicate a plot in Orbital Mechanics by Curtis but I just can't quite get it. However, I have made head way by switching to np.arctan2 from np.arctan.

也许我没有正确实现arctan2?

import pylab
import numpy as np

e = np.arange(0.0, 1.0, 0.15).reshape(-1, 1)

nu = np.linspace(0.001, 2 * np.pi - 0.001, 50000)
M2evals = (2 * np.arctan2(1, 1 / (((1 - e) / (1 + e)) ** 0.5 * np.tan(nu / 2) -
           e * (1 - e ** 2) ** 0.5 * np.sin(nu) / (1 + e * np.cos(nu)))))

fig2 = pylab.figure()
ax2 = fig2.add_subplot(111)

for Me2, _e in zip(M2evals, e.ravel()):
    ax2.plot(nu.ravel(), Me2, label = str(_e))

pylab.legend()
pylab.xlim((0, 7.75))
pylab.ylim((0, 2 * np.pi))
pylab.show()

在下图中,弹出了不连续性.该函数应该是平滑的,并且在(0,2pi)的y范围内的0和2 pi处连接,而不会碰到0和2pi.

In the image below, there are discontinuities popping up. The function is supposed to be smooth and connect at 0 and 2 pi in the y range of (0, 2pi) not touching 0 and 2pi.

教科书情节和方程式:

应Saullo Castro的要求,我被告知:

At the request of Saullo Castro, I was told that:

问题可能出在arctan函数上,该函数提供原理值"作为输出.

"The problem may lie in the arctan function which gives "principle values" as output.

因此,如果x是第二象限或第三象限中的一个角度,则arctan(tan(x))不会产生x.如果将arctan(tan(x))从x = 0绘制到x = Pi,则会发现它在x = Pi/2处具有不连续的跳跃.

Thus, arctan(tan(x)) does not yield x if x is an angle in the second or third quadrant. If you plot arctan(tan(x)) from x = 0 to x = Pi, you will find that it has a discontinuous jump at x = Pi/2.

对于您的情况,我相信您可以编写arctan2(1,1/arg)而不是编写arctan(arg),其中arg是您的arctan函数的参数.这样,当arg变为负数时,arctan2将在第二个象限而不是第四个象限中产生一个角度."

For your case, instead of writing arctan(arg), I believe you would write arctan2(1, 1/arg) where arg is the argument of your arctan function. That way, when arg becomes negative, arctan2 will yield an angle in the second quadrant rather than the fourth."

推荐答案

通常的做法是在arctan()的否定结果

The common practice is to sum 2*pi in the negative results of arctan(), which can be done efficiently. The OP's suggestion to replace arctan(x) by arctan2(1,1/x), also suggested by Maple 15's documentation as pointed out by @Yay295, produces the same results without the need to sum 2*pi. Both are shown below:

import pylab
import numpy as np
e = np.arange(0.0, 1.0, 0.15).reshape(-1, 1)
nu = np.linspace(0, 2*np.pi, 50000)
x =  ((1-e)/(1+e))**0.5 * np.tan(nu/2.)
x2 = e*(1-e**2)**0.5 * np.sin(nu)/(1 + e*np.cos(nu))
using_arctan = True
using_OP_arctan2 = False

if using_arctan:
    M2evals = 2*np.arctan(x) - x2
    M2evals[ M2evals<0 ] += 2*np.pi
elif using_OP_arctan2:
    M2evals = 2 * np.arctan2(1,1/x) - x2

fig2 = pylab.figure()
ax2 = fig2.add_subplot(111)
for M2e, _e in zip(M2evals, e.ravel()):
    ax2.plot(nu.ravel(), M2e, label = str(_e))
pylab.legend(loc='upper left')
pylab.show()

这篇关于使用arctan/arctan2绘制从0到2π的a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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