dot product using cosine rules ... how?

  • Follow


Guys calculating dot product with matlab is fairly easy 

a=[1 2 3];
b=[3 2 1];
dot(a,b)
10

however could you please show me more explicitly how I can come to this number (10) while using cosines etc.  Thank you....
0
Reply Sofia 3/24/2011 8:41:04 AM

On 3/24/2011 1:41 AM, Sofia Häggberg wrote:
> Guys calculating dot product with matlab is fairly easy
>
> a=[1 2 3];
> b=[3 2 1];
> dot(a,b)
> 10
>
> however could you please show me more explicitly how I can
>  come to this number (10) while using cosines etc.  Thank you....

Well, from definition,  A.B = |A| |B| cos(angle between vectors)

So, use norm() to find the magnitude of the vectors, and find
the angle between the vectors, then you got the dot product?


EDU>> a=[1  2 3];
b=[3 2 1];
angle = atan2(norm(cross(a,b)),dot(a,b));  %from post by Roger Stanford
norm(a)*norm(b)*cos(angle)

ans =
     10

But the above is kind'a silly, since one is using dot product
to find the angle to use to find the dot product. But this is what
you asked for.

--Nasser



0
Reply Nasser 3/24/2011 8:56:43 AM


"Nasser M. Abbasi" <nma@12000.org> wrote in message <imf10h$e8u$1@speranza.aioe.org>...
> On 3/24/2011 1:41 AM, Sofia Häggberg wrote:
> > Guys calculating dot product with matlab is fairly easy
> >
> > a=[1 2 3];
> > b=[3 2 1];
> > dot(a,b)
> > 10
> >
> > however could you please show me more explicitly how I can
> >  come to this number (10) while using cosines etc.  Thank you....
> 
> Well, from definition,  A.B = |A| |B| cos(angle between vectors)
> 
> So, use norm() to find the magnitude of the vectors, and find
> the angle between the vectors, then you got the dot product?
> 
> 
> EDU>> a=[1  2 3];
> b=[3 2 1];
> angle = atan2(norm(cross(a,b)),dot(a,b));  %from post by Roger Stanford
> norm(a)*norm(b)*cos(angle)
> 
> ans =
>      10
> 
> But the above is kind'a silly, since one is using dot product
> to find the angle to use to find the dot product. But this is what
> you asked for.
> 
> --Nasser
> 
> 

Indeed I asked about this! 

Bat Nasser, could you please explain an other thing related exactly about the same things...

How to come in the number 10 while using some fft tricks ... e.g.,
to move the above vectors into frequency domain and later to calculate the difference of their phase angles ... and in the end to take the cosine? ... any idea ... how this is done?

Thank YOU!
0
Reply Sofia 3/24/2011 9:09:19 AM

On 3/24/2011 2:09 AM, Sofia Häggberg wrote:

>>
>
> Indeed I asked about this!
>
> Bat Nasser, could you please explain an other thing related exactly about the same things...
>
> How to come in the number 10 while using some fft tricks ... e.g.,
> to move the above vectors into frequency domain and later to calculate the difference
>  of their phase angles ... and in the end to take the cosine? ... any idea ... how this is done?
>
> Thank YOU!

I do not understand you question at all.

What do you mean by "move the above vectors into frequency domain"

?

What does angle between vectors and phase angle of a signal have
to do with each others.

I am getting a headach now :)

I think I'll go make coffee now.

--Nasser
0
Reply Nasser 3/24/2011 9:16:07 AM

"Nasser M. Abbasi" <nma@12000.org> wrote in message <imf24t$h0t$1@speranza.aioe.org>...
> On 3/24/2011 2:09 AM, Sofia Häggberg wrote:
> 
> >>
> >
> > Indeed I asked about this!
> >
> > Bat Nasser, could you please explain an other thing related exactly about the same things...
> >
> > How to come in the number 10 while using some fft tricks ... e.g.,
> > to move the above vectors into frequency domain and later to calculate the difference
> >  of their phase angles ... and in the end to take the cosine? ... any idea ... how this is done?
> >
> > Thank YOU!
> 
> I do not understand you question at all.
> 
> What do you mean by "move the above vectors into frequency domain"
> 
> ?
> 
> What does angle between vectors and phase angle of a signal have
> to do with each others.
> 
> I am getting a headach now :)
> 
> I think I'll go make coffee now.
> 
> --Nasser

Hi Nasser, I think this time I will be clear and hopefully you will also be to find the solution (and explain) me ;)

Please have a look to this formula:

http://tinyurl.com/5uzpwex

theta_j(x) - is phase angle of j-th component of fft of x (in our case a)
theta_j(y) - is phase angle of j-th component of fft of y (in our case b)

I think implementing this formula in this form ... needs to give you a result (same as above) - 10

Could you show me ... how this will work on Matlab???
0
Reply Sofia 3/24/2011 11:07:02 AM

On 3/24/2011 2:09 AM, Sofia Häggberg wrote:
> "Nasser M. Abbasi"<nma@12000.org>  wrote in message<imf10h$e8u$1@speranza.aioe.org>...
>> On 3/24/2011 1:41 AM, Sofia Häggberg wrote:
>>> Guys calculating dot product with matlab is fairly easy
>>>
>>> a=[1 2 3];
>>> b=[3 2 1];
>>> dot(a,b)
>>> 10
>>>
>>> however could you please show me more explicitly how I can
>>>   come to this number (10) while using cosines etc.  Thank you....
>>
>> Well, from definition,  A.B = |A| |B| cos(angle between vectors)
>>
>> So, use norm() to find the magnitude of the vectors, and find
>> the angle between the vectors, then you got the dot product?
>>
>>
>> EDU>>  a=[1  2 3];
>> b=[3 2 1];
>> angle = atan2(norm(cross(a,b)),dot(a,b));  %from post by Roger Stanford
>> norm(a)*norm(b)*cos(angle)
>>
>> ans =
>>       10
>>
>> But the above is kind'a silly, since one is using dot product
>> to find the angle to use to find the dot product. But this is what
>> you asked for.
>>
>> --Nasser
>>
>>
>

  
> Indeed I asked about this!
>
> Bat Nasser, could you please explain an other thing related exactly about the same things...
>
> How to come in the number 10 while using some fft tricks ... e.g.,
> to move the above vectors into frequency domain and later to calculate the difference
>  of their phase angles ... and in the end to take the cosine? ... any idea ... how this is done?
>
> Thank YOU!

If I understand your equation, then this below is your equation in Matlab:

a=[1 2 3];
b=[3 2 1];
N=length(a);

N * sum( cos( angle(fft(a)) - angle(fft(b)) ) )

ans =
    -0.3333

which is not 10

May be someone else can understand the equation better. Notice
your sequences are real, so phase is conjugate symmmetic, so sum of
phase for each sequence is zero since they cancel.

--Nasser
0
Reply Nasser 3/24/2011 11:32:08 AM

"Nasser M. Abbasi" <nma@12000.org> wrote in message <imfa3t$3n6$1@speranza.aioe.org>...
> On 3/24/2011 2:09 AM, Sofia Häggberg wrote:
> > "Nasser M. Abbasi"<nma@12000.org>  wrote in message<imf10h$e8u$1@speranza.aioe.org>...
> >> On 3/24/2011 1:41 AM, Sofia Häggberg wrote:
> >>> Guys calculating dot product with matlab is fairly easy
> >>>
> >>> a=[1 2 3];
> >>> b=[3 2 1];
> >>> dot(a,b)
> >>> 10
> >>>
> >>> however could you please show me more explicitly how I can
> >>>   come to this number (10) while using cosines etc.  Thank you....
> >>
> >> Well, from definition,  A.B = |A| |B| cos(angle between vectors)
> >>
> >> So, use norm() to find the magnitude of the vectors, and find
> >> the angle between the vectors, then you got the dot product?
> >>
> >>
> >> EDU>>  a=[1  2 3];
> >> b=[3 2 1];
> >> angle = atan2(norm(cross(a,b)),dot(a,b));  %from post by Roger Stanford
> >> norm(a)*norm(b)*cos(angle)
> >>
> >> ans =
> >>       10
> >>
> >> But the above is kind'a silly, since one is using dot product
> >> to find the angle to use to find the dot product. But this is what
> >> you asked for.
> >>
> >> --Nasser
> >>
> >>
> >
> 
>   
> > Indeed I asked about this!
> >
> > Bat Nasser, could you please explain an other thing related exactly about the same things...
> >
> > How to come in the number 10 while using some fft tricks ... e.g.,
> > to move the above vectors into frequency domain and later to calculate the difference
> >  of their phase angles ... and in the end to take the cosine? ... any idea ... how this is done?
> >
> > Thank YOU!
> 
> If I understand your equation, then this below is your equation in Matlab:
> 
> a=[1 2 3];
> b=[3 2 1];
> N=length(a);
> 
> N * sum( cos( angle(fft(a)) - angle(fft(b)) ) )
> 
> ans =
>     -0.3333
> 
> which is not 10
> 
> May be someone else can understand the equation better. Notice
> your sequences are real, so phase is conjugate symmmetic, so sum of
> phase for each sequence is zero since they cancel.
> 
> --Nasser

Nasser, let's hope someone will come with the answer!!! I need it...
0
Reply Sofia 3/24/2011 1:02:06 PM

"Sofia Häggberg" wrote in message <imf8km$1ej$1@fred.mathworks.com>...
> "Nasser M. Abbasi" <nma@12000.org> wrote in message <imf24t$h0t$1@speranza.aioe.org>...
> > On 3/24/2011 2:09 AM, Sofia Häggberg wrote:
> > 
> > >>
> > >
> > > Indeed I asked about this!
> > >
> > > Bat Nasser, could you please explain an other thing related exactly about the same things...
> > >
> > > How to come in the number 10 while using some fft tricks ... e.g.,
> > > to move the above vectors into frequency domain and later to calculate the difference
> > >  of their phase angles ... and in the end to take the cosine? ... any idea ... how this is done?
> > >
> > > Thank YOU!
> > 
> > I do not understand you question at all.
> > 
> > What do you mean by "move the above vectors into frequency domain"
> > 
> > ?
> > 
> > What does angle between vectors and phase angle of a signal have
> > to do with each others.
> > 
> > I am getting a headach now :)
> > 
> > I think I'll go make coffee now.
> > 
> > --Nasser
> 
> Hi Nasser, I think this time I will be clear and hopefully you will also be to find the solution (and explain) me ;)
> 
> Please have a look to this formula:
> 
> http://tinyurl.com/5uzpwex
> 
> theta_j(x) - is phase angle of j-th component of fft of x (in our case a)
> theta_j(y) - is phase angle of j-th component of fft of y (in our case b)
> 
> I think implementing this formula in this form ... needs to give you a result (same as above) - 10
================

Sofia, it looks like your formula is missing some quantities. It is true that Fourier space and non-Fourier space are isometrix, meaning that

dot(x,y)=dot(X,Y)/N

where X=fft(x), Y=fft(Y), N=length(x).


The formulat for dot(X,Y) would be

dot(X,Y) = sum_j Rx(j)*Ry(j)*exp(j*(theta_j(x) - theta_j(y)))

but since dot(X,Y) is also supposed to be real, you can just take the real part leading to

dot(x,y) = sum_j Rx(j)*Ry(j)*cos( theta_j(x) -  theta_j(y) )/N

which is your formula once you include the Rx(j) and Ry(j) factors.





 
0
Reply Matt 3/24/2011 2:24:04 PM

"Matt J" wrote in message <imfk64$o86$1@fred.mathworks.com>...
>
> but since dot(X,Y) is also supposed to be real, you can just take the real part leading to
> 
> dot(x,y) = sum_j Rx(j)*Ry(j)*cos( theta_j(x) -  theta_j(y) )/N
> 
> which is your formula once you include the Rx(j) and Ry(j) factors.
=============

Sorry. Forgot to mention that Rx=abs(X) and similary for Ry. And here's the test:

x=[1 2 3];
y=[3 2 1];
N=length(x);

X=fft(x);
Y=fft(y);

thetaX=angle(X);
thetaY=angle(Y);

Rx=abs(X);
Ry=abs(Y);

sum(Rx.*Ry.*cos(thetaX-thetaY))/N  %=10
0
Reply Matt 3/24/2011 2:39:05 PM

8 Replies
228 Views

(page loaded in 0.068 seconds)

Similiar Articles:













7/13/2012 3:43:56 PM


Reply: