Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
0.4x + 100 if x is <= 5000;
0.3x + 5000 if 5000 <= x <= 10000;
0.2x + 10000 if x > 10000;
x -> quantity of fish to catch
b-> quantity of fish availavable in the beginning of year i
c(x,b) -> cost of catching x fish with b fishes available
f_i(b) = max {(5x - c(x,b)) + 0.8 * f_i+1((b - x) * 1.2)}
clear; % make sure previously defined variables are erased.
global FishBeginningYear Years FishSold MaxProfit MatrixProfit
FishBeginningYear = 10; % In thousands (x1000)
Years = 10;
FishSold = 0;
MatrixProfit = zeros(10,52);
% Border Conditions
if FishBeginningYear <= 5
MatrixProfit(10, FishBeginningYear) = 5 * FishSold - (0.4 * FishSold + 1);
elseif (FishBeginningYear > 5) && (FishBeginningYear <= 10)
MatrixProfit(10, FishBeginningYear) = 5 * FishSold - (0.3 * FishSold + 5);
else
MatrixProfit(10, FishBeginningYear) = 5 * FishSold - (0.2 * FishSold + 10);
end
MaxProfit = pesca_rec(2, 10);
Function function y = pesca_rec(Year, FishBeginningYear)
global FishSold MaxProfit MatrixProfit Years
y = MatrixProfit(Year, FishBeginningYear);
if y ~= 0 %Memoization
return
end %if
auxMax=-1000;
kchosen=0;
for k = 1 : Years
% Costs
if FishSold <= 5
Cost = 0.4 * FishSold + 100;
elseif (FishSold > 5) && (FishSold <= 10)
Cost = 0.3 * FishSold + 5000;
else
Cost = 0.2 * FishSold + 10000;
end
MaxProfit = 5 * FishSold - Cost + 0.8 * pesca_rec(k + 1, FishBeginningYear - FishSold); % * 1.2
if auxMax < MaxProfit
auxMax=MaxProfit ;
kchosen=k;
end %if MaxProfit
end; %
MatrixProfit(k,FishSold) = kchosen;
y=auxMax;
end %function
clear;
global M Kdep Cost RecursiveProfit ValorF prop
Kdep=[10; 20; 30; 40; 50; 60; 70; 80; 90; 100]; %max nr of fish in the lake at the beginning of each year, 10 years, in thousands. Growth factor = 20%
M=1000;
%Cost and Profit of selling i fishes given that there are j at the beginning of the year
for i = 1:50
for j = 1:11
Cost(i,j) = 0.2 * i + 10;
RecursiveProfit(i,j) = 5 * i - Cost(i, j);
end
end
for i = 1:10
for j = 1:10
Cost(i,j) = 0.3 * i + 5;
RecursiveProfit(i,j) = 5 * i - Cost(i, j);
end
end
for i = 1:5
for j = 1:5
Cost(i,j) = 0.4 * i + 0.1;
RecursiveProfit(i,j) = 5 * i - Cost(i, j);
end
end
%prop = 1 : 10;
ValorF = -M * ones(10, 50);
%Border conditions
for a = 1:5
ValorF(10, a) = 5 * a - (0.4 * a + 1); %On Year 10, if there are <= a thousand fishes in the lake ...
prop(10, a) = a;
end
for b = 6:10
ValorF(10, b) = 5 * b - (0.3 * b + 5); %On Year 10, if there are 6 <= a <= 10 thousand fishes in the lake ...
prop(10, b) = b;
end
for c = 10:41
ValorF(10, c) = 5 * c - (0.2 * c + 10);
prop(10, c) = c;
end
MaxProfit = RecursiveProfitRecursivo(1, 10)
k1 = prop(1,10)
kant=k1;
y = 6 - Cost(kant,10);
for q=2:10
if(kant == 0)
kant = kant + 1;
end
kq=prop(q,y)
kant=kq;
y = y - Cost(kant,q);
end %for i
function y=RecursiveProfit(j,x)
global M Kdep Cost Prof ValorF prop
y=ValorF(j,x);
if y~= -M
return
end %if
auxMax=-M;
decision=0;
for k=1:Kdep(j)
if Prof(k,j) <= x-k
aux=Prof(k,j)+RecursiveProfit(j+1, (x - k));
if auxMax < aux
auxMax=aux;
decision=k;
end %if aux
else break
end %if Cost
end %for k
ValorF(j,x)=auxMax;
prop(j,x)=decision;
y=auxMax;
decide the number of fish to catch each yearinstead of "decide the equal number of fish to catch per year each and every year". But, perhaps I made a bad interpretation of the objective. Which is it?
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
expectj telnet failing | 5 | 35 | |
use lov values | 2 | 49 | |
iterator/ListIterator approach | 17 | 25 | |
How to pass pointer to int when expected type is pointer to const char * ? | 6 | 22 |
Join the community of 500,000 technology professionals and ask your questions.