R中的矩阵功效 [英] Matrix power in R

查看:340
本文介绍了R中的矩阵功效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试计算R中矩阵的幂,发现包expm实现了运算符解决方案

我已修复了R-forge源("expm"程序包中)的错误, svn版本53.-> expm R-forge页面 由于某种原因,该网页仍显示修订版52,因此可能尚未显示以下内容 解决您的问题(但应在24小时之内):

 install.packages("expm", repos="http://R-Forge.R-project.org")

否则,直接获取svn版本,并自行安装:

 svn checkout svn://svn.r-forge.r-project.org/svnroot/expm

感谢"gd047"通过电子邮件将问题通知我. 请注意,R-forge还具有自己的错误跟踪功能.
马丁特(Martint)

Trying to compute the power of a matrix in R, I found that package expm implements the operator %^%.

So x %^% k computes the k-th power of a matrix.

> A<-matrix(c(1,3,0,2,8,4,1,1,1),nrow=3)

> A %^% 5
      [,1]  [,2] [,3]
[1,]  6469 18038 2929
[2,] 21837 60902 9889
[3,] 10440 29116 4729

but, to my surprise:

> A
     [,1] [,2] [,3]
[1,]  691 1926  312
[2,] 2331 6502 1056
[3,] 1116 3108  505

somehow the initial matrix A has changed to A %^% 4 !!!

How do you perform the matrix power operation?

解决方案

I have fixed that bug in the R-forge sources (of "expm" package), svn rev. 53. --> expm R-forge page For some reason the web page still shows rev.52, so the following may not yet solve your problem (but should within 24 hours):

 install.packages("expm", repos="http://R-Forge.R-project.org")

Otherwise, get the svn version directly, and install yourself:

 svn checkout svn://svn.r-forge.r-project.org/svnroot/expm

Thanks to "gd047" who alerted me to the problem by e-mail. Note that R-forge also has its own bug tracking facilities.
Martint

这篇关于R中的矩阵功效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆