# Functions with Variable Numbers of Arguments: Outer Vector Product

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.

Thanks!

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

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.

Edit:

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

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