Sorry I didn't answer before.

   Martin, thanks very much for your notes and for tidying the function
   up!= ! I've learnt a lot with you.

   About matPower, I didn't realise that where it says "pot <- pot %*% p   ot", 
consumption of memory was higer than it was on the original
   algorithm,= where a function to calculate M^2 where implemented.

   And about the other function in this thread, matExp, I can remember I
   us= ed Horner's algorithm to get an aproximation to it. I must have a
   look to m= y old library.

   >Message: 27
   >Date: Thu, 22 Jan 2004 18:22:27 +0100
   >= From: Martin Maechler <[EMAIL PROTECTED]>
   >Subject: [R= ] Re: matrix __power__ (was "exponential")
   >To: Vicente Canto Casasol= a <[EMAIL PROTECTED]>
   >Cc: [EMAIL PROTECTED] h.ethz.ch
   >Message-ID: <[EMAIL PROTECTED] L>
   >Content-Type: text/plain; charset=us-ascii
   >
   >&g= t;>>>> "Vicente" == Vicente Canto Casasola <vicented.can   [EMAIL PROTECTED]>
   >>>>>>   &nbs= p; on Thu, 22 Jan 2004 14:34:01 +0100 writes:
   >
   > &nb= sp; Vicente> H i, all!  First of all, I'd like to apologize fo   r
   >   Vicente> my poor English. It's for years I do= n't use it.
   >
   >no problem at all.

   Well, that is because I'm not speaking!! ;)

   >
   >   Vicente> This is a R-version of a funct= ion I wrote a long
   >   Vicente> ago for my HP48 cal= culator.  It works with the
   >   Vicente> binar= y expression of the power and just need to
   >   Vicente= > duplicate the mem used by X.
   >
   >excellent. This is really = the way to solve the problem
   >I think.
   >
   >As I've menti= oned earlier in this thread,
   >computing a matrix "power" is really mu= ch easier than the
   >matrix exponential.

   I do agree. It did sound strange to me, but I followed the thread!

   >
   >Hence I wouldn't use exponential in the function name.
   &g= t;Also note that trailing ";" are considered as `dirty' (they are
   >co= mpletely superfluous).

   A C++ tic I have to correct!! Thank you, Martin.

   >
   >These slight modifications (+ initial "test")
   >give>
   >matPower <- function(X,n)
   >## Function to calculate = the n-th power of a matrix X
   >{
   >   if(n != ro= und(n)) {
   >       n <- round(n)   >       warning("rounding exponen= t `n' to", n)
   >   }
   >   phi <-= diag(nrow = nrow(X))
   >   pot <- X # the first po= wer of the matrix.
   >
    >  while (n > 0)
   >= ;   {
   >       if (n= %% 2)
   >          &= nbsp;phi <- phi %*% pot
   >
   >     &nb= sp; n <- n %/% 2
   >       p= ot <- pot %*% pot
   >   }
   >   return(= phi)
   >}

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to