[R] vectors cross-product V1 x V2
Eik Vettorazzi
E.Vettorazzi at uke.uni-hamburg.de
Fri Jul 8 14:52:12 CEST 2011
Hi,
how about this:
mm<-cbind(V1,V2)
xy<-sapply(1:3,function(x)det(mm[-x,])*(2*(x%%2)-1))
#some checks
all.equal(0,as.vector(xy%*%V1))
all.equal(0,as.vector(xy%*%V2))
Am 08.07.2011 08:27, schrieb Bai:
> Hi, everyone,
>
> I need an efficient way to do vectors cross product in R.
>
> Set vectors,
> V1 = ai + bj + ck
> V2 = di + ej + fk
>
> then the cross product is
> V1 x V2 = (bf - ce) i + (cd - af) j + (ae - bd) k
>
>
> As shown here ( http://en.wikipedia.org/wiki/Cross_product ).
>
> Thanks.
>
> Best,
> Bai
>
> ______________________________________________
> 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.
--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
More information about the R-help
mailing list