Вы находитесь на странице: 1из 2

Имеется сумма средств E=100 для инвестиций в три проекта порциями по 20 единиц.

Потенциальная прибыль от вложений в каждый проект представлена в таблице 1.


Таблица 1
X1 F1(x1) F2(x1) F3(x1)
20 5 4 6
40 8 10 9
60 12 15 14
80 17 18 18
100 20 21 17

Код (2-1-3)

a = [0 0 0 0; 20 5 4 6; 40 8 10 9; 60 12 15 14; 80 17 18 18; 100 20 21 17]


x = zeros(6,6)
y = zeros(20,8)
for i=1:6
for j=1:i
if a(j,3)>x(i,6) then
x(i,6) = a(j,3);
x(i,5) = a(j,1);
end;
end;
end

temp = 1;

for i=1:5
for j = 1:(i+1)
y(temp,1) = a(j,1);
y(temp,2) = a(i+1,1)-y(temp,1);
temp = temp + 1;
end;
end

temp = 1;
for i=1:20
if y(i,1) == 0 then
temp = temp + 1;
end;
for j=1:6
if x(j,5) == y(i,1) then
y(i,3) = x(j,6)
end;
if a(j,1) == y(i,2) then
y(i,4) = a(j,2)
end;
if a(j,1) == y(i,1) then
y(i,6) = a(j,4)
end;
end;
y(i,5) = y(i,3) + y(i,4)
if y(i,5) > x(temp,4) then
x(temp,4) = y(i,5);
x(temp,3) = y(i,1);
end;
end

temp = 1;
for i=1:20
if y(i,1) == 0 then
temp = temp + 1;
end;
for j=1:6
if a(j,1) == y(i,2) then
y(i,7) = x(j,4)
end;
end;
y(i,8) = y(i,6)+y(i,7)
if y(i,8) > x(temp,2) then
x(temp,2) = y(i,8);
x(temp,1) = y(i,1);
end;
end

temp = 100 - x(6,1);


temp_id = 1
disp("В проект 2")
disp(x(6,1))
for i=1:5
if (x(i,4) > x(temp_id,4)) & (x(i,3) < temp) then
temp_id = i;
end;
end

temp = temp - x(temp_id,3);


disp("В проект 1")
disp(x(temp_id,3))

for i=1:6
if x(i,5) == temp then
temp_id = i
end;
end
temp = temp - x(temp_id,3);
disp("В проект 3")
disp(x(temp_id,5))

disp(x)
disp(y)

Результат работы программы:

Вам также может понравиться