0

How can i perform a matrix multiplication of a and b because when I do a + b, it combines the two matrices. And also how to create a matrix of n*n dimensions. Thank you as you help.

<html>
<body></body>
<script>
Var a=[1,2,3]
Var b=[4,5,6]
Var e=a + b
Var c=[]
C.push(e)
Console.log(c)
Document.write(e)
</script>
</html>
chika
  • 177
  • 1
  • 3
  • 12
  • 4
    This question can be seen as a duclicate of [this question](http://stackoverflow.com/questions/27205018/multiply-2-matrices-in-javascript) – Codor Jun 23 '16 at 06:40
  • take look of math.js library, it allow to work with matrix – Jax Teller Jun 23 '16 at 06:41

1 Answers1

1

Expanding on @A.Rossi's answer:

  var a = math.matrix([1,2,3]);
  var b = math.matrix([4,5,6]);
  var e = math.add(a,b);
  document.write(e);

Demo here

neer
  • 4,031
  • 6
  • 20
  • 34
derp
  • 2,300
  • 13
  • 20
  • How about creating an n*n matrix and inverting the matrix. – chika Jun 23 '16 at 07:02
  • var e = math.inv(a); – derp Jun 23 '16 at 07:27
  • Sorry for disturbing again @derb. D code above didn't work. D browser was showing a blank page when i run the program. But if I do a=[1,2,3] it will show. So the problem of adding d .matrix still exists – chika Jun 23 '16 at 08:31
  • try opening up your browser console. My maths isn't that good but apparently not all matrices are invertable. When i was testing my own examples, i turned a into a 3 * 3 matrix before callling math.inv(a) – derp Jun 23 '16 at 13:49