Matlab:Basic population model: Difference between revisions

From Puella Magi Wiki
Jump to navigation Jump to search
(Created page with "<pre> % % BASIC MAGICAL GIRL-WITCHES MODEL % This file has been produced for FreeMat 4.0 % The syntax of the plot commands may differ from Matlab. % % If you want to modify the c...")
 
No edit summary
Line 41: Line 41:
hold off
hold off
</pre>
</pre>
[[Category:Science]]

Revision as of 20:05, 18 March 2011

%
% BASIC MAGICAL GIRL-WITCHES MODEL
% This file has been produced for FreeMat 4.0
% The syntax of the plot commands may differ from Matlab.
%
% If you want to modify the constants, please bear these restrictions in mind:
% -C should be an integer
% -D, B, N 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
N = 0.015;  % Proportion of familiars maturing into witches, per iteration
K = 0.12;   % Proportion of witches getting killed

M(1) = 0;
W(1) = 0;

hold on

for t=1:100
    deltaM = C-(D+B)*M(t);
    deltaW = N*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