1
|
24909 Views
|
19 Replies
|
17 Total Likes
View groups...
Share
GROUPS:

# The Dot Operator vs Standard Matrix Multiplication

Posted 11 years ago
 The Dot operator can do both dot products and matrix multiplication. As a result,it can multiply a matrix by a row vector as in M.v, even though that's not kosherin linear algebra. I wonder if the documentation should warn about that.
19 Replies
Sort By:
Posted 2 years ago
 You have entered your matrices a,b in two dimensional form, but the kernel sees them a lists of lists: In[4]:= a Out[4]= {{1, 2}, {3, 4}, {5, 6}} There is no need to "convert" them to lists of lists.
Posted 2 years ago
 If I multiply a 2 by 3 matrix by a 3 by 2 in matrix form in either order, I get the expected answer, but in list form I get an error. I am pretty new to Mathematica, so maybe it's my fault, but this seems strange to me.Edit: I found that the problem is that List does not convert a matrix to a list of lists in the right form for a matrix.
Posted 4 years ago
 Here's my notebook with the above examples in it:/Users/chrisyoungsmacpro/Library/Mobile Documents/com~apple~CloudDocs/Documents/Math/Subjects/Algebra/Linear Algebra/Vectors, tensors/Mathematica; matrices and vectors with ~/Combining vectors and matrices/B3b. .nb Attachments:
Posted 4 years ago
 One main wish: Anywhere we have what is a vector argument to a function, we should be able to type it as a row or column vector. I've figured out that I can just add in a substitution rule to do that, so I guess that's not too much to ask. But it would be much easier just to have Mathematica convert row and column vectors to lists when they're passed to ParametricPlot, etc. Also, couldn't matrices be threaded over lists of vectors, instead of requiring the clutter of mapping the dot-product? And why doesn't MatrixForm applied to the result give me the expected list of matrices, in standard layout. Even TraditionalForm, doesn't give the expected, traditional list of vectors in column form. The readability of column vectors vs. lists is worth it to me. If I have time, I'll try to develop a linear algebra package that lets me use the time-tested traditional notation, from square brackets, to a space meaning matrix multiplication, to always being able to use traditional matrix and vector layout.It is a good feature that I can use oblong matrices to put all my vertices into, so I won't complain too much about these small difficulties. I'm assuming that the different forms of bracketing needed in column vectors versus row vectors have some payoff later in terms of being able to use the Dot[ ] function with tensors. But for beginners, I think it would be good not to have any extra quirks or hurdles for them to get over.
Posted 4 years ago
 Can you explain in more details those hoops you feel you need jump through? Surely you do not mean the simple matter of having to use . instead of *?
Posted 4 years ago
 It looks like regular Times[ ] multiplication does element-by-element multiplication, as least in these cases. What drives me crazy is the hoops I have to jump through just to do standard linear algebra such as multiplying a matrix times a column vector. More on that later. Have to watch myself as a humble Home User.enter image description here
Posted 4 years ago
Posted 11 years ago
 For me, the biggest gotcha for the unsuspecting with Dot is that it's noncommutative. If you're innocently normalizing vectors without a keen and active understanding of Mathematica's generalized approach to tensors and of its Attributes structure (like knowing that noncommutativity is flagged by the ABSENCE of Orderless-ness) you might be in for some troubled times.Fred
Posted 11 years ago
 I think the fact that Dot is more general than matrix multiplication should be at the start of its documentation, not inside Detail or Possible Issues.  For example:  "a.b.c or Dot[a,b,c] gives products of vectors, matrices and tensors.  Note that Dot works in a more general way than matrix mulitplication.  See Details and Possible Issues"Mathematica is typically regarded as being very powerful but having a steep learning curve.  Anything that makes it easier for new users is a good thing, in my opinion.
Posted 11 years ago
 But isn't it already explained under the Detail section?  There are explicit examples for vector-vector, vector-matrix, matrix-vector and matrix-matrix products, followed by a general definition of tensor contraction, written out explicitly using sums.
Posted 11 years ago
 Yes, so think of all the questions to Stack Exchange that could be eliminated by simply explaining in the documentation how Mathematica takes a more general approach to vectors than other software.  You don't want to discourage people who are trying to switch to Mathematica.  Perhaps I'm thinking of this from a marketing viewpoint.  I suppose that's one of the dangers of having a Ph.D. in Physics and an M.B.A.  However, given the recent push to increase Mathematica's presence in STEM, I think that my suggestion makes sense.
Posted 11 years ago
 Mathematica was designed to work with tensors of arbitrary dimensions, not just 2-dimensional matrices.  Correspondingly, Dot[] does tensor contraction, not just matrix multiplication.  I find this implementation much more logical and consistent than what I see in rigidly matrix based systems like MATLAB, which don't even support vectors.On Mathematica.SE I regularly see people trying to use "row vectors" and "column vectors" and a lot of transposision and complex indexing to try to do simple tasks.  This is all unnecessary complication in Mathematica, which does support proper 1D vectors, as well as N-D tensors.  I believe most of these people come from MATLAB or MATLAB-inspired software which typically doesn't support vectors at all, only row and column matrices.When I studied linear algebra, we started with vectors, not "row vectors" and "column vectors", and I didn't find it confusing.  So it's not quite accurate to say that this is "not kosher".  There are different traditions of teaching this stuff.  One is not necessarily better than the other.
Posted 11 years ago
 I'm not saying that Dot fails at matrix multiplication; I'm saying that it overachieves.  That's fine except that it could be confusing to students learning linear algebra.
Posted 11 years ago
 It is somewhat missing the point to talk about how Dot fails as matrix multiplication.  The point of Dot is that it is a tensor operation and that it sometimes corresponds to matrix multiplication. In terms of tensor indices, Dot contracts the right-most index of the first entry with the left-most index of the second. Using Part for indices we have for a tensor of rank p+1 and a tensor of rank q+1 then Dot gives a tensor of rank p+q.(T.U)[[i1,i2,...,ip,j1,j2,...,jq]]=Sum[T[[i1, i2, ..., ip, k]] U[[k, j1, j2, ..., jq]], {k, 1, n}]It is typical in Mathematica to define functions that are as general as they can reasonably be; Dot is a tensor generalization of matrix multiplication.
Posted 11 years ago
 Maybe it does need more explaining. Personally I am not entirely convinced, but in any case, there is a 'Give Feedback' button at the bottom of each web documentation page, which is an excellent way to send any feedback or suggestions about the documentation content.
Posted 11 years ago
 Ilian, rather than putting this in "Possible Issues", I'd suggest putting it in the main description, explaining how Mathematica's treatment of a matrix as a list of lists enables returning a list of dot products, as a row vector, when mulitplying a matrix by a row vector.
Posted 11 years ago
 I think this is exactly why the 'Possible Issues' give an explicit illustration for the {1, 1} and {{1}, {1}} cases, thereby making the same point. Both results are certainly correct according to the formal tensor definition given in the Details section.
Posted 11 years ago
 I don't think what's said in Possible Issues is completely correctIn[1]:= {{1, 2}, {3, 4}}.{5, 6}Out[1]= {17, 39}In[2]:= {{1, 2}, {3, 4}}.{{5}, {6}}Out[2]= {{17}, {39}}since you can use dot to right mulitply a matrix by a column vector.
Posted 11 years ago
 See 'Possible Issues' in the Dot documentation: Dot effectively treats vectors multiplied from the right as column vectors.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.