[R] matrix exponential: M^0
Federico Calboli
f.calboli at ucl.ac.uk
Wed Jan 21 20:26:18 CET 2004
Dear All,
Thanks for all the help. I tried to implement Stephane Dray's suggestion
and Erin Hodgess function with the following matrices:
> A
[,1] [,2]
[1,] 2 1
[2,] 1 3
> P
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 2 3 4
> D
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
[3,] 0 0 0
But I run in a number of troubles, probably my fault. I also tried
MatrixExp from the library msm, but I failed to understand how to use
it.
anyway, as my linear algebra is too poor for any intelligent
decomposition and whatnot, and I wanted a function, I went for the brute
force approach.
mtx.exp<-function(X,n){
if (n==0) {
phi<-diag(rep(1,length(X[1,])))
return(phi)
}
if (n==1) {
phi<-X
return(phi)
}
X1<-X
for (i in 2:n) {
X<-X%*%X1
}
phi<-X
return(phi)
}
I would imagine this approach would be memory inefficient; would it
incurr in other problems?
Again, many thanks to all for the invaluable help.
Regards,
Federico Calboli
--
=================================
Federico C. F. Calboli
PLEASE NOTE NEW ADDRESS
Dipartimento di Biologia
Via Selmi 3
40126 Bologna
Italy
tel (+39) 051 209 4187
fax (+39) 051 251 208
f.calboli at ucl.ac.uk
More information about the R-help
mailing list