1
$\begingroup$

I'm trying to multiply a matrix 4x1 with a vector 1x4. I'm supposed to get a matrix 4x4. When I try to multiply both matrices I get an error, incompatible shapes. It doesn't make any sense because the shapes are compatible so probablyh I'm doing something wrong:

B = {{3619.3}, {3619.3}, {-29800}, {0}} 
Cc = {0, 0, 0, 1} 
B.Cc 

Dot::dotsh: Tensors {{3619.3},{3619.3},{-29800},{0}} and {0,0,0,1} have incompatible shapes.

I tried doing similar multiplications but sometimes Matheamtica doesn't give any error but gives me wrong a answer which is worse. What Am I doing wrong?

$\endgroup$
6
  • 1
    $\begingroup$ You probably want Outer[Times, {3619.3, 3619.3, -29800, 0}, {0, 0, 0, 1}]. $\endgroup$ Commented Sep 8, 2017 at 15:29
  • $\begingroup$ Have a look at the this tutorial and related ones. The error message you get is very explicit about what went wrong. $\endgroup$ Commented Sep 8, 2017 at 15:33
  • 3
    $\begingroup$ You could do B . {Cc} instead. $\endgroup$
    – Carl Woll
    Commented Sep 8, 2017 at 15:48
  • 1
    $\begingroup$ You might want to read this. $\endgroup$ Commented Sep 8, 2017 at 15:54
  • 1
    $\begingroup$ TIL: As explained in the answer JM links, one might also do {{3619.3}, {3619.3}, {-29800}, {0}}.{{0, 0, 0, 1}}, which you might find more satisfying. Essentially to force Mathematica to think of it as a row vector, you have to make it a 1xn matrix. (Edit I now realize Carl Woll also said something similar above.) $\endgroup$
    – jjc385
    Commented Sep 8, 2017 at 16:31

0

Browse other questions tagged or ask your own question.