Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to multiply an array by each element of another array, and am having a lot of trouble finding a built-in or automated method of doing.

Here is an example of what I'd like to achieve:

a = 0.5;
b = 4.0;

mat = {{0, 1}, {a, b}};
Rmat = RandomInteger[10, {4, 4}]
m11 = mat[[1, 1]]*Rmat;
m12 = mat[[1, 2]]*Rmat;
m21 = mat[[2, 1]]*Rmat;
m22 = mat[[2, 2]]*Rmat;

fmat = ArrayFlatten[{{m11, m12}, {m21, m22}}]

As you can see, the first matrix mat is multiplied by each individual element of Rmat. I feel like this should be easy, but I'm not finding a built-in function that works?

Thanks!

share|improve this question

3 Answers 3

ArrayFlatten[Outer[Times, mat, Rmat]]
share|improve this answer
    
Those both work thanks! –  gKirkland Mar 7 '14 at 4:16
    
@rasher...good old Outer,+1 –  ubpdqn Mar 7 '14 at 4:45

Try this:

ArrayFlatten[Map[Rmat*# &, mat, {2}]]
share|improve this answer

It was apparently missed by the other posters that KroneckerProduct[] is built-in:

KroneckerProduct[mat, Rmat]
share|improve this answer
    
Yep. Forgot it.... –  ciao Aug 21 at 19:57
    
J.M Could you help me question if you have time now? Please see here and here –  Shutao Tang Aug 22 at 7:40
    
@Shutao, not sure what those pictures are supposed to be. Why not write a proper question instead of a comment? –  Guess who it is. Aug 22 at 8:11
    
@Guesswhoitis. I think this small question could be solved in the chatting room. –  Shutao Tang Aug 22 at 8:14
    
Maybe this picture can express what I need. –  Shutao Tang Aug 22 at 8:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.