Download code

Jump to: navigation, search

Back to Simple_economic_model_(MATLAB)

Download for Windows: zip

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

init_resources.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Simple_economic_model_(MATLAB)?oldid=19333
14 
15 function data = init_resources( names, varargin)
16 % INIT_RESOURCE - 
17 % example:
18 % my_resources = init_resources({'oil','kangaroo','people','money'});
19 opt = options({'quantities', [], 'value', []},varargin);
20 q   = opt.get('quantities');
21 if isempty(q)
22 
23 end
24 data = struct('quantities', struct('title','resources','date',1,'value',zeros(1,length(res_names)),'names',{names}), ...
25               'value'     , struct('title','resources','date',1,'value',zeros(1,length(res_names)),'names',{names}));


hijacker
hijacker
hijacker
hijacker

test_cycle.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Simple_economic_model_(MATLAB)?oldid=19333
14 
15 function pop = test_cycle(pop, f, varargin)
16 % TEST_CYCLE - simple life cycle test
17 % use:
18 %  pop = test_cycle(pop, food, options)
19 % options:
20 % - 'threshold',  9
21 % - 'slope'    ,  8
22 % - 'm-star'   , 10
23 % - 'rho'      ,  []
24 % exemple:
25 %  pops = [];
26 %  for f=8.6:.1:10.2
27 %    pop=100; food=f;
28 %    for i=1:100, pop = [pop; test_cycle(pop(end), food)]; end
29 %    pops = [pops, pop];
30 %  end
31 %  figure; plot(pops, 'linewidth',2)
32 
33 opt = options({'threshold',9,'slope',8, 'm-star', 10, 'rho', []}, varargin);
34 rho = opt.get('rho');
35 if isempty(rho)
36     rho = tanh((opt.get('m-star') - opt.get('threshold'))/opt.get('slope'))/2;
37 end
38 if isfinite(pop)
39     real_rho = mean(rand(ceil(pop),1)<rho);
40 else
41     real_rho = 0;
42 end
43 pop = pop * abs(1+tanh((f - opt.get('threshold'))/opt.get('slope'))/2-real_rho);
44 


hijacker
hijacker
hijacker
hijacker