如何在 Python 2.7.2 中计算一组 GPS 卫星的 DOP 值?
How can I calculate the DOP values for a set of GPS satellites in Python 2.7.2?
我正在尝试使用 numpy 1.9.3 计算 Python 2.7.2 中一组 GPS 卫星的 DOP 值。
我找到了关于如何执行此操作的 guide,但我无法将其翻译成 python。
这是我到目前为止尝试过的方法:
import numpy as np
# First I defined 3 variables for each satellite as described in the guide.
sat_1_1 = np.sin(np.deg2rad(136)) * np.cos(np.deg2rad(14))
sat_1_2 = np.cos(np.deg2rad(136)) * np.cos(np.deg2rad(14))
sat_1_3 = np.sin(np.deg2rad(14))
sat_2_1 = np.sin(np.deg2rad(329)) * np.cos(np.deg2rad(48))
sat_2_2 = np.cos(np.deg2rad(329)) * np.cos(np.deg2rad(48))
sat_2_3 = np.sin(np.deg2rad(48))
sat_3_1 = np.sin(np.deg2rad(253)) * np.cos(np.deg2rad(36))
sat_3_2 = np.cos(np.deg2rad(253)) * np.cos(np.deg2rad(36))
sat_3_3 = np.sin(np.deg2rad(36))
sat_4_1 = np.sin(np.deg2rad(188)) * np.cos(np.deg2rad(9))
sat_4_2 = np.cos(np.deg2rad(188)) * np.cos(np.deg2rad(9))
sat_4_3 = np.sin(np.deg2rad(9))
# Next I created the line-of-sight matrix:
LOS_Matrix = np.array([[sat_1_1, sat_1_2, sat_1_3, 1.0], [sat_2_1, sat_2_2, sat_2_3, 1.0], [sat_3_1, sat_3_2, sat_3_3, 1.0], [sat_4_1, sat_4_2, sat_4_3, 1.0]])
# Then its transpose:
LOS_Matrix_t = LOS_Matrix.transpose()
# Next the guide says to compute the covariance matrix which is said to be equal to the inverse of LOS_Matrix * LOS_Matrix_t, so:
cov_matrix = np.linalg.inv(LOS_Matrix * LOS_Matrix_t)
# This should now lets me calculate the DOP values such as GDOP, PDOP, etc
PDOP = np.sqrt(cov_matrix[0, 0] + cov_matrix[1, 1] + cov_matrix[2, 2])
# This comes out as 2.25575033021 which is possbile though it seems suspiciously low
# Also TDOP can't be computed since cov_matrix[3, 3] is a negative number so something must be wrong I guess?
我是一个 python 菜鸟,数学也不是我的强项,我只是通过谷歌搜索一条又一条错误消息才走到这一步。
我现在运行时没有任何错误消息,但它似乎也不正确,否则 TDOP 值应该是可计算的,例如。
有人知道问题出在哪里吗?
干杯
cov_matrix = np.linalg.inv(LOS_Matrix * LOS_Matrix_t)
应该是
cov_matrix = np.linalg.inv(LOS_Matrix.dot(LOS_Matrix_t))
我知道我知道,这令人困惑。但是在 numpy 中你有两种不同的类型,一种是你应该使用的 ndarray
,另一种是你不应该使用的矩阵。对于 ndarray
乘法默认为逐元素乘法。
我正在尝试使用 numpy 1.9.3 计算 Python 2.7.2 中一组 GPS 卫星的 DOP 值。
我找到了关于如何执行此操作的 guide,但我无法将其翻译成 python。
这是我到目前为止尝试过的方法:
import numpy as np
# First I defined 3 variables for each satellite as described in the guide.
sat_1_1 = np.sin(np.deg2rad(136)) * np.cos(np.deg2rad(14))
sat_1_2 = np.cos(np.deg2rad(136)) * np.cos(np.deg2rad(14))
sat_1_3 = np.sin(np.deg2rad(14))
sat_2_1 = np.sin(np.deg2rad(329)) * np.cos(np.deg2rad(48))
sat_2_2 = np.cos(np.deg2rad(329)) * np.cos(np.deg2rad(48))
sat_2_3 = np.sin(np.deg2rad(48))
sat_3_1 = np.sin(np.deg2rad(253)) * np.cos(np.deg2rad(36))
sat_3_2 = np.cos(np.deg2rad(253)) * np.cos(np.deg2rad(36))
sat_3_3 = np.sin(np.deg2rad(36))
sat_4_1 = np.sin(np.deg2rad(188)) * np.cos(np.deg2rad(9))
sat_4_2 = np.cos(np.deg2rad(188)) * np.cos(np.deg2rad(9))
sat_4_3 = np.sin(np.deg2rad(9))
# Next I created the line-of-sight matrix:
LOS_Matrix = np.array([[sat_1_1, sat_1_2, sat_1_3, 1.0], [sat_2_1, sat_2_2, sat_2_3, 1.0], [sat_3_1, sat_3_2, sat_3_3, 1.0], [sat_4_1, sat_4_2, sat_4_3, 1.0]])
# Then its transpose:
LOS_Matrix_t = LOS_Matrix.transpose()
# Next the guide says to compute the covariance matrix which is said to be equal to the inverse of LOS_Matrix * LOS_Matrix_t, so:
cov_matrix = np.linalg.inv(LOS_Matrix * LOS_Matrix_t)
# This should now lets me calculate the DOP values such as GDOP, PDOP, etc
PDOP = np.sqrt(cov_matrix[0, 0] + cov_matrix[1, 1] + cov_matrix[2, 2])
# This comes out as 2.25575033021 which is possbile though it seems suspiciously low
# Also TDOP can't be computed since cov_matrix[3, 3] is a negative number so something must be wrong I guess?
我是一个 python 菜鸟,数学也不是我的强项,我只是通过谷歌搜索一条又一条错误消息才走到这一步。
我现在运行时没有任何错误消息,但它似乎也不正确,否则 TDOP 值应该是可计算的,例如。
有人知道问题出在哪里吗?
干杯
cov_matrix = np.linalg.inv(LOS_Matrix * LOS_Matrix_t)
应该是
cov_matrix = np.linalg.inv(LOS_Matrix.dot(LOS_Matrix_t))
我知道我知道,这令人困惑。但是在 numpy 中你有两种不同的类型,一种是你应该使用的 ndarray
,另一种是你不应该使用的矩阵。对于 ndarray
乘法默认为逐元素乘法。