grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
130 stars 24 forks source link

matrix inversion is very slow #326

Closed grzegorzmazur closed 3 years ago

grzegorzmazur commented 3 years ago

I tested pow.yac_symbol with a 2 by 2 matrix using a negative n power and it worked properly.

Apparently the inverse of x in the case above takes forever on my machine using any of the following: y_fn(ysym(x), "MatrixPower", -1), yac_str(paste0("MatrixPower(", ysym(x), ",", -1, ")")), and solve(x)

I also tried the same matrix as input in yacas (see below) and the same happens. There is nothing wrong with the implementation of pow.yac_symbol. It just takes to long to obtain a solution in yacas for this case. Obtaining the inverse of a matrix is not a trivial task.

x := {{36.32,-633.09,-320.73,2.19,-5.11,4.50},
        {-633.09, 15360.79, 6721.15, -47.06, 107.68, -96.05},
        {-320.73, 6721.15, 4700.86, -16.45, 44.19, -86.77},
        {2.19, -47.06, -16.45, 0.28, -0.37, 0.08},
        {-5.11, 107.68, 44.19, -0.37, 0.95, -0.30},
        {4.50, -96.05, -86.77, 0.08, -0.30, 3.19}};
Inverse(x);
MatrixPower(x, -1);

Note, however, that pow.default does not have this issue.

In summary,

Let me know which direction you wish to take.

Originally posted by @jeksterslab in https://github.com/r-cas/ryacas/issues/56#issuecomment-779276725