用MATLAB作有约束条件的非线性优化

函数FMINCON 问题,是非线性约束函数,function [c,g]=mycon(x)
c(1)=0.9-(min(min(corrcoef((D.*x(1)+B.*x(2)+C.*x(3)),S))));
c(2)=((abs((D.*x(1)+B.*x(2)+C.*x(3)))-S)./S)-0.1;
g(1)=x(1)+x(2)+x(3)-1;

D=[0.074728
0.20964
0.012444
0.038306
0.08948
1
0.099868
0.39473
0.1428
0.038821];
计算报错
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:
Undefined function or variable "D".
那这个数组D,该怎么附值呢??急等求解决。。。。。。。。

把数组D=[ ]放在c(1)的前面追问

谢谢你啊,输入数组的问题,用for i=,解决了,但是我现在计算出来了结果不在我所设定的区间内啊,而且系统提示“
Optimization terminated: Magnitude of directional derivative in search
direction less than 2*options.TolFun and maximum constraint violation
is less than options.TolCon.
”是什么意思啊??难道fmincon函数不能解决我的问题?谢谢你啊,求教导

追答

能把问题发给我,看一看。[email protected]

温馨提示:答案为网友推荐,仅供参考