Hi, I have an optimization for x'Ax/x'Bx, x is a vector, A/B are matrix,
I wrote a small program which can take in 2 matrices and a vector and a variable, this program combine the variable and the vector and generate a new vector, then test the x'Ax/x'Bx. However I dodnot know if there is a way that can calculate the x automatically instead of I typing different values to get the result and compare. =================================================== getMultiVal3 = function (a, b, cc, x) { + i-1; j=1; sum=0; sum2=0 + n=nrow(a); v= c(x, cc) + for (i in 1:n) { + for (j in 1:n) { + sum=sum+a[i,j]*v[i]*v[j]; sum2=sum2+b[i,j]*v[i]*v[j] + } + } + return(sum/sum2) + } ______________________________________________ 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.