I am trying to write a function that takes a column vector of variable dimension as an input and returns the outer product matrix as an output.

What I have tried:

OuterVectorProduct[x__] := MatrixForm[Outer[Times, x, x]]

However, this obviously returns wrong results.


  • $\begingroup$ can you post an example of wrong result? $\endgroup$
    – kglr
    Commented Aug 4, 2019 at 13:49
  • $\begingroup$ @kglr Having MatrixForm in the definition makes it a bit useless for further computation. Otherwise, its fine (except x_ would be better than x__). $\endgroup$ Commented Aug 4, 2019 at 22:17

1 Answer 1


Here is a simple example that will get you started,

x = {x1, x2, x3};
y = {y1, y2};

(xy = KroneckerProduct[x, y]) // MatrixForm

(* get 3x2 matrix output *) 

(yx = KroneckerProduct[y, x]) // MatrixForm 

(* get 2x3 matrix output *) 

The parentheses are important --- compare the FullForm of the resulting "matrix" if you leave them out.


In answer to your specific Qn,

OuterVectorProduct[x_] := KroneckerProduct[x, x]

which will work for a vector x for any value of Dimensions[x].

  • $\begingroup$ Thanks for your answer! My issue is, though, that I am struggling with the variable nature of my arguments, not the syntax of the outer product. $\endgroup$
    – Pentaquark
    Commented Aug 4, 2019 at 12:55
  • $\begingroup$ Thank you for your help! $\endgroup$
    – Pentaquark
    Commented Aug 4, 2019 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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