Efficient way of calculating quadratic forms: avoid for loops?
问题 I want to calculate N (N is big) quadratic forms. I am using the command 'quad.form' from the R package 'emulator'. How can I implement this without using a for loop? So far, I am using library(emulator) A = matrix(1,ncol=5,nrow=5) # A matrix x = matrix(1:25,ncol=5,nrow=5) # The vectors of interest in the QF # for loop QF = vector() for(i in 1:5){ QF[i] = quad.form(A,x[,i]) } Is there a more direct and efficient way to calculate these quadratic forms? Something intriguing is that quad.form(A