www.gusucode.com > 钻井问题的较完善解答 以及图论,线性规划,lingo lindo matlab使用教程 > 数学建模优化资料/myfun.m
function [max,x,y,m,n]=myfun(a,b) s=0; max=0; n=length(a); for m=0:0.01:1 for n=0:0.01:1 for i=1:n a=a+m; b=b+n; na=round(a(i)); nb=round(b(i)); A=abs(a(i)-na); B=abs(b(i)-nb); C=abs(a(i)-na-1); D=abs(b(i)-nb-1); L1=max(A,B); L2=max(A,D); L3=max(C,B); L4=max(C,D); if min(L1,L2,L3,L4)<=0.05 s=s+1;a(i)=x;b(i)=y; if s>=max max=s; end end end end end