Email: [email protected]

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Windows
      • Office
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Windows
      • Office
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Value Function Iteration Code Not Converging

Value Function Iteration Code Not Converging

PuTI / 2025-02-02
Value Function Iteration Code Not Converging
Matlab News

Hello all, I am currently coding a value/policy function iteration code to solve an economic problem. The problem that this is solving for is that there is a certain amount of S and R currently owned (these are the state variables). S and R generate income, which must be allocated to purchase more S and R for the next "round" (S’ and R’, equivalently. S’ and R’ are the control variables). This code solves for the optimal amount of income that should be spent on R’ at any given level of S and R. Right now my code below only works at specific parameter values and does not converge–the error term gets stuck, and I cannot seem to figure out why. My code is below. Any help on what could possibly prevent it from converging would be greatly appreciated. Thank you all in advance!
clc;
clear;
% Model Parameters and initalize matrices
numRisky = 100;
numSafe = 100;
v = (1:numSafe)’ + (1:numRisky);
vnew=ones(numSafe, numRisky);
policy = zeros(numSafe, numRisky);
delta=0.99;
ctol=0.001;
ntol=200;
count=0;
norm=1;
vx = ones(numSafe);
vy = ones(numRisky);
alpha = 1;
while norm>ctol && count<ntol
for R=1:numRisky
riskyReturns = 1:1:3;
numReturns = numel(riskyReturns);
pReturns = (1/numReturns)*ones(1, numReturns);
u = zeros(1, numReturns);
p = zeros(1, numReturns);
for S = 1:numSafe
safeReturn = 2;
for r = 1:numReturns
safeIncome = S*safeReturn;
riskyIncome = R*riskyReturns(r);
posI = safeIncome + riskyIncome;
U = alpha*log(S+R);
W = zeros(1, posI);

for i = 1:posI
if S + (posI-i) > numSafe && R + i <= numRisky
vBar = v(numSafe,R+i) + vx(R+i)*(S+posI-i-numSafe); %conduct linear approximation
W(i) = (1-delta)*U + delta*vBar;
elseif R + i > numRisky && S + (posI-i) <= numSafe
vBar = v(S+posI-i,numRisky) + vy(S+posI-i)*(R+i-numRisky);
W(i) = (1-delta)*U + delta*vBar; %conduct linear approximation
elseif R + i > numRisky && S + (posI-i) > numSafe
vBar = v(numSafe,numRisky) + vx(numRisky)*(S+posI-i-numSafe) + vy(numSafe)*(R+i-numRisky);
W(i) = (1-delta)*U + delta*vBar; %conduct linear approximation
else
W(i) = (1-delta)*U + delta*v(S + (posI – i), R + i); %no linear approximation needed here
end
end
[w, ind] = max(W);
u(r) = w;
p(r) = ind/posI;
end
vnew(S, R) = dot(u, pReturns);
policy(S, R) = dot(p, pReturns);
end
end
%calculate slopes for linear approximation if S’ and R’ are greater than numSafe and numRisky, respectively
for n = 1:numSafe
vx(n) = v(numSafe,n)-v(numSafe-1,n);
end
for m = 1:numRisky
vy(m) = v(m,numRisky)-v(m,numRisky-1);
end
%calculate convergence criteria and update value function
count = count + 1;
norm = max(abs(log(vnew(:)) – log(v(:))));
v = vnew;
disp(‘Iteration:’)
disp(count)
disp(‘Error Term:’)
disp(norm)
endHello all, I am currently coding a value/policy function iteration code to solve an economic problem. The problem that this is solving for is that there is a certain amount of S and R currently owned (these are the state variables). S and R generate income, which must be allocated to purchase more S and R for the next "round" (S’ and R’, equivalently. S’ and R’ are the control variables). This code solves for the optimal amount of income that should be spent on R’ at any given level of S and R. Right now my code below only works at specific parameter values and does not converge–the error term gets stuck, and I cannot seem to figure out why. My code is below. Any help on what could possibly prevent it from converging would be greatly appreciated. Thank you all in advance!
clc;
clear;
% Model Parameters and initalize matrices
numRisky = 100;
numSafe = 100;
v = (1:numSafe)’ + (1:numRisky);
vnew=ones(numSafe, numRisky);
policy = zeros(numSafe, numRisky);
delta=0.99;
ctol=0.001;
ntol=200;
count=0;
norm=1;
vx = ones(numSafe);
vy = ones(numRisky);
alpha = 1;
while norm>ctol && count<ntol
for R=1:numRisky
riskyReturns = 1:1:3;
numReturns = numel(riskyReturns);
pReturns = (1/numReturns)*ones(1, numReturns);
u = zeros(1, numReturns);
p = zeros(1, numReturns);
for S = 1:numSafe
safeReturn = 2;
for r = 1:numReturns
safeIncome = S*safeReturn;
riskyIncome = R*riskyReturns(r);
posI = safeIncome + riskyIncome;
U = alpha*log(S+R);
W = zeros(1, posI);

for i = 1:posI
if S + (posI-i) > numSafe && R + i <= numRisky
vBar = v(numSafe,R+i) + vx(R+i)*(S+posI-i-numSafe); %conduct linear approximation
W(i) = (1-delta)*U + delta*vBar;
elseif R + i > numRisky && S + (posI-i) <= numSafe
vBar = v(S+posI-i,numRisky) + vy(S+posI-i)*(R+i-numRisky);
W(i) = (1-delta)*U + delta*vBar; %conduct linear approximation
elseif R + i > numRisky && S + (posI-i) > numSafe
vBar = v(numSafe,numRisky) + vx(numRisky)*(S+posI-i-numSafe) + vy(numSafe)*(R+i-numRisky);
W(i) = (1-delta)*U + delta*vBar; %conduct linear approximation
else
W(i) = (1-delta)*U + delta*v(S + (posI – i), R + i); %no linear approximation needed here
end
end
[w, ind] = max(W);
u(r) = w;
p(r) = ind/posI;
end
vnew(S, R) = dot(u, pReturns);
policy(S, R) = dot(p, pReturns);
end
end
%calculate slopes for linear approximation if S’ and R’ are greater than numSafe and numRisky, respectively
for n = 1:numSafe
vx(n) = v(numSafe,n)-v(numSafe-1,n);
end
for m = 1:numRisky
vy(m) = v(m,numRisky)-v(m,numRisky-1);
end
%calculate convergence criteria and update value function
count = count + 1;
norm = max(abs(log(vnew(:)) – log(v(:))));
v = vnew;
disp(‘Iteration:’)
disp(count)
disp(‘Error Term:’)
disp(norm)
end Hello all, I am currently coding a value/policy function iteration code to solve an economic problem. The problem that this is solving for is that there is a certain amount of S and R currently owned (these are the state variables). S and R generate income, which must be allocated to purchase more S and R for the next "round" (S’ and R’, equivalently. S’ and R’ are the control variables). This code solves for the optimal amount of income that should be spent on R’ at any given level of S and R. Right now my code below only works at specific parameter values and does not converge–the error term gets stuck, and I cannot seem to figure out why. My code is below. Any help on what could possibly prevent it from converging would be greatly appreciated. Thank you all in advance!
clc;
clear;
% Model Parameters and initalize matrices
numRisky = 100;
numSafe = 100;
v = (1:numSafe)’ + (1:numRisky);
vnew=ones(numSafe, numRisky);
policy = zeros(numSafe, numRisky);
delta=0.99;
ctol=0.001;
ntol=200;
count=0;
norm=1;
vx = ones(numSafe);
vy = ones(numRisky);
alpha = 1;
while norm>ctol && count<ntol
for R=1:numRisky
riskyReturns = 1:1:3;
numReturns = numel(riskyReturns);
pReturns = (1/numReturns)*ones(1, numReturns);
u = zeros(1, numReturns);
p = zeros(1, numReturns);
for S = 1:numSafe
safeReturn = 2;
for r = 1:numReturns
safeIncome = S*safeReturn;
riskyIncome = R*riskyReturns(r);
posI = safeIncome + riskyIncome;
U = alpha*log(S+R);
W = zeros(1, posI);

for i = 1:posI
if S + (posI-i) > numSafe && R + i <= numRisky
vBar = v(numSafe,R+i) + vx(R+i)*(S+posI-i-numSafe); %conduct linear approximation
W(i) = (1-delta)*U + delta*vBar;
elseif R + i > numRisky && S + (posI-i) <= numSafe
vBar = v(S+posI-i,numRisky) + vy(S+posI-i)*(R+i-numRisky);
W(i) = (1-delta)*U + delta*vBar; %conduct linear approximation
elseif R + i > numRisky && S + (posI-i) > numSafe
vBar = v(numSafe,numRisky) + vx(numRisky)*(S+posI-i-numSafe) + vy(numSafe)*(R+i-numRisky);
W(i) = (1-delta)*U + delta*vBar; %conduct linear approximation
else
W(i) = (1-delta)*U + delta*v(S + (posI – i), R + i); %no linear approximation needed here
end
end
[w, ind] = max(W);
u(r) = w;
p(r) = ind/posI;
end
vnew(S, R) = dot(u, pReturns);
policy(S, R) = dot(p, pReturns);
end
end
%calculate slopes for linear approximation if S’ and R’ are greater than numSafe and numRisky, respectively
for n = 1:numSafe
vx(n) = v(numSafe,n)-v(numSafe-1,n);
end
for m = 1:numRisky
vy(m) = v(m,numRisky)-v(m,numRisky-1);
end
%calculate convergence criteria and update value function
count = count + 1;
norm = max(abs(log(vnew(:)) – log(v(:))));
v = vnew;
disp(‘Iteration:’)
disp(count)
disp(‘Error Term:’)
disp(norm)
end value function iteration, bellman, dynamic program, matlab, bellman equation MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Generate ST code from a look-up table with CONSTANT attribute
2025-05-22

Generate ST code from a look-up table with CONSTANT attribute

“no healthy upstream” error when trying to access My Account
2025-05-22

“no healthy upstream” error when trying to access My Account

MATLAB Answers is provisionally back?
2025-05-21

MATLAB Answers is provisionally back?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: [email protected]
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss