[R] How do I write a sum of matrixes??
Vincent Goulet
vincent.goulet at act.ulaval.ca
Tue May 6 21:36:23 CEST 2008
Le mar. 06 mai à 14:23, Alberto Monteiro a écrit :
>> 3) Bill Venables offered this about a week ago in this list:
>> --------------
>> This is probably as good a way as any way for this kind of problem.
>> First define a binary operator:
>>
>>> "%^%" <- function(x, n)
>> with(eigen(x), vectors %*% (values^n * t(vectors)))
>>
> This example only works for _diagonalizable_ matrices. It
> crashes, for example, in cases like:
>
> m <- rbind(c(1,1,0), c(0,1,1), c(0,0,1))
> m %^% 2
> m %*% m
Then the %^% operator defined in package expm [1] will work for any
kind of (square) matrix. The actual work is done in C, so it is pretty
fast.
[1] On R-Forge: http://r-forge.r-project.org/projects/expm/
---
Vincent Goulet, Associate Professor
École d'actuariat
Université Laval, Québec
Vincent.Goulet at act.ulaval.ca http://vgoulet.act.ulaval.ca
More information about the R-help
mailing list