1

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?

Frankster
  • 653
  • 7
  • 26

1 Answers1

1

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.

Elikill58
  • 4,050
  • 24
  • 23
  • 45
Ahmad Zuhair
  • 39
  • 1
  • 4