Simple economic model (MATLAB)

From LiteratePrograms

Jump to: navigation, search

This program is under development.
Please help to debug it. When debugging
is complete, remove the {{develop}} tag.

Let's try to implement a simple economic model.

Contents


Component of an economic model

In any economic model, we will have resources and agents. The resources are all goods, natural resources and anything that can be used by the agents. The agents will buy resources and use them to build other resources (money is one of the resources, of course).

Resources

At first we will model a very simple economy with as resources:

  • oil (energy)
  • kangaroo (animals)
  • cooked kangaroo (food)
  • people
  • money

We will store our resources in a zdata structure. The value of an unit of each resource must be stored too.

The point is that resources do not have an eternal duration. So we need to specify the life cycle of each resource, to do this, we need:

  • the variables having an impact on the resource lifecycle (inputs of the lifecycle)
  • the name of the resources changed by the resources lifecycle (outputs of the lifecycle)
  • a function associating inputs to outputs.

For instance, the lifecycle of the people can be expressed like this:

  • inputs of their lifecycle are:
    • number of other people
    • money that people possess
    • food available to people
  • outputs are:
    • a new number of people (according to death and birth)
    • a new number of food units
  • and the function is like <<people_lifecycle.m>>:

Lifecycle

Enlarge
the tanh
The life cycle of a people can be parametrized by a large number of ways. Here we choose to use the tanh function.

So we take the number of birth by people (with F is food, and M money, the division by 2 take into account that only female can have children):

The thresholds and as well as the slopes cF and cM has to be carefully chosen. Consequently I choose the death rate to obtain an equilibrium:

ρdeath = ρ(F * ,M * )

> function)">> function)" width="180" height="136" longdesc="/Image:Matlab_lifecycle_01.png"/>
Enlarge
some trajectories of the lifecycle (the example of the <<test_cycle.m>> function)
Here is the version with only one input (for instance food):
<<test_cycle.m>>=
function pop = test_cycle(pop, f, varargin)
% TEST_CYCLE - simple life cycle test
% use:
%  pop = test_cycle(pop, food, options)
% options:
% - 'threshold',  9
% - 'slope'    ,  8
% - 'm-star'   , 10
% - 'rho'      ,  []
% exemple:
%  pops = [];
%  for f=8.6:.1:10.2
%    pop=100; food=f;
%    for i=1:100, pop = [pop; test_cycle(pop(end), food)]; end
%    pops = [pops, pop];
%  end
%  figure; plot(pops, 'linewidth',2)
opt = options({'threshold',9,'slope',8, 'm-star', 10, 'rho', []}, varargin);
rho = opt.get('rho');
if isempty(rho)
    rho = tanh((opt.get('m-star') - opt.get('threshold'))/opt.get('slope'))/2;
end
if isfinite(pop)
    real_rho = mean(rand(ceil(pop),1)<rho);
else
    real_rho = 0;
end
pop = pop * abs(1+tanh((f - opt.get('threshold'))/opt.get('slope'))/2-real_rho);

That way we can define our resources at an object initialized by the list of the resources names, their initial numbers and values, and their lifecycle functions:

<<init_resources.m>>=
function data = init_resources( names, varargin)
% INIT_RESOURCE - 
% example:
% my_resources = init_resources({'oil','kangaroo','people','money'});
opt = options({'quantities', [], 'value', []},varargin);
q   = opt.get('quantities');
if isempty(q)
end
data = struct('quantities', struct('title','resources','date',1,'value',zeros(1,length(res_names)),'names',{names}), ...
              'value'     , struct('title','resources','date',1,'value',zeros(1,length(res_names)),'names',{names}));

Agents

Economy

Download code
Views