Re: Element-by-element Matrix Multiplication
- To: mathgroup at smc.vnet.net
- Subject: [mg30081] Re: [mg30070] Element-by-element Matrix Multiplication
- From: BobHanlon at aol.com
- Date: Fri, 27 Jul 2001 03:52:18 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2001/7/26 1:32:34 AM, mcoleman at bondspace.com writes: >I'm searching for an efficient way to calculate and element-by-element >matrix multiplication for non-square matrices such that when I pass the >module an integer 'k', it multplies the matrix by itself 'k' times. For >instance, if k=25, then > > matMult[k,X] multiplies X*X*X..... 25 times. > > >Note that this problem comes about in calculating k-step Marvok transition >matrices. For my application, this function call is embedded in a Monte >Carlo simulation, so efficiency is important. The methods I've used to >date >seem "too slow" and I was hoping that some of the Mathematica gurus on >this list >might offer me suggestions on speeding things up. > If I understand what you mean by element-by-element it is just matMult[k_Integer, x_List] := x^k; mat = Array[a, {2, 3}]; matMult[3, mat] {{a[1, 1]^3, a[1, 2]^3, a[1, 3]^3}, {a[2, 1]^3, a[2, 2]^3, a[2, 3]^3}} However, for efficiency you should not use a function call just use x^k Bob Hanlon Chantilly, VA USA