# Re: [R] How do I write a sum of matrixes??

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Tue, 06 May 2008 12:55:58 +0000 (UTC)

pascal vrolijk <pascalvrolijk_at_hotmail.com> wrote in news:BAY120-W47837F2A708683682EB44AACD60_at_phx.gbl:

> Hello best helpers,
>
> I am a new user and I have been struggling for hours. So finally I
> decide to ask you: If I have a matrix P, and P.2 = P%*%P, and
> P.3=P.2%*%P is there a function to calculate the power of a matrix??
> if not how can i do: for (i in 1:10) {P.i=P^i}

Three methods show up in a search "r-help power of a matrix":

1. Use a pre-built function: library(msm) ?MatrixExp

This is probably as good a way as any way for this kind of problem. First define a binary operator:

with(eigen(x), vectors %*% (values^n * t(vectors)))

[,1] [,2]
[1,] 1.0 0.4
[2,] 0.4 1.0

[,1] [,2]
[1,] 1.0680744 -0.2229201
[2,] -0.2229201 1.0680744

```--
David Winsemius

> after this I need to sum them up and my problem is to combine P and

> i to P.i  can anyone help me please???
>
> Thanks and have a nice day,
>
> Pascal.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help