R right matrix division

What is the most concise, fastest, most numerically stable, most R-idiomatic way to do left and right matrix division in R? I understand that left division is inv(A)*Busually done with solve(a,b), but what about B*inv(A)? Best way to really calculate t(solve(t(A),t(B)))?

+4
source share
2 answers

I have no better solution than B %*% solve(A), but I would like to note that overall it solve(A,B)works faster and is numerically more stable than that 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
+1
source

B %*% solve(A), solve(A) A.

+2

All Articles