目标函数:
max f(x)=0.70*(0.2*x(1)+0.5*x(2)+0.7*x(3))+0.80*(0.3*x(1)+0.3*x(2)+0.3*x(3))+0.90*(0.5*x(1)+0.2*x(2)+0.0*x(3))-0.40*x(1)-0.20*x(2)-0.10*x(3)
约束条件:
s.t. 0.2*x(1)+0.5*x(2)+0.7*x(3)<=9000
0.3*x(1)+0.3*x(2)+0.3*x(3)<=8000
0.5*x(1)+0.2*x(2)+0.0*x(3)<=7000
x(1)<=10 000
x(2)<=12 000
x(3)<=15 000
x(i)>=0 i=1,2,3
MATLAB程序:
f=-[0.70*0.2+0.80*0.3+0.90*0.5-0.40
0.70*0.5+0.80*0.3+0.90*0.2-0.20
0.70*0.7+0.80*0.3+0.90*0.0-0.10];
A=[0.2 0.5 0.7
0.3 0.3 0.3
0.5 0.2 0.0];
B=1000*[9;8;7];
ub=1000*[10;12;15];
[x,fval,exitflag,output]=linprog(f,A,B,[],[],zeros(3,1),ub);
运行结果:
Optimization terminated.
x =
1.0e+004 *
0.9200
1.2000
0.1657
fval =
-1.1840e+004
exitflag =
1
output =
iterations: 7
algorithm: 'large-scale: interior point'
cgiterations: 0
message: 'Optimization terminated.'
>> x=vpa(x,5),fval=vpa(fval,5)
x =
9200.
12000.
1657.1
fval =
-11840.
最大利润:max f(x)=11840$
用 matlab optimazation toolbox
看帮助文档,有线性优化的问题
用while循环:a=zeros(1000,1);
a(1)=1;a(2)=1;
i=1;
while
a(i)<=10000
a(i+2)=a(i+1)+a(i);
i=i+1;
end
disp(['第一个大于10000的元素为:',num2str(a(i))])用for循环:a=zeros(1000,1);
a(1)=1;a(2)=1;
i=1;
for
i=1:1000
a(i+2)=a(i+1)+a(i);
if
a(i+2)>10000,break,end
end
disp(['第一个大于10000的元素为:',num2str(a(i+2))])运行结果:第一个大于10000的元素为:10946