用matlab怎样解方程组的整数解
答案:1 悬赏:60 手机版
解决时间 2021-03-23 08:32
- 提问者网友:谁的错
- 2021-03-22 11:24
用matlab怎样解方程组的整数解
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-03-22 12:15
程序:
clear;
clc;
%a+b+c+d+e=10
%290a+470b+720c+1060d+1490e=6000
e0 = floor(6000/1490);
d0 = floor(6000/1060);
c0 = floor(6000/720);
index = 0;
cxd = zeros(10,5);
for cxde = 0:e0
for cxdd = 0:d0
for cxdc = 0:c0
for cxdb = 0:10
for cxda = 0:10
check1 = (290*cxda + 470*cxdb + 720*cxdc + 1060*cxdd + 1490*cxde == 6000);
check2 = (cxda + cxdb +cxdc +cxdd +cxde == 10);
if check1&check2;
index = index+1;
cxd(index,1) = cxda;
cxd(index,2) = cxdb;
cxd(index,3) = cxdc;
cxd(index,4) = cxdd;
cxd(index,5) = cxde;
end
end
end
end
end
end
disp(cxd(1:index,:))
结果:
3 1 5 1 0
4 2 1 3 0
4 1 4 0 1
5 2 0 2 1追问为何a+b+c+d+e前要加%?我怎么运行不了?追答加%是没有用的,被我注释掉了。怎么运行不了?报错了吗?发出来看看追问哦,谢谢了
clear;
clc;
%a+b+c+d+e=10
%290a+470b+720c+1060d+1490e=6000
e0 = floor(6000/1490);
d0 = floor(6000/1060);
c0 = floor(6000/720);
index = 0;
cxd = zeros(10,5);
for cxde = 0:e0
for cxdd = 0:d0
for cxdc = 0:c0
for cxdb = 0:10
for cxda = 0:10
check1 = (290*cxda + 470*cxdb + 720*cxdc + 1060*cxdd + 1490*cxde == 6000);
check2 = (cxda + cxdb +cxdc +cxdd +cxde == 10);
if check1&check2;
index = index+1;
cxd(index,1) = cxda;
cxd(index,2) = cxdb;
cxd(index,3) = cxdc;
cxd(index,4) = cxdd;
cxd(index,5) = cxde;
end
end
end
end
end
end
disp(cxd(1:index,:))
结果:
3 1 5 1 0
4 2 1 3 0
4 1 4 0 1
5 2 0 2 1追问为何a+b+c+d+e前要加%?我怎么运行不了?追答加%是没有用的,被我注释掉了。怎么运行不了?报错了吗?发出来看看追问哦,谢谢了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯