%Itt a dinamika: Population(i+1)=Beta*Population(i)*exp(-Alpha*Population(i));
%Ez ugyanaz, mint az elozoben, csak a parameterek mashogy szerepelnek:
%Konnyebb oket kezelni (matematikailag).
%A cel hogy megnezzuk, hogyan fugg a kovetkezo populacio a mostani allomanytol.

%Parameterek:
%Iteraciok szama: 300

%Alpha: 0.01
%Beta: 5
%Kezdeti ertek: 10
%Egyenlet:
%Population(1)=10
%Population(i+1)=Beta*i*exp(-Alpha*i); 

Beta=5;
Alpha=0.01;
NumberOfIterations=48;
InitialValue=10;

StockFrom=1;
StockTill=300;
Iterations=StockTill-StockFrom;

Samples=zeros(Iterations,1);
Samples2=zeros(Iterations,1);
Line=1:(Iterations);

Samples(1)=InitialValue;
Samples2(1)=InitialValue;

for i=1:(Iterations-1)
    Samples(i+1)=Beta*i*exp(-Alpha*i);
end

%Kirajzolja a vonalat es a fuggvenyt
subplot(1,2,1);
hold on;
plot(Line,Samples,Line,Line);


%Megcsinalja az iteraciot
Population=zeros(NumberOfIterations,1);
Population(1)=InitialValue;

for i=1:(NumberOfIterations-1)
    Population(i+1)=Beta*Population(i)*exp(-Alpha*Population(i));
end

% Pokhalo diagram
for i=1:(NumberOfIterations-1)
    plot([Population(i),Population(i)],[Population(i),Population(i+1)],'red');
    hold on
    plot([Population(i),Population(i+1)],[Population(i+1),Population(i+1)],'red');
    hold on
end

subplot(1,2,2);
plot(Population)

%{
% A legelejen levo parametereket csereljuk le az alabbiakkal, s nezzuk meg,
% hol milyen viselkedest tapasztalunk.

% 1) Gyors konvergenica
Beta=5;
Alpha=0.01;
NumberOfIterations=60;
InitialValue=10;

% 2) Stabil hosszutavu populacio lassan konvergal.
Beta=7.95;
Alpha=0.0186;
NumberOfIterations=12;
InitialValue=190;

% 3) Szeles tartomanyokon belul valtozo ertekek, dupla iteracio hosszusagu periodus.
Beta=13.95;
Alpha=0.018636;
NumberOfIterations=48;
InitialValue=10;
%}
