我已经Python
多次使用向量的点积,但由于某种原因,一个这样np.dot()
的命令不起作用。
#!/usr/bin/env ipython
import numpy as np
from numpy import linalg as LA
from scipy.optimize import fsolve
Re = 1.496e8 # semi-major axis of the Earth
Te = 365.25 * 24.0 * 3600.0 # period of the Earth in sec
mus = 132712000000.0 # grav param of the Sun
def f(a):
return (2 * np.pi / np.sqrt(mus) * np.sqrt(a ** 3) - Te * 2.0 / 3.0)
a = fsolve(f, 100000000)
e = Re / a - 1
rp = a * (1 - e)
h = np.sqrt(2 * mus) * np.sqrt(Re * rp / (Re + rp))
vE = np.sqrt(mus / Re)
vp = h / Re
vinf = vE - vp
alt = 500.0 # the flyby distance
rph = 6378 + alt # radius at periapsis of the flyby hyperbola
mue = 398600.0 # grav param of the Earth
eh = 1 + rph * vinf ** 2 / mue
beta = np.arccos(1.0 / eh)
delta = 2.0 * beta
vpvec = np.array([0, -vp, 0])
vinfoutvec = vinf * np.array([-np.sin(delta), np.cos(delta)])
vhpostvec = np.array([vinfoutvec[0], vinfoutvec[1] + vpvec[1]])
r0 = np.array([-Re, 0, 0])
v0 = np.array([vhpostvec[0], vhpostvec[1], 0])
h0vec = np.cross(r0, v0)
h0 = LA.norm(h0vec)
e2vec = np.cross(v0, h0vec) / mus - r0 / LA.norm(r0)
e2 = LA.norm(e2vec)
nu0 = np.arccos(np.dot(e2vec, np.array([1.0, 0, 0])) / e2)
#taking the dot product of the vector, specifying the vector location,
#and pulling the actual coordinate options
#nupost = (np.arccos(np.dot(r0, e2vec) / (Re * e2)) * 180.0 / np.pi)
#nupost = (np.arccos(r0[0] * e2vec[0] / (Re * e2)) * 180.0 / np.pi)
#nupost = (np.arccos(-Re * 0.30029169 / (Re * e2)) * 180.0 / np.pi)
我检查了向量是否具有相同的维度,并且我们有相同的
r0
维度1x3
,e2vec
. 但是,每当我尝试取这两个向量的点积时,我都会收到ValueError Traceback (most recent call last) <ipython-input-13-40977131af32> in <module>() ----> 1 execfile(r'/home/dustin/test.py') # PYTHON-MODE /home/dustin/test.py in <module>() 26 27 #nupost = (np.arccos(-Re * 0.30029169 / (Re * e2)) * 180.0 / np.pi) ---> 28 nupost = (np.arccos(np.dot(r0, e2vec) / (Re * e2)) * 180.0 / np.pi) 29 #nupost = (np.arccos(r0[0] * e2vec[0] / (Re * e2)) * 180.0 / np.pi) 30 ValueError: matrices are not aligned
然后我尝试指定向量分量
r0[0]
,并将e2vec[0]
它们相乘会1x3
在第一个位置产生一个带有正确答案的向量。但是,我不应该在这里收到向量。In [14]: The eccentricity vector of the new ellipse is [[ 0.30029169 0.14176274 \ 0. ]] The post flyby true anomaly is [ 154.72877834 115.27122166 90. ]
如果我只是提取实际值,一切都会完美运行。
我不是Python
专家,但为什么点积在情况 1 中不起作用,为什么在情况 2 中不能指定矢量分量?在我的示例中,我之前使用了点积向量分量规范,没有出现此类问题。