Matlab:Basic population model: Difference between revisions
Jump to navigation
Jump to search
Homerun-chan (talk | contribs) No edit summary |
Homerun-chan (talk | contribs) mNo edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
% | % | ||
% BASIC MAGICAL GIRL-WITCHES MODEL | % BASIC MAGICAL GIRL-WITCHES MODEL | ||
% This file has been produced for | % This file has been produced for Matlab 7.4.0 | ||
% | % It is 100% compatible with FreeMat 4.0, however, you may want to change the plot commands to | ||
% plot(M, 'g.-') and plot(W, 'r.-') for aesthetics purpose | |||
% | % | ||
% If you want to modify the constants, please bear these restrictions in mind: | % If you want to modify the constants, please bear these restrictions in mind: | ||
% -C should be an integer | % -C should be an integer | ||
% -D, B, | % -D, B, F and K should be values in [0,1] | ||
% -B should be greater than K (or else, the number of witches will be negative) | % -B should be greater than K (or else, the number of witches will be negative) | ||
% | % | ||
C = 100; | C = 100; % Amount of Magical Girls contracted by Kyubey, per iteration | ||
D = 0.25; | D = 0.25; % Proportion of girls getting killed, per iteration | ||
B = 0.125; | B = 0.125; % Proportion of girls becoming witches, per iteration | ||
F = 0.015; % Proportion of familiars maturing into witches, per iteration | |||
K = 0.12; | K = 0.12; % Proportion of witches getting killed | ||
M(1) = 0; | steps = 100; % Number of iterations for the simulation | ||
W(1) = 0; | |||
M(1) = 0; % Number of magical girls at first | |||
W(1) = 0; % Number of witches at first | |||
hold on | hold on | ||
for t=1: | for t=1:steps | ||
deltaM = C-(D+B)*M(t); | deltaM = C-(D+B)*M(t); | ||
deltaW = | deltaW = F*W(t) + (B-K)*M(t); | ||
M(t+1)=M(t)+deltaM; | M(t+1)=M(t)+deltaM; | ||
Line 34: | Line 37: | ||
xlabel('time') | xlabel('time') | ||
ylabel('number of magical girls/witches') | ylabel('number of magical girls/witches') | ||
plot(M, 'g | plot(M, 'g-') | ||
plot(W, 'r | plot(W, 'r-') | ||
legend('Magical Girls', 'Witches', 'location', 'southeast') | legend('Magical Girls', 'Witches', 'location', 'southeast') | ||
legend('boxoff') | legend('boxoff') |
Latest revision as of 08:56, 21 May 2011
% % BASIC MAGICAL GIRL-WITCHES MODEL % This file has been produced for Matlab 7.4.0 % It is 100% compatible with FreeMat 4.0, however, you may want to change the plot commands to % plot(M, 'g.-') and plot(W, 'r.-') for aesthetics purpose % % If you want to modify the constants, please bear these restrictions in mind: % -C should be an integer % -D, B, F and K should be values in [0,1] % -B should be greater than K (or else, the number of witches will be negative) % C = 100; % Amount of Magical Girls contracted by Kyubey, per iteration D = 0.25; % Proportion of girls getting killed, per iteration B = 0.125; % Proportion of girls becoming witches, per iteration F = 0.015; % Proportion of familiars maturing into witches, per iteration K = 0.12; % Proportion of witches getting killed steps = 100; % Number of iterations for the simulation M(1) = 0; % Number of magical girls at first W(1) = 0; % Number of witches at first hold on for t=1:steps deltaM = C-(D+B)*M(t); deltaW = F*W(t) + (B-K)*M(t); M(t+1)=M(t)+deltaM; W(t+1)=W(t)+deltaW; end title('Evolution of the Magical Girls population over time') xlabel('time') ylabel('number of magical girls/witches') plot(M, 'g-') plot(W, 'r-') legend('Magical Girls', 'Witches', 'location', 'southeast') legend('boxoff') hold off