From 04323301a52c2e975918cf5e044be4e086cc61cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 26 Mar 2019 16:49:39 +0100 Subject: [PATCH] isdiag was introduced in MATLAB R2014a Provide a replacement by reusing a similar function that was under matlab/general/utilities/. --- matlab/dynare_config.m | 5 +++++ matlab/imcforecast.m | 4 ++-- .../isdiagonal.m => missing/isdiag/isdiag.m} | 16 ++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) rename matlab/{utilities/general/isdiagonal.m => missing/isdiag/isdiag.m} (82%) diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 8d214fa49..75cbcb0a3 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -132,6 +132,11 @@ if ~isoctave && matlab_ver_less_than('7.11') p{end+1} = '/missing/is-row-column-matrix'; end +%% isdiag is missing in MATLAB < R2014a +if ~isoctave && matlab_ver_less_than('8.4') + p{end+1} = '/missing/isdiag'; +end + P = cellfun(@(c)[dynareroot(1:end-1) c], p, 'uni',false); % Get mex files folder(s) diff --git a/matlab/imcforecast.m b/matlab/imcforecast.m index 4760dfa1d..4b132c5dc 100644 --- a/matlab/imcforecast.m +++ b/matlab/imcforecast.m @@ -180,7 +180,7 @@ if options_.loglinear && isfield(oo_.dr,'ys') && options_.logged_steady_state==0 options_.logged_steady_state=1; %set option for use in stoch_simul end -if ~isdiagonal(M_.Sigma_e) +if ~isdiag(M_.Sigma_e) warning(sprintf('The innovations are correlated (the covariance matrix has non zero off diagonal elements), the results of the conditional forecasts will\ndepend on the ordering of the innovations (as declared after varexo) because a Cholesky decomposition is used to factorize the covariance matrix.\n\n=> It is preferable to declare the correlations in the model block (explicitly imposing the identification restrictions), unless you are satisfied\nwith the implicit identification restrictions implied by the Cholesky decomposition.')) sQ = chol(M_.Sigma_e,'lower'); else @@ -299,4 +299,4 @@ forecasts.graph.fname = M_.fname; %reset qz_criterium options_.qz_criterium=qz_criterium_old; -save('conditional_forecasts.mat','forecasts'); \ No newline at end of file +save('conditional_forecasts.mat','forecasts'); diff --git a/matlab/utilities/general/isdiagonal.m b/matlab/missing/isdiag/isdiag.m similarity index 82% rename from matlab/utilities/general/isdiagonal.m rename to matlab/missing/isdiag/isdiag.m index a8c1a4cf8..89dcec2f1 100644 --- a/matlab/utilities/general/isdiagonal.m +++ b/matlab/missing/isdiag/isdiag.m @@ -1,4 +1,4 @@ -function b = isdiagonal(A) % --*-- Unitary tests --*-- +function b = isdiag(A) % --*-- Unitary tests --*-- % Copyright (C) 2014-2017 Dynare Team % @@ -25,38 +25,38 @@ if isnumeric(A) % in ir and ic (row and column numbers) should be equal. b = isequal(ir, ic); else - error('isdiagonal: Input must be a square matrix!') + error('isdiag: Input must be a square matrix!') end else - error('isdiagonal: Input must be numeric!') + error('isdiag: Input must be numeric!') end %@test:1 %$ A = zeros(3,3); -%$ t = isdiagonal(A); +%$ t = isdiag(A); %$ T = all(t); %@eof:1 %@test:2 %$ A = zeros(3,3); A(1,3) = 1; -%$ t = ~isdiagonal(A); +%$ t = ~isdiag(A); %$ T = all(t); %@eof:2 %@test:3 %$ A = randn(3,3); -%$ t = ~isdiagonal(A); +%$ t = ~isdiag(A); %$ T = all(t); %@eof:3 %@test:4 %$ A = diag(randn(3,1)); -%$ t = isdiagonal(A); +%$ t = isdiag(A); %$ T = all(t); %@eof:4 %@test:5 %$ A = diag(randn(3,1)); A(1,1) = 0; -%$ t = isdiagonal(A); +%$ t = isdiag(A); %$ T = all(t); %@eof:5