% % mccall1.m is an example matlab program % to solve a simple maacall searcgmodel % % ----- save output to file ----- % clear all diary mccall1.mout diary off delete mccall1.mout diary mccall1.mout % ----- display date and time of computation ----- % %format short date time0 = clock; % ----- set control vars ----- % iters = 200; states = 101; % ------ set parameters ------ % beta = 0.99; c = 10*ones(states,1); P = 1/states*ones(states,states); % ----- find limiting distribution ----- % [v,d]=eig(P') ; % - find the row of the unit eigenvalue - % [d1,d2]=find(fix(diag(d)+eps)) % - normalize eigenvector - % mu = abs(v(:,d1))./sum(abs(v(:,d1))) ; % ----- discretize wage ----- % w = zeros(states,1); for j = 1:(states-1); w(j+1,1) = w(j,1) + 1; end; % ----- value function iteration ----- % % - initial guess of value function - % v0 = zeros(states,1); % - start iterations - % crit1 = 3; for j = 1:iters ; if crit1 < 0.0001, break, end; % - compute second period payoffs and policy - % payoff11 = 1/(1-beta)*w ; payoff12 = c + beta*P*v0 ; payoff0 = [payoff11 payoff12 ]; [newv0,policy0] = max(payoff0') ; % - put matrices back to correct dimension - % newv0 = newv0'; policy0 = policy0'; iter = j; % - compute criterion - % crit1 = sqrt((newv0-v0)'*(newv0-v0))/(1+sqrt(v0'*v0)) ; % - update - % v0 = newv0; end; % ----- print solutions ----- % [w,v0,policy0], [crit1, iter] w0bar = sum(any(policy0-1,2)) comptime = etime(clock, time0) diary off