matlab运输问题:设有两个工厂A1,A2,产量都是10万个,工厂有三个仓库T1,T2,T3?
- 转运问题设有两个工厂A、B,产量分别为9,8个单位
- MATLAB编程解决运输问题
- matlab 题 求答案 在线等
- (转运问题)设有两个工厂A、B,产量分别为9,8个单位;四个顾客分别为1,2,3,4,需求量分别为3,5,4,5
转运问题设有两个工厂A、B,产量分别为9,8个单位
lingo程序大概如下 用程序解的话不会有详细的资料 也不需要图表 只要会写就行了
model:
sets:
factory/1..2/:produce;
warehouse/1..3/:trans;
custom/1..4/:demand;
link1(warehouse,factory):cost1,t1;
link2(warehouse,custom):cost2,t2;
endsets
data:
produce=9 8;
demand=3 5 4 5;
cost1=
1 3
2 1
100 2;
cost2=
5 7 100 100
9 6 7 100
100 6 7 4;
enddata
min=@sum(link1:t1*cost1)+@sum(link2:t2*cost2);
@for(warehouse(j):@sum(custom(k):t2(j,k))=@sum(factory(i):t1(j,i)));
@for(factory(i):@sum(warehouse(j):t1(j,i))<=produce(i));
@for(custom(k):@sum(warehouse(j):t2(j,k))=demand(k));
end
@for(warehouse(j):
MATLAB编程解决运输问题
该运输模型,可用Matlab的linprog()函数来求解。求得
x11=150.0000
x12=0.0000
x13=50.0000
x21=0.0000
x22=150.0000
x23=150.0000
总费用为
2.6500e+003
代码见附件
matlab 题 求答案 在线等
全部通过测试,可以运行、
问题1
%Q1
%主函数
num = input('please input a number: ')
if func_is_prime(num)
disp('The input number is a prime number.');
else
disp('The input number is NOT a prime number.');
end
%子函数
function result = func_is_prime(x)
temp = 2:x-1;
temp = x./temp;
result = (temp ~= round(temp));
问题2
%Q2
zero_num = 0;
for x = 1:2007;
zero_num = func_cal_zero_num(x) + zero_num;
end
disp(zero_num);
%子函数,统计数字中0的个数
function result = func_cal_zero_num(x)
result = 0;
if x>=0 & x<10 & x==0
result = 1;
elseif x>=10 & x<=99 & mod(x,10)==0;
result = 1;
elseif x>=100 & x<=999 & mod(x,100)==0
result = 1;
elseif x>=100 & x<=999 & mod(x-mod(x,10),100)==0;
result = 1;
elseif x>=1000 & mod(x,1000)==0;
result = 1;
elseif x>=1000 & mod(x-mod(x,10),100)==0 ~mod(x-mod(x,100),1000)==0;
result = 1;
elseif x>=1000 & mod(x-mod(x,100),1000)==0 ~ mod(x-mod(x,10),100)==0;
result = 1;
end
问题3
%Q3
x = -3:0.01:3;
y=zeros(size(x));
for i = 1:length(x)
if -3<= x(i)& x(i)<=-1
y(i)=(-x(i).^2-4*x(i)-3)/2;
elseif -1<= x(i) & x(i)<=1
y(i)=-x(i).^2+1;
elseif 1<=x(:,i)<=3
y(i)=(-x(i).^2+4*x(i)-3)/2;
end
end
plot(x,y);
问题4
%Q4
k = menu('please choose a number', '1', '4');
switch k
case 1
a = -10; b = 10;
result = a + (b-a) * rand(1);
case 4
a = 0; b = 1;
result = a + sqrt(b) * randn(1);
end
disp(result);
问题5
%Q5
x = 25;
result = 0;
if x <= 10
result = x*0.1;
elseif x>10 & x<=20
result = 10*0.1+(x-10)*0.05;
elseif x>20 & x<=40
result = 10*0.1+10*0.05+(x-20)*0.02;
else
result = 10*0.1+10*0.05+20*0.02+(x-40)*0.01;
end
disp(result);
问题6
%Q6
num = 3;
a = 1; b = 2;
result = 0;
for i = 1:num
result = result + b/a;
temp = a;
a = b;
b = temp + b;
end
disp(result);
问题7,也是约瑟夫环问题
%Q7
n = 20;
m = 7;
arr_size = n;
s = 1;
a = 1:n;
result = zeros(1,n);
s1 = s-1;
for t = n:-1:1
s1 = rem((s1 +m-1),t);
w = a(s1+1);
fprintf('The %d-th person is out\n',w);% 显示第几号人出列
result(n-t+1) = w;% 将出列的人放入result数组
for t=s1+1:1:arr_size-1%移动数组元素
a(t)=a(t+1);
end
arr_size = arr_size-1;
end
disp(result);
(转运问题)设有两个工厂A、B,产量分别为9,8个单位;四个顾客分别为1,2,3,4,需求量分别为3,5,4,5
充满了无形的火焰,紧闭,圣洁,
岁月没来得及进入轨道
树木层叠,
当多雨的许阿得斯们 用急流
为么它们仍然在世界上并且
穿透骨子里——