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: factor analysis: rotated axes angle - comp.soft-sys.matlab ...> > Using the dot product of the axis coords and an inverse cosine, I would think. > ** I don't get this I'm afraid. Do the 'axis coords' correspond to Lambda0 in the ... IML: matrix product with missing elements. - comp.soft-sys.sas ...... in the expressions, why not to use it in matrix product. ... consistent using matrix operation using standard SAS rule ... library operator* on Vector does dot products. On ... angle between two vectors - comp.soft-sys.matlabFactor 2') --- I'd like to know: 1) how to calculate the angle between the oblique axes? 2) is ... The dot product of two vectors is equal to the lengths times the cos of ... How multiply two __int64 ... - comp.lang.c... 32-bit unsigned product, with no overflow possible One use of the latter ... assume an "eventual use governs evaluation" rule int i ... -- Eric Sosman esosman@ieee-dot-org ... Suggestions for Inverse Euler Rotation - comp.soft-sys.matlab ...... matrix / angles satisfy that the elements of rotation matrix (1,1) = cos(psi)cos ... (You could get that with a simple cross product to get the rotation axis and a dot product ... how to draw an arc between two points given centre and radius ...... and then the points of the arc are [radius * cos ... P1-P0; v2 = P2-P0; c = det([v1,v2]); % "cross product" of v1 and v2 a = linspace(0,atan2(abs(c),dot(v1 ... Re: fast angle calculation between 2D vectors - comp.soft-sys ...While the scalar product is easily envisioned ... v2 will be the same as if calculated using V1 and V2 angle(v1,v2)=acosd( dot ... way to calculate ..... float)Math.Cos ... Migration Specialties Prepares Avanti Beta - comp.os.vms ...... OpenVMS and TRU64 operating systems and layered products. .... ... FreeAXP.pdf How does HP and the VMS license rules ... VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)ORG ... how to get lease DHCP expiration time? - comp.unix.solaris ...Statements on Sun products included here are not gospel and may be fiction rather than ... Daniel Rawson wrote: > Casper H.S. Dik wrote: >> Daniel Rawson <daniel_dot_rawson ... Dynamic PDF-Generation via Server / Web-to-print - how? - comp ...... complex templates, such as a business card or a product ... further, please e-mail me at larry"at"jbmsystems"dot ... Well, as a rule of thumb, "intelligent" templates ... Law of cosines - Wikipedia, the free encyclopediaIn trigonometry, the law of cosines (also known as the cosine formula or cosine rule) relates ... in the theory of vectors, which expresses the dot product of two vectors in ... Dot product - Wikipedia, the free encyclopediaIf both and have length one (i.e., they are unit vectors), their dot product simply gives the cosine of the angle between them. If only is a unit vector, then the dot ... 7/13/2012 3:43:56 PM
|