Qiang Li
Qiang Li

Reputation: 10865

How to calculate a matrix formed by vector in Mathematica

I need to obtain a matrix vvT formed by a column vector v. i.e. the column vector v matrix times its transpose.

I found Mathematica doesn't support column vector. Please help.

Upvotes: 3

Views: 3394

Answers (1)

Mr.Wizard
Mr.Wizard

Reputation: 24336

Does this do what you want?

v = List /@ Range@5;
vT = Transpose[v];
vvT = v.vT;

v // MatrixForm
vT // MatrixForm
vvT // MatrixForm

Mathematica graphics

To get {1, 2, 3, 4, 5} into {{1}, {2}, {3}, {4}, {5}} you can use any of:

List /@ {1, 2, 3, 4, 5}

{ {1, 2, 3, 4, 5} }\[Transpose]

Partition[{1, 2, 3, 4, 5}, 1]

You may find one of these more convenient than the others. Usually on long lists you will find Partition to be the fastest.

Also, your specific operation can be done in different ways:

x = {1, 2, 3, 4, 5};

Outer[Times, x, x]

Syntactically shortest:

{Range@5}; %[Transpose].%

Upvotes: 7

Related Questions