准备用matlab做一个求最优解的问题;准备用fmincon 函数。在写function的时候遇到问题,请帮忙指点。源代码如下;
A = [1,1,1;-1,-1,-1;1,0,0;0,1,0;0,0,1;-1,0,0;0,-1,0;0,0,-1];
b = [1,1,1,1,1,1,1,1];
x0 = [1/3,1/3,1/3];
function func = objfun (w)
r = 100;
coeff = importdata('C:\return.csv');
func =(1/11) * (r-1)^(-1)*(...
(1+w(1)*coeff(1,1)+w(2)*coeff(1,2)+w(3)*coeff(1,3))^(1-r)+...
(1+w(1)*coeff(2,1)+w(2)*coeff(2,2)+w(3)*coeff(2,3))^(1-r) +...
(1+w(1)*coeff(3,1)+w(2)*coeff(3,2)+w(3)*coeff(3,3))^(1-r)+...
(1+w(1)*coeff(4,1)+w(2)*coeff(4,2)+w(3)*coeff(4,3))^(1-r)+...
(1+w(1)*coeff(5,1)+w(2)*coeff(5,2)+w(3)*coeff(5,3))^(1-r)+...
(1+w(1)*coeff(6,1)+w(2)*coeff(6,2)+w(3)*coeff(6,3))^(1-r)+...
(1+w(1)*coeff(7,1)+w(2)*coeff(7,2)+w(3)*coeff(7,3))^(1-r)+...
.....................................................
);
x = fmincon( @objfun,x0,A,b);
在function代码中, (1+w(1)*coeff(1,1)+w(2)*coeff(1,2)+w(3)*coeff(1,3))^(1-r) 这个要做10000次循环,一直到
(1+w(1)*coeff(10000,1)+w(2)*coeff(10000,2)+w(3)*coeff(10000,3))^(1-r).
但是如何使用循环来做?手写全部方程是不可能的了。
感谢高人指点,现在非常着急!!!!!