%l1_s分别是不同实验条件下的数据,下面的函数为极大既然函数的负值,先用fmincon求解,运行出错了。
function [l1_s,l2_s,l3_s,l4_s,l5_s,l6_s] = readandevaluate(filename)
global l1_s l2_s l3_s l4_s l5_s l6_s;
filename = 'li_s.xlsx';
l1_s = xlsread(filename,'A:A');
l2_s = xlsread(filename,'B:B');
l3_s = xlsread(filename,'C:C');
l4_s = xlsread(filename,'D
');
l5_s = xlsread(filename,'E:E');
l6_s = xlsread(filename,'F:F');
end
function f = fmin4mle(x)
global l1_s l2_s l3_s l4_s l5_s l6_s;
f = -(x(5)*l1_s.^(x(5)-1)*exp(-x(5)*(x(1)+x(2)/80+x(3)/20+x(4)*log(20)))*exp(-l1_s.^x(5)*exp(-x(5)*(x(1)+x(2)/80+x(3)/80+x(4)*log(20)))))...
*(x(5)*l2_s.^(x(5)-1)*exp(-x(5)*(x(1)+x(2)/80+x(3)/60+x(4)*log(20)))*exp(-l2_s.^x(5)*exp(-x(5)*(x(1)+x(2)/80+x(3)/80+x(4)*log(60)))))...
*(x(5)*l3_s.^(x(5)-1)*exp(-x(5)*(x(1)+x(2)/80+x(3)/40+x(4)*log(20)))*exp(-l3_s.^x(5)*exp(-x(5)*(x(1)+x(2)/55+x(3)/80+x(4)*log(40)))))...
*(x(5)*l4_s.^(x(5)-1)*exp(-x(5)*(x(1)+x(2)/95+x(3)/20+x(4)*log(20)))*exp(-l4_s.^x(5)*exp(-x(5)*(x(1)+x(2)/55+x(3)/95+x(4)*log(20)))))...
*(x(5)*l5_s.^(x(5)-1)*exp(-x(5)*(x(1)+x(2)/95+x(3)/60+x(4)*log(20)))*exp(-l5_s.^x(5)*exp(-x(5)*(x(1)+x(2)/70+x(3)/95+x(4)*log(60)))))...
*(x(5)*l6_s.^(x(5)-1)*exp(-x(5)*(x(1)+x(2)/95+x(3)/40+x(4)*log(20)))*exp(-l6_s.^x(5)*exp(-x(5)*(x(1)+x(2)/70+x(3)/95+x(4)*log(40)))));
end
A = [0 0 0 0 -1];
b = [0];
x0 = [10,10,10,10,10];
[x,fval] = fmincon(@readandevaluate,x0,A,b)
提示错误如下:
错误使用 fmincon (line 637)
User supplied objective function must return a scalar value.