Download code

From LiteratePrograms

Jump to: navigation, search

Back to Simple_economic_model_(MATLAB)

Download for Windows: zip

Download for UNIX: zip, tar.gz, tar.bz2

test_cycle.m

 1 % Copyright (c) 2008 the authors listed at the following URL, and/or
 2 % the authors of referenced articles or incorporated external code:
 3 % http://en.literateprograms.org/Simple_economic_model_(MATLAB)?action=history&offset=20060826025301
 4 % 
 5 % Permission is hereby granted, free of charge, to any person obtaining
 6 % a copy of this software and associated documentation files (the
 7 % "Software"), to deal in the Software without restriction, including
 8 % without limitation the rights to use, copy, modify, merge, publish,
 9 % distribute, sublicense, and/or sell copies of the Software, and to
10 % permit persons to whom the Software is furnished to do so, subject to
11 % the following conditions:
12 % 
13 % The above copyright notice and this permission notice shall be
14 % included in all copies or substantial portions of the Software.
15 % 
16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 % 
24 % Retrieved from: http://en.literateprograms.org/Simple_economic_model_(MATLAB)?oldid=7487
25 
26 function pop = test_cycle(pop, f, varargin)
27 % TEST_CYCLE - simple life cycle test

28 % use:

29 %  pop = test_cycle(pop, food, options)

30 % options:

31 % - 'threshold',  9

32 % - 'slope'    ,  8

33 % - 'm-star'   , 10

34 % - 'rho'      ,  []

35 % exemple:

36 %  pops = [];

37 %  for f=8.6:.1:10.2

38 %    pop=100; food=f;

39 %    for i=1:100, pop = [pop; test_cycle(pop(end), food)]; end

40 %    pops = [pops, pop];

41 %  end

42 %  figure; plot(pops, 'linewidth',2)

43 
44 opt = options({'threshold',9,'slope',8, 'm-star', 10, 'rho', []}, varargin);
45 rho = opt.get('rho');
46 if isempty(rho)
47     rho = tanh((opt.get('m-star') - opt.get('threshold'))/opt.get('slope'))/2;
48 end
49 if isfinite(pop)
50     real_rho = mean(rand(ceil(pop),1)<rho);
51 else
52     real_rho = 0;
53 end
54 pop = pop * abs(1+tanh((f - opt.get('threshold'))/opt.get('slope'))/2-real_rho);
55 


init_resources.m

 1 % Copyright (c) 2008 the authors listed at the following URL, and/or
 2 % the authors of referenced articles or incorporated external code:
 3 % http://en.literateprograms.org/Simple_economic_model_(MATLAB)?action=history&offset=20060826025301
 4 % 
 5 % Permission is hereby granted, free of charge, to any person obtaining
 6 % a copy of this software and associated documentation files (the
 7 % "Software"), to deal in the Software without restriction, including
 8 % without limitation the rights to use, copy, modify, merge, publish,
 9 % distribute, sublicense, and/or sell copies of the Software, and to
10 % permit persons to whom the Software is furnished to do so, subject to
11 % the following conditions:
12 % 
13 % The above copyright notice and this permission notice shall be
14 % included in all copies or substantial portions of the Software.
15 % 
16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 % 
24 % Retrieved from: http://en.literateprograms.org/Simple_economic_model_(MATLAB)?oldid=7487
25 
26 function data = init_resources( names, varargin)
27 % INIT_RESOURCE - 

28 % example:

29 % my_resources = init_resources({'oil','kangaroo','people','money'});

30 opt = options({'quantities', [], 'value', []},varargin);
31 q   = opt.get('quantities');
32 if isempty(q)
33 
34 end
35 data = struct('quantities', struct('title','resources','date',1,'value',zeros(1,length(res_names)),'names',{names}), ...
36               'value'     , struct('title','resources','date',1,'value',zeros(1,length(res_names)),'names',{names}));
37 


Views
Personal tools