Skip to main content
added 978 characters in body
Source Link
Teun Zijp
  • 283
  • 2
  • 7

I totally agree with @InquisitiveInquirer. Multiplication of a (3x1) with a (1x3) matrix should give a (3x3) matrix. I was struggling with this as well. I worked with Mathematica for years, but suddenly I need to switch to Mathlab, because it makes better sense with matrix multiplication.

In case you'd like to switch to Mathlab, I give the comands + MWE for (2x1) and (1x2) matrix multiplication below.

b1 = {a, b};
b2 = {c, d};
Print["Mathematica ", MatrixForm[b1], "*", MatrixForm[b2], " = ", MatrixForm[b1*b2], ". In Mathlab: ", MatrixForm[b1], ".*", MatrixForm[b2], " = ", MatrixForm[b1*b2]]

$$\text{Mathematica }\left(\begin{array}{c}a\\b\end{array}\right)*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right)\text{. In Mathlab: }\left(\begin{array}{c}a\\b\end{array}\right).*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right) $$

Print["Mathematica ", MatrixForm[b1], ".", MatrixForm[b2], " = ", b1.b2, ". In Mathlab: ", MatrixForm[{b1}], "*", MatrixForm[b2], " = ", b1.b2]

$$ \text{Mathematica }\left(\begin{array}{c} a \\ b \end{array}\right) . \left(\begin{array}{c} c \\ d\end{array}\right) = a c+b d\text{. In Mathlab: }\left(\begin{array}{cc} a & b\end{array}\right) * \left(\begin{array}{c} c \\ d\end{array}\right) = a c+b d$$

Print["Mathematica Outer[Times,{{c,d}},{a,b}] = ",MatrixForm[Outer[Times,{b2},b1]],". In Mathlab: ",MatrixForm[b1],"*",MatrixForm[{b2}]," = ",MatrixForm[Outer[Times,{b2},b1]]]

$$\text{Mathematica Outer[Times,}\left(\begin{array}{cc}c & d\end{array}\right),\left(\begin{array}{c}a\\b\end{array}\right) \text{] = }\left(\begin{array}{c}a c & b c \\a d & b d \end{array}\right)\text{. In Mathlab: }\left(\begin{array}{c}a\\b\end{array}\right)*\left(\begin{array}{cc}c & d\end{array}\right) = \left(\begin{array}{c}a c & b c \\a d & b d \end{array}\right) $$

I totally agree with @InquisitiveInquirer. Multiplication of a (3x1) with a (1x3) matrix should give a (3x3) matrix. I was struggling with this as well. I worked with Mathematica for years, but suddenly I need to switch to Mathlab, because it makes better sense with matrix multiplication.

In case you'd like to switch to Mathlab, I give the comands + MWE for (2x1) and (1x2) matrix multiplication below.

b1 = {a, b};
b2 = {c, d};
Print["Mathematica ", MatrixForm[b1], "*", MatrixForm[b2], " = ", MatrixForm[b1*b2], ". In Mathlab: ", MatrixForm[b1], ".*", MatrixForm[b2], " = ", MatrixForm[b1*b2]]

$$\text{Mathematica }\left(\begin{array}{c}a\\b\end{array}\right)*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right)\text{. In Mathlab: }\left(\begin{array}{c}a\\b\end{array}\right).*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right) $$

I totally agree with @InquisitiveInquirer. Multiplication of a (3x1) with a (1x3) matrix should give a (3x3) matrix. I was struggling with this as well. I worked with Mathematica for years, but suddenly I need to switch to Mathlab, because it makes better sense with matrix multiplication.

In case you'd like to switch to Mathlab, I give the comands + MWE for (2x1) and (1x2) matrix multiplication below.

b1 = {a, b};
b2 = {c, d};
Print["Mathematica ", MatrixForm[b1], "*", MatrixForm[b2], " = ", MatrixForm[b1*b2], ". In Mathlab: ", MatrixForm[b1], ".*", MatrixForm[b2], " = ", MatrixForm[b1*b2]]

$$\text{Mathematica }\left(\begin{array}{c}a\\b\end{array}\right)*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right)\text{. In Mathlab: }\left(\begin{array}{c}a\\b\end{array}\right).*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right) $$

Print["Mathematica ", MatrixForm[b1], ".", MatrixForm[b2], " = ", b1.b2, ". In Mathlab: ", MatrixForm[{b1}], "*", MatrixForm[b2], " = ", b1.b2]

$$ \text{Mathematica }\left(\begin{array}{c} a \\ b \end{array}\right) . \left(\begin{array}{c} c \\ d\end{array}\right) = a c+b d\text{. In Mathlab: }\left(\begin{array}{cc} a & b\end{array}\right) * \left(\begin{array}{c} c \\ d\end{array}\right) = a c+b d$$

Print["Mathematica Outer[Times,{{c,d}},{a,b}] = ",MatrixForm[Outer[Times,{b2},b1]],". In Mathlab: ",MatrixForm[b1],"*",MatrixForm[{b2}]," = ",MatrixForm[Outer[Times,{b2},b1]]]

$$\text{Mathematica Outer[Times,}\left(\begin{array}{cc}c & d\end{array}\right),\left(\begin{array}{c}a\\b\end{array}\right) \text{] = }\left(\begin{array}{c}a c & b c \\a d & b d \end{array}\right)\text{. In Mathlab: }\left(\begin{array}{c}a\\b\end{array}\right)*\left(\begin{array}{cc}c & d\end{array}\right) = \left(\begin{array}{c}a c & b c \\a d & b d \end{array}\right) $$

Source Link
Teun Zijp
  • 283
  • 2
  • 7

I totally agree with @InquisitiveInquirer. Multiplication of a (3x1) with a (1x3) matrix should give a (3x3) matrix. I was struggling with this as well. I worked with Mathematica for years, but suddenly I need to switch to Mathlab, because it makes better sense with matrix multiplication.

In case you'd like to switch to Mathlab, I give the comands + MWE for (2x1) and (1x2) matrix multiplication below.

b1 = {a, b};
b2 = {c, d};
Print["Mathematica ", MatrixForm[b1], "*", MatrixForm[b2], " = ", MatrixForm[b1*b2], ". In Mathlab: ", MatrixForm[b1], ".*", MatrixForm[b2], " = ", MatrixForm[b1*b2]]

$$\text{Mathematica }\left(\begin{array}{c}a\\b\end{array}\right)*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right)\text{. In Mathlab: }\left(\begin{array}{c}a\\b\end{array}\right).*\left(\begin{array}{c}c\\d\end{array}\right)\text{ = }\left(\begin{array}{c}a c \\b d\end{array}\right) $$