0
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ can you post an example of wrong result? $\endgroup$ – kglr Aug 4 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$ – Andrew Norton Aug 4 at 22:17
1
$\begingroup$

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:

In answer to your specific Qn,

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

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

$\endgroup$
  • $\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 Aug 4 at 12:55
  • $\begingroup$ Thank you for your help! $\endgroup$ – Pentaquark Aug 4 at 14:18

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.