Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
162 views
1
function [k, X, Y] = vnbrody(F, signoX, signoXF)
2
%vnbrody
3
% [k, X, Y] = vnbrody(F)
4
%
5
% Formatea el problema y lanza un c�digo de Br�dy para resolver VN.
6
%
7
% [k, X, Y] = vnbrody(F, signoX, signoXF)
8
% F recetas en tiempo discreto
9
% signoX signo de las intensidades; por defecto X >= 0
10
% signoXF signo de los balances materiales; por defecto X F(k) = 0
11
% k, X, Y factor, intensidades y valores soluci�n
12
%
13
% Los c�digos para los signos son 0 = 1 >= 2 <= 3 >=<
14
% El algoritmo puede consultarse en:
15
% Andr�s Br�dy, "The implicit dynamics of the Neumann growth model",
16
% Acta Oeconomica, Vol. 54 (1) pp. 63-72 (2004)
17
% http://www.akademiai.com/content/x71485711558/
18
19
%necesita formaproblema.m, formaab.m, formasolucion.m
20
21
if nargin < 2, signoX = []; end
22
if nargin < 3, signoXF = []; end
23
24
[Fn, signoX, signoXF] = formaproblema(F, signoX, signoXF, 1); %convierte el problema a la forma can�nica
25
[A, B] = formaab(Fn, 1); %convierte a la forma A, B
26
[k, p, x] = neumann(A', B'); %lanza el c�digo original de Brody
27
X = x(1:size(Fn, 1)); %extrae las intensidades de los procesos que se inician
28
Y = p(1:size(Fn, 2))'; %extrae los precios de las materias habituales
29
[X, Y] = formasolucion(X, Y, signoX, signoXF, 1); %convierte la soluci�n desde la forma can�nica
30
31
32
33
34
35
function [rho,p,x] = neumann(in,out)
36
% the function [rho,p,x] = neumann(in,out) computes a solution
37
% rho,p,x (growth factor, prices and quantities),
38
% for rectangular matrices in and out(input and output).
39
40
% Preliminaries:
41
% initial vectors, scaling, flag for indicating selection,
42
% initial rate, and select = 1 for going on with the process
43
44
[m,n] = size(out);
45
p = ones(1,m)/m;
46
x = ones(1,n)/n;
47
48
scale = m;
49
b = in/scale;
50
a = out/scale;
51
52
flag = [0 0 0 0 0];
53
54
rho = (p*a*x')/(p*b*x');
55
select = 1;
56
57
while select
58
c = (a-rho*b);
59
for i = 1:100
60
dx = p*c; %surplus gain
61
dp = x*c'; %excess product
62
p = p-dp;
63
x = x+dx;
64
65
p = p.*(p>0); %selecting valuable goods
66
p = p/sum(p); %normalizing
67
x = x.*(x>0); %selecting applied processes
68
x = x/sum(x); %normalizing
69
70
R(i,:) = p;
71
Y(i,:) = x;
72
end
73
p = median(R); %taking median price
74
x = median(Y); %taking median quantity
75
p = p.*(p>0);
76
p = p/sum(p);
77
x = x.*(x>0);
78
x = x/sum(x);
79
rho = (p*a*x')/(p*b*x');
80
81
%adjusting flag
82
flag(1:4) = flag(2:5);
83
flag(5) = sum(p>0) == sum(x>0); %indicating squareness
84
85
%testing if the matrix was square for the last 5 iterations
86
if sum(flag) == 5
87
select = 0;
88
end
89
end
90
91
%Selection finished. Finding equilbrium
92
93
pindex = find(p>0); %indexes of selected goods
94
xindex = find(x>0); %indexes of selected processes
95
96
A = a(pindex,xindex); %square matrix of outputs
97
B = b(pindex,xindex); %square matrix of inputs
98
99
%Inverting an almost singular matrix to improve exactness
100
for k = 1:3
101
s = inv(A-rho*B);
102
P = sum(s)/sum(s(:));
103
X = sum(s')/sum(s(:));
104
rho = P*A*X'/(P*B*X');
105
end
106
107
%Final values and exactness
108
109
p = zeros(1,m);
110
p(pindex) = P;
111
x = zeros(1,n);
112
x(xindex) = X;
113
114
sistem = rho*in-out;
115
error = num2str(p*sistem*x');
116
disp(['Exactness',error])
117
118