电子科大实验报告之四:罐装饮料瓶(Matlab的解法)
题目:
设易拉罐的侧面的厚度1单位,
s=2*PI*r*h+4*PI*r^2
h高度,r为半径,体积V=PI*h*r^2.
V一定时,求使s最小的r和h.
Matlab的解法:
解法1:
v=350;
s=0;h=0;r=0;
for j=1:6
r_=(v/(j*pi))^(1/3)
h_=j*r_
s_=2*pi*r_*h_+4*pi*r_*r_
if(s>s_ | s==0)
s=s_;
h=h_;
r=r_;
end
end
s
r
h
r/h
解法2:
v=350;
s=[];h=[];r=[];
for j=1:6
r(j)=(v/(j*pi))^(1/3)
h(j)=j*r(j)
s(j)=2*pi*r(j)*h(j)+4*pi*r(j)^2
end
[minCost,j]=min(s)
r(j)
h(j)
r(j)/h(j)
解法3:
cost=inline('(2*pi*x+4*pi)*(350/(pi*x))^(2/3)');
s=fminbnd(cost,0.001,25)
feval(cost,s)
fplot(cost,[0.1 50]);grid on;