## 计算1-D阵列之间的协方差，以便在Python中结合不确定性的传播内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (0)
• 关注 (0)
• 查看 (114)

import numpy as np

A=np.asarray([0.195, 0.154, 0.208, 0.22, 0.204, 0.175, 0.184, 0.187, 0.171, 0.2, 0.222, 0.235, 0.206, 0.215, 0.222, 0.252, 0.269, 0.251, 0.285, 0.28])
B=np.asarray([0.119, 0.134, 0.132, 0.121, 0.11, 0.097, 0.13, 0.106, 0.103, 0.139, 0.124, 0.147, 0.152, 0.123, 0.177, 0.172, 0.18, 0.182, 0.197, 0.193])
C=np.asarray([0.11, 0.1, 0.103, 0.111, 0.105, 0.098, 0.099, 0.093, 0.105, 0.099, 0.113, 0.093, 0.104, 0.095, 0.099, 0.105, 0.108, 0.128, 0.125, 0.118])
D=np.asarray([-0.015, -0.015, -0.007, -0.02, 0.002, 0.009, 0.019, 0.0, -0.02, -0.001, -0.006, -0.015, -0.03, -0.036, -0.051, -0.058, -0.065, -0.081, -0.082, -0.055])

A_err=np.asarray([ 0.016,  0.015,  0.017,  0.016,  0.015,  0.016,  0.016,  0.018, 0.015,  0.014,  0.015,  0.016,  0.017,  0.016,  0.017,  0.017, 0.017,  0.017,  0.017,  0.017])
B_err=np.asarray([ 0.045,  0.049,  0.039,  0.044,  0.036,  0.027,  0.032,  0.033, 0.029,  0.036,  0.032,  0.027,  0.04 ,  0.022,  0.034,  0.026, 0.021,  0.028,  0.035,  0.028])
C_err=np.zeros(20)+0.7
D_err=np.zeros(20)+0.9

Y是A，B，C和D的总和，我试图找出Y上的误差，因为A，B，C和D是因变量。

Y=A+B+C+D

Y_err =？

X = np.vstack([A,B,C,D])
X = np.cov(X)
print(X)
[[  1.31819737e-03   9.52921053e-04   2.17881579e-04  -8.58197368e-04]
[  9.52921053e-04   9.87252632e-04   1.69478947e-04  -7.97089474e-04]
[  2.17881579e-04   1.69478947e-04   9.47868421e-05  -1.88007895e-04]
[ -8.58197368e-04  -7.97089474e-04  -1.88007895e-04   8.85081579e-04]]

σ_AB=9.52921053e-04
σ_AC=2.17881579e-04
σ_AD=-8.58197368e-04
σ_BC=1.69478947e-04
σ_BD=-7.97089474e-04
σ_CD=-1.88007895e-04

### 1 个回答

X = np.vstack([A,B,C,D])
cov = np.cov(X)
c = np.asarray([1, 1, 1, 1])                    # coefficients: linear combination

np.matmul(c.T, np.matmul(cov,c))

# 0.002279292105263158