【发布时间】:2015-12-25 16:47:52
【问题描述】:
这是一个矩阵问题,我试图解决一个满足 2 个或更多矩阵方程的最佳拟合非负 x。我能够单独求解方程,但我不知道如何同时求解所有 'n' 矩阵。
Ax - c = Bx - d = Ex - f = ... = 0
下面我有 2 组我单独求解的矩阵。
Ax = c
By = d
x = y 没有约束
require(pracma)
require(corpcor)
require(NMF)
mat=c(0.005,0.006,0.002,0,0,0,0,
0,0.005,0.006,0.002,0,0,0,
0,0,0.005,0.006,0.002,0,0,
0,0,0,0.005,0.006,0.002,0,
0,0,0,0,0.005,0.006,0.002,
0,0,0,0,0,0.005,0.006,
0.003,0.004,0.002,0,0,0,0,
0,0.003,0.004,0.002,0,0,0,
0,0,0.003,0.004,0.002,0,0,
0,0,0,0.003,0.004,0.002,0,
0,0,0,0,0.003,0.004,0.002,
0,0,0,0,0,0.003,0.004
)
mat = matrix(mat,byrow=T,ncol=7)
rownames(mat) = rep(c("Group A", "Group B"), times = c(6,6))
mat.A = mat[rownames(mat) == "Group A",]
mat.B = mat[rownames(mat) == "Group B",]
y.A = sample(c(100:500), 7)
y.B = sample(c(200:300), 7)
# Solve B
a = t(mat.A)
b = as.numeric(y.A)
Test.a = qr(a, tol = 0.0000001)
nc = ncol(Test.a$qr)
nr = nrow(Test.a$qr)
if (Test.a$rank != min(nc, nr)){
x = ceiling(fcnnls(a,b, pseudo = T)$x)
} else x = ceiling(lsqnonneg(a,b)$x)
# Solve A
a = t(mat.B)
b = as.numeric(y.B)
Test.a = qr(a, tol = 0.0000001)
nc = ncol(Test.a$qr)
nr = nrow(Test.a$qr)
if (Test.a$rank != min(nc, nr)){
x = ceiling(fcnnls(a,b, pseudo = T)$x)
} else x = ceiling(lsqnonneg(a,b)$x)
【问题讨论】: