%cd('S:\Dropbox\ZEF\Storage\storage_cooperation\calculation');
tic;clear all;
Mu                = [1 1];
sigma             = [0.06 0; 0 0.06];usesolver='path';
model = recsmodel('v25_standard.yaml',struct('Mu',Mu,'Sigma',sigma^2,'order',7),[],struct('eqsolver',usesolver));
%sc = model.params(end-1);

%% Define approximation space
[interp,s] = recsinterpinit(30,[0.6 0.6],[1.7 1.7]);
%Old borders: 0.6 0.6 and 2 2

%% Find a first guess through the perfect foresight solution
[interp,x] = recsFirstGuess(interp,model,s,model.sss,model.xss,...
    struct('T',5,'eqsolver',usesolver));
%toc;%136s

%% Solve for rational expectations%load test17_tempdata
[interp,x] = recsSolveREE(interp,model,s,x,...
    struct('eqsolver',usesolver,'loop_over_s',0, ...
'reemethod','iter'));toc;
%10,6s;18,1s;/ with border=0:10,1s;17.1s;
%% Simulate the model
% options.stat = 1;
% [SSIM,XSIM,ESIM,STAT,~]=recsSimul(model,interp,repmat([1 1],500,1),300,[],options);
% toc;clock;
%All times for notebook: (for PC maybe 50%-70% of this)
%8s for 4^2 with 1-step
%26s for 10^2; with 1-step: 14s
%43s for 20^2; with 1-step: 43; (afterwards, 1-step does't work) 97s for 30^2; 
%183s for 40^2 with loop_over_s=200
%374s for 50^2 with loop_over_s=400
%988s for 80^2 with loop_over_s=1000  /With loop=0 on PC: 456s
%PC: 827s for 100^2 with loop_over_s=1000
%PC: 1168s for 120^2 with loop_over_s=1000
% for i=1:size(XSIM,1)
%     for i2=1:size(XSIM,3)
%         if XSIM(i,1,i2)<0.195 && XSIM(i,9,i2)>0.004
%             [i i2]
%             XSIM(i,:,i2)
%         end;
%         if XSIM(i,2,i2)<0.195 && XSIM(i,10,i2)>0.004
%             [i i2]
%             XSIM(i,:,i2)
%         end;
%     end;
% end;
% for i=1:size(XSIM,1)
%     for i2=1:size(XSIM,3)
%         if XSIM(i,9,i2)>0.0054 && XSIM(i,10,i2)>0.0054
%             [i i2]
%             XSIM(i,:,i2)
%         end;
%     end;
% end;
% for i=1:size(XSIM,1)
%     for i2=1:size(XSIM,3)
%         XSIM(i,:,i2)
%     end;
% end;
% %XSIM(1000,:,300)