[R] Question about Calculation of Cross Product

R. Michael Weylandt michael.weylandt at gmail.com
Thu Nov 3 14:12:22 CET 2011


Try

library(pracma)
? cross

Michael Weylandt

On Thu, Nov 3, 2011 at 1:17 AM, 阮铮 <rz1991 at foxmail.com> wrote:
> The function of crossprod in R puzzled me.
> I would like to calculate the cross product of two vectors. According to my text book, it defines like this:
> a = (ax, ay, az)
> b = (bx, by, bz)
> then, the cross product of a and b is:
> a X b = (ay*bz-az*by, az*bx-ax*bz, ax*by-ay*bz)
> It can also write in a determinant format.
>
>
> But the crossprod or tcrossprod function in R appeared not calculate the cross product. Suppose I enter this:
>> a = c(1, 2, 3)
>> b = c(2, 3, 4)
>> ab = crossprod(a, b)
>> ab
>     [,1]
> [1,]   20
>> ab = tcrossprod(a, b)
>> ab
>     [,1] [,2] [,3]
> [1,]    2    3    4
> [2,]    4    6    8
> [3,]    6    9   12
>
>
> Does any know how to calculate cross product in R. Or I have to write the function myself?
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list