[R] R programming question, one dimensional optimization

From: <phwang2000_at_ucla.edu>
Date: Thu 25 Jan 2007 - 06:28:45 GMT


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 

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. Received on Thu Jan 25 18:42:44 2007

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 Thu 25 Jan 2007 - 08:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.