用matlab怎样解方程组的整数解a+b+c+d+e=10290a+470b+720c+1060d+1490e=6000
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/31 13:04:55
用matlab怎样解方程组的整数解a+b+c+d+e=10290a+470b+720c+1060d+1490e=6000
用matlab怎样解方程组的整数解
a+b+c+d+e=10
290a+470b+720c+1060d+1490e=6000
用matlab怎样解方程组的整数解a+b+c+d+e=10290a+470b+720c+1060d+1490e=6000
程序:
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