If you have big powers or big matrices you might want to use the repeated-squaring trick, something like

mpwr =: 4 : 'p =. x for_i. }. #: y do. p =. x mp^:i p mp p end.'

fails for y <: 0

Henry Rich


On 10/4/2013 12:26 PM, km wrote:
Verb mpwr calculates matrix powers .  Is there a tacit way?

  mp =: +/ . *  NB. matrix product

  mpwr =: 4 : 'x mp^:y =i.#x' NB. square matrix x to integer power y

  A =: 1 1 ,: 1 0

     A
  1 1
  1 0
     A mpwr 3
  3 2
  2 1
     A mp A mp A
  3 2
  2 1
     A mpwr _1
  0  1
  1 _1
     A mp A mpwr _1
  1 0
  0 1

--Kip Murray

Sent from my iPad

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to