0
$\begingroup$

I've seen the answers 1 and 2 about the transposition and creation of rank $m$ matrices.

What I'd like to do is first create a random vector, which I know how to do with

d = 3;

a = RandomReal[{-3, 3}, {d}]

and then create the matrix $A=\begin{pmatrix} a_1\\a_1\\a_3\end{pmatrix}\cdot(1,1,1)=\begin{pmatrix}a_1&a_1&a_1\\ a_2&a_2&a_2\\ a_3&a_3&a_3\end{pmatrix}$

But MatrixForm[a.Transpose[{1, 1, 1}]] doesn't work.

Edit:

I randomly ran the line TensorProduct[a, {1, 1, 1}] and that works (didn't expect to find an answer like that)

$\endgroup$
5
$\begingroup$

That's precisely what a KroneckerProduct is:

KroneckerProduct[{a1, a2, a3}, {1, 1, 1}]
(*    {{a1, a1, a1}, {a2, a2, a2}, {a3, a3, a3}}    *)
$\endgroup$
1
$\begingroup$

You have already answered your question. I only give two other solutions that came first into head:

 d = 3;
        a = RandomReal[{-3, 3}, {d}];
    a /. {x_, y_, z_} -> {{x, x, x}, {y, y, y}, {z, z, z}}

    (* {{1.62507, 1.62507, 1.62507}, {2.03748, 2.03748, 
      2.03748}, {-0.478757, -0.478757, -0.478757}}  *)

and

Map[Times[#, {1, 1, 1}] &, a]
    (* {{1.62507, 1.62507, 1.62507}, {2.03748, 2.03748, 
      2.03748}, {-0.478757, -0.478757, -0.478757}} *)

Have fun!

$\endgroup$
1
$\begingroup$

The operation you are looking for with your two vectors is the outer product. Hence:

a = RandomReal[{-3, 3}, 3];
b = RandomReal[{-3, 3}, 3];
Outer[Times, a, b]

gives the matrix.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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