Reputation: 689
I'm trying to perform vector and matrix operations by using the mathJS package.
I have a vector which I want to turn into a matrix by mulitplying with its transpose.
The expected result would be
a = [1 1 1], [1x3] vector
a^T = [1 1 1]^T, [3,1] vector
[1, 1, 1]
a^T * a = [1, 1, 1]
[1, 1, 1]
For some reason I'm having problems constructing a column vector in javascript because
const test1 = math.multiply(math.transpose([1, 1, 1]), [1, 1, 1]);
const test2 = math.multiply([1, 1, 1], math.transpose([1, 1, 1]));
both test1 and test2 returns 3. What am I missing?
Upvotes: 1
Views: 907
Reputation: 49
You were missing the brackets.
const test1 = math.multiply(math.transpose([[1, 1, 1]]), [[1, 1, 1]]);
The dimensions of [1, 1, 1]
is 1, but for [[1, 1, 1]]
, it is 1x3.
Upvotes: 1