[R] R programming question, one dimensional optimization
phwang2000 at ucla.edu
phwang2000 at ucla.edu
Thu Jan 25 07:28:45 CET 2007
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)
+ }
More information about the R-help
mailing list