本文介绍了R右矩阵除法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在R中进行左右矩阵除法的最简洁,最快,最数值稳定,最R惯用的方法是什么?我知道通常用solve(a,b)
进行左除法inv(A)*B
,但是B*inv(A)
怎么样?真的是计算t(solve(t(A),t(B)))
的最佳方法吗?
What's the most succinct, fastest, most numerically stable, most R-idiomatic way to do left and right matrix division in R? I understand left division inv(A)*B
is usually done with solve(a,b)
, but how about B*inv(A)
? Is the best way really to compute t(solve(t(A),t(B)))
?
推荐答案
我没有比B %*% solve(A)
更好的解决方案,但是我确实想指出,通常solve(A,B)
比[c5]更快,并且在数值上更稳定solve(A) %*% B
.
I don't have a solution better than B %*% solve(A)
, but I did want to point out that in general solve(A,B)
is faster and more numerically stable than solve(A) %*% B
.
> A = matrix(rnorm(10000),100,100)
> B = matrix(rnorm(10000),100,100)
> microbenchmark(solve(A,B), solve(A) %*% B, t(solve(t(B),t(A))), B %*% solve(A))
Unit: microseconds
expr min lq mean median uq max neval
solve(A, B) 481.695 604.2435 722.2512 677.2455 761.735 1280.888 100
solve(A) %*% B 628.243 830.2095 1056.3947 927.0130 1204.682 5275.030 100
t(solve(t(B), t(A))) 603.855 792.1360 1164.7210 924.0895 1122.184 10351.307 100
B %*% solve(A) 645.119 784.1990 1070.4751 927.9400 1097.601 7866.591 100
这篇关于R右矩阵除法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!