Matlab:Refined population model: Difference between revisions

From Puella Magi Wiki
Jump to navigation Jump to search
(Created page with "<pre> % % REFINED MAGICAL GIRL-WITCH POPULATION MODEL % This file has been produced for FreeMat 4.0 % The syntax of the plot commands may differ from Matlab. % % If you want to m...")
 
mNo edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 2: Line 2:
%
%
% REFINED MAGICAL GIRL-WITCH POPULATION MODEL
% REFINED MAGICAL GIRL-WITCH POPULATION MODEL
% This file has been produced for FreeMat 4.0
% BASIC MAGICAL GIRL-WITCHES MODEL
% The syntax of the plot commands may differ from Matlab.
% 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, N, K and P should be values in [0,1]
% -D, B, F, 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)
* -W(1) should be strictly positive. If W(1)=0, no witch appear ever, and MSes grow linearily
% -W(1) should be strictly positive. If W(1)=0, no witch appear ever, and MSes grow linearily
%
%




C = 100; % Number of girls contracted by QBe
C = 100;     % Number of girls contracted by QBe
D = 0.25; % Proportion of girls (who are fighting) that die
D = 0.200;   % Proportion of girls (who are fighting) that die
B = 0.125; % Proportion of girls (who are fighting) to become witches
B = 0.100;   % Proportion of girls (who are fighting) to become witches
N = 0.015; % Proportion of familiars becoming witches
F = 0.015;   % Proportion of familiars becoming witches
K = 0.12; % Proportion of witches getting killed by MSes
K = 0.096;   % Proportion of witches getting killed by MSes
P = 0.8; % proportion of MSes fighting


M(1) = 0;
steps = 500; % Number of iterations for the simulation
W(1) = 1;
 
M(1) = 0;   % Number of magical girls at first
W(1) = 1;   % Number of witches at first


hold on
hold on


for t=1:500
for t=1:steps
     prop = P*min(M(t), W(t));
     prop = min(M(t), W(t));
          
          
     deltaM = C- prop*(D+B);
     deltaM = C- prop*(D+B);
     deltaW = N*W(t) + prop*(B-K);
     deltaW = F*W(t) + prop*(B-K);
      
      
     M(t+1)=M(t)+deltaM;
     M(t+1)=M(t)+deltaM;
Line 38: Line 42:
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', 'northeast')
legend('Magical Girls', 'Witches', 'location', 'northeast')
legend('boxoff')
legend('boxoff')
Line 46: Line 50:


</pre>
</pre>
[[Category:Science]]

Latest revision as of 08:59, 21 May 2011

%
% REFINED MAGICAL GIRL-WITCH POPULATION MODEL
% 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, K should be values in [0,1]
% -B should be greater than K (or else, the number of witches will be negative)
% -W(1) should be strictly positive. If W(1)=0, no witch appear ever, and MSes grow linearily
%


C = 100;     % Number of girls contracted by QBe
D = 0.200;    % Proportion of girls (who are fighting) that die
B = 0.100;   % Proportion of girls (who are fighting) to become witches
F = 0.015;   % Proportion of familiars becoming witches
K = 0.096;    % Proportion of witches getting killed by MSes

steps = 500; % Number of iterations for the simulation

M(1) = 0;    % Number of magical girls at first
W(1) = 1;    % Number of witches at first

hold on

for t=1:steps
    prop = min(M(t), W(t));
        
    deltaM = C- prop*(D+B);
    deltaW = F*W(t) + prop*(B-K);
    
    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', 'northeast')
legend('boxoff')

hold off