From: Vince Virgilio on 26 May 2010 07:06 On May 25, 6:32 am, "S. B. Gray" <stevebg(a)ROADRUNNER.COM> wrote: SNIP > ambiguous, but I assumed the dot product would always commute. Should > there be a warning? SNIP Nope, this is just the usual behavior of an inner product of a matrix and vector. The doc. says that Dot[] contracts the last dimension of the first tensor, with the first dimension of the second tensor. So if either operand has dims > 1, Dot[] doesn't commute. Vince Virgilio
From: Simon on 26 May 2010 07:08 Hi Steve, The result is correct, since {aa,bb,cc} is treated as a vector that can be either row or column. Then, thinking of matrix multiplication - with indices and summation convention (A.v)_i = A_{i j} v_j => A.v = ( A_{1 j}v_j , A_{2 j}v_j , A_{3 j} v_j ) (v.A)_i = v_j A_{j i} => v.A = ( A_{j 1}v_j , A_{j 2}v_j , A_{j 3 } v_j ) If you want your dot products to be unambiguous, then write your vector as a 3x1 or a 1x3 matrix - equivalent to a column and row vector resp. So using your objects: In[1]:= ptsa={{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}}; Column vector: In[2]:= ptsa.{{aa},{bb},{cc}} Out[2]= {{aa x1+bb y1+cc z1},{aa x2+bb y2+cc z2},{aa x3+bb y3+cc z3}} Fails if used the wrong way round: In[3]:= {{aa},{bb},{cc}}.ptsa During evaluation of In[3]:= Dot::dotsh: Tensors {{aa},{bb},{cc}} and {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}} have incompatible shapes. >> Out[3]= {{aa},{bb},{cc}}.{{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}} Row vector: In[4]:= {{aa,bb,cc}}.ptsa Out[4]= {{aa x1+bb x2+cc x3,aa y1+bb y2+cc y3,aa z1+bb z2+cc z3}} Fails if used the wrong way around: In[5]:= ptsa.{{aa,bb,cc}} During evaluation of In[5]:= Dot::dotsh: Tensors {{x1,y1,z1}, {x2,y2,z2},{x3,y3,z3}} and {{aa,bb,cc}} have incompatible shapes. >> Out[5]= {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}}.{{aa,bb,cc}} ~~~ Simon On May 25, 6:32 pm, "S. B. Gray" <stev...(a)ROADRUNNER.COM> wrote: > Given > > ptsa = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}}; > > I thought the following expressions would be identical: > > {aa, bb, cc}.ptsa (* expression 1 *) > ptsa.{aa, bb, cc} (* expression 2 *) > > but they are not. They evaluate respectively as: > > {aa x1 + bb x2 + cc x3, aa y1 + bb y2 + cc y3, > aa z1 + bb z2 + cc z3} > > {aa x1 + bb y1 + cc z1, aa x2 + bb y2 + cc z2, > aa x3 + bb y3 + cc z3} > > Since ptsa is itself three xyz coordinates, the expressions might be > ambiguous, but I assumed the dot product would always commute. Should > there be a warning? > > The first result is the one I want. > > Steve Gray
From: inOr on 26 May 2010 07:08 On May 25, 3:32 am, "S. B. Gray" <stev...(a)ROADRUNNER.COM> wrote: > Given > > ptsa = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}}; > > I thought the following expressions would be identical: > > {aa, bb, cc}.ptsa (* expression 1 *) > ptsa.{aa, bb, cc} (* expression 2 *) > > but they are not. They evaluate respectively as: > > {aa x1 + bb x2 + cc x3, aa y1 + bb y2 + cc y3, > aa z1 + bb z2 + cc z3} > > {aa x1 + bb y1 + cc z1, aa x2 + bb y2 + cc z2, > aa x3 + bb y3 + cc z3} > > Since ptsa is itself three xyz coordinates, the expressions might be > ambiguous, but I assumed the dot product would always commute. Should > there be a warning? > > The first result is the one I want. > > Steve Gray Steve, The dot product is most definitely NON-commutative. To see this for a case like yours, think of vector-matrix multiplication as the transformation of a vector into a new vector. In real number representation, pre-multiplication of a vector by a matrix creates a new vector that is the sum of the column vectors of the matrix weighted by the elements of the vector. In this case, the matrix multiplication creates a column vector out of another column vector. When the vector is post-multiplied by the matrix, the result is a vector that is the sum of the ROW vectors of the matrix, still weighted by the components of the vector. In this case, a row vector is transformed into another row vector. Disregarding the row- / column- difference, the two results are equal only if the rows and columns of the matrix are identical (symmetric matrix). Mark Harder
|
Pages: 1 Prev: Dot product confusion Next: Some collected information about Dynamic |