check the following:
A <- matrix(rnorm(100*100), 100, 100); A <- A + t(A) B <- matrix(rnorm(100*100), 100, 100); B <- B + t(B)
sum(diag(A %*% B))
sum(A * B)
system.time(for(i in 1:10000) out <- sum(diag(A %*% B))) system.time(for(i in 1:10000) out <- sum(A * B))
I hope it helps.
Best,
Dimitris
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899 Fax: +32/(0)16/337015Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm
Dear all,
I need to calculate tr(A B), tr(A B A B) and similar quantities
**fast** where the matrices A, B are symmetrical. I've searched for
built-in functions for that purpose, but without luck. Can anyone
help?
Thanks in advance
Søren
[[alternative HTML version deleted]]
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.
Archive generated by hypermail 2.1.8, at Tue 15 Aug 2006 - 00:27:22 EST.
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.