diff --git a/matlab/lmmcp/get_complementarity_conditions.m b/matlab/lmmcp/get_complementarity_conditions.m index 5d3f961f59f304ebdaf915f6b41d1505a0ba4356..d17f0c21e4cb0a1ba246899f751fbbd9f09c5a66 100644 --- a/matlab/lmmcp/get_complementarity_conditions.m +++ b/matlab/lmmcp/get_complementarity_conditions.m @@ -12,7 +12,7 @@ function [lb,ub,eq_index] = get_complementarity_conditions(M_,ramsey_policy) % from complementarity setup used in % perfect_foresight_mcp_problem.m -% Copyright © 2014-2018 Dynare Team +% Copyright © 2014-2024 Dynare Team % % This file is part of Dynare. % @@ -60,8 +60,10 @@ for i=1:size(etags,1) error('Complementarity condition %s: variable %s is not recognized', etags{i,3}, strtrim(str(1:kop-1))) end ub(k) = str2num(str(kop+1:end)); + swapped_eq_nbr = find(eq_index == k); + assert(length(swapped_eq_nbr) == 1); + eq_index(swapped_eq_nbr) = eq_index(eq_nbr); eq_index(eq_nbr) = k; - eq_index(k) = eq_nbr; else kop = strfind(etags{i,3},'>'); if ~isempty(kop) @@ -70,8 +72,10 @@ for i=1:size(etags,1) error('Complementarity condition %s: variable %s is not recognized', etags{i,3}, strtrim(str(1:kop-1))) end lb(k) = str2num(str(kop+1:end)); + swapped_eq_nbr = find(eq_index == k); + assert(length(swapped_eq_nbr) == 1); + eq_index(swapped_eq_nbr) = eq_index(eq_nbr); eq_index(eq_nbr) = k; - eq_index(k) = eq_nbr; else error('Complementarity condition %s can''t be parsed',etags{i,3}) end