要求解一个非线性优化问题,建立了目标函数和限制条件两个m文件,下面是代码:

function f=fun1(x)
a=xlsread('数据化.xls','B1:B139');
b=xlsread('数据化.xls','C1:C139');
c=xlsread('数据化.xls','F1:F139');
d=xlsread('数据化.xls','E1:E139');
e=xlsread('数据化.xls','D1:D139');
prob=optimproblem('ObjectiveSense','min');
x=optimvar('x',8,138,'Type','integer','LowerBound',0,'UpperBound',1);
w1=1000000;
w2=10000;
w3=100;
w4=1;
x_mean=sum(x,2)./8;
a_mean=sum(a,1)./8;
b_mean=sum(b,1)./8;
c_mean=sum(c,1)./8;
f1=sum((sum(x,2)-x_mean).^2);
f2=sum((sum(x*a)-a_mean).^2);
f3=sum((sum(x*b)-b_mean).^2);
f4=sum((sum(x*c)-c_mean).^2);
f5=sum(sum(x(:,1:26)-1,2))+sum(sum(x(:,27:49)-1,2))+sum(sum(x(:,50:59)-1,2))+sum(sum(x(:,60:93)-1,2))+sum(sum(x(:,94:100)-1,2))+sum(sum(x(:,101:102)-1,2))+(sum(x(103:111)-1))+sum(sum(x(:,112:121)-1,2))+sum(sum(x(:,122:130)-1,2))+sum(sum(x(:,131:135)-1,2))+sum(sum(x(:,136:138)-1,2));
f=w1.*f1+w2.*f3+w3.*(0.5.*f2+0.5.*f4)+w4.*f5;
end

fun2.m
function [g,h]=fun2(x);
x=optimvar('x',8,138,'Type','integer','LowerBound',0,'UpperBound',1);
d=xlsread('数据化.xls','E1:E139');%队长候选
        g=[sum(x)'-1];
        for i=1:8
        h=[-sum(x*d)+2;x(i,28).*x(i,27);x(i,54).*x(i,55).*x(i,56);x(i,65).*x(i,66);x(i,85).*x(i,86)];
        end
end

主程序:
[x,fval]=fmincon('fun1',0,[],[],[],[],0,1,'fun2')

报错:
[x,fval]=fmincon('fun1',0,[],[],[],[],0,1,'fun2')
错误使用 fmincon (第 726 行)
FMINCON requires all values returned by functions to be of data type double.