solution at initial point

4 views (last 30 days)
mrrox
mrrox on 9 Feb 2015
Edited: mrrox on 9 Feb 2015
Hello Everyone,
I have, as usual, a lengthy code again. Hope someone will help this time round.
The code runs well, no problem at all, but the solution I am getting is at initial point only. I expect the solution to vary over time/at each run of loop instead. I used 'fsolve' and 'fmincon' to get some sort of variation in solution at every iteration. No desired result so far.
I am trying to get a solution that changes value. Perhaps, the way I put together the FUNCTION or the code, in general, is not right? Please take a look at the code running it, it is part of the code.The unknowns are n(1) and n(2), everything else is either parameters or starting values in 'global'.
Thank you
close all
clear all
clc
global sigma c eta nu a a1 a2 n A tau Thetac Thetaw
T=300;
sigma=3;
a=0.40;
a1=0.15;
a2=0.25;
tau=[1,1];
gc=1;
gw=1;
lc=1;
lw=14;
nu=0.05;
eta=0.0001;
%Initial values
Ac0=50;
Aw0=100;
Sc0=200;
Sw0=100;
Rc0=0;
Rw0=0;
cc0=50;
cw0=125;
Ec=zeros(T,1);Ew=zeros(T,1);
Ac=zeros(T+1,1); Aw=zeros(T+1,1);
Ac(1,1)=Ac0;Aw(1,1)=Aw0;
Pc=zeros(T,1); Pw=zeros(T,1);
cc=zeros(T+1,1); cw=zeros(T+1,1); cc(1,1)=cc0; cw(1,1)=cw0
Rc=zeros(T+1,1);Rw=zeros(T+1,1);
Rc(1,1)=Rc0; Rw(1,1)=Rw0;
Sc=zeros(T+1,1); Sw=zeros(T+1,1);
Sc(1,1)=Sc0; Sw(1,1)=Sw0;
Lw=zeros(T,1);Lc=zeros(T,1);
Year=zeros(T,1);
for t=1:T
c=[cc(t),cw(t)];
A=[Ac(t),Aw(t)];
% options=optimset('TolFun',1e-11,'TolX',1e-11,'MaxFunEvals',16e10,'MaxIter',10e10);
% [x,fval,exitflag]=fmincon(@productivity_vL12,[Rc(t),Rw(t)],[],[],[],[],[0,0],[],[],options);
options=optimset('Algorithm','trust-region-dogleg','TolX',1e-15,'TolFun',1e-15,'MaxFunEvals',1e10,'maxiter',10e10);
[x,fval, exitflag]=fsolve(@productivity_vL12,[Rc(t),Rw(t)],options);
Rc(t+1)=x(1);
Rw(t+1)=x(2);
Ac(t+1)=(1+tau(1)*nu*Rc(t+1)^eta)*Ac(t);
Aw(t+1)=(1+tau(2)*nu*Rw(t+1)^eta)*Aw(t);
FUNCTION
function F=productivity_vL12(n)
global sigma c A eta nu a a1 a2 tau
Ac1=(1+tau(1)*nu*n(1)^eta)*A(1);
Aw1=(1+tau(2)*nu*n(2)^eta)*A(2);
P1=((Aw1/Ac1)^(1-a1)*(c(1)/c(2)^a2))/(1+((Aw1/Ac1)^(1-a1)*(c(1)/c(2))^a2)^(1-sigma))^(1/(1-sigma));
P2=(1-P1^(1-sigma))^(1/(1-sigma));
E1=((a2/c(1))*P1^(1/(1-a1))*P1^((1-sigma)*(1-a)/(1-a1))*Ac1)^((1-a1)/(1-a1-a2));
E2=((a2/c(2))*P2^(1/(1-a1))*P2^((1-sigma)*(1-a)/(1-a1))*Aw1)^((1-a1)/(1-a1-a2));
% n(1)=(nu*eta*a1*(1-a1)*(P1*(E1^a2)*P1^((1-sigma)*(1-a)))^(1/(1-a1)))^(1/(1-eta));
% n(2)=(nu*eta*a1*(1-a1)*(P2*(E2^a2)*P2^((1-sigma)*(1-a)))^(1/(1-a1)))^(1/(1-eta));
L1=((n(1)^(1-eta)/(a1*nu*eta*(1-a1)))^(1-a1)*(1/(P1*E1^a2)))^(1/(1-a));
L2=((n(2)^(1-eta)/(a1*nu*eta*(1-a1)))^(1-a1)*(1/(P2*E2^a2)))^(1/(1-a));
% F=n(1)+n(2)-1;
% F=L2+L1-1;
% F=[x(1)-(1+tau(1))*A(1)*(nu*eta*a1*(1-a1)*(P1*(E1^a2)*L1^(1-a))^(1/(1-a1)))^(1/(1-eta));
% x(2)-(1+tau(2))*A(2)*(nu*eta*a1*(1-a1)*(P2*(E2^a2)*L2^(1-a))^(1/(1-a1)))^(1/(1-eta))];
F=[n(1)-(nu*eta*a1*(1-a1)*(P1*(E1^a2)*L1^(1-a))^(1/(1-a1)))^(1/(1-eta));
n(2)-(nu*eta*a1*(1-a1)*(P2*(E2^a2)*L2^(1-a))^(1/(1-a1)))^(1/(1-eta))];

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!