dynare/matlab/mcp_func.m

45 lines
1.5 KiB
Matlab
Raw Normal View History

2016-05-05 20:40:14 +02:00
function [res,fjac,domer] = mcp_func(x,jacflag)
2016-07-05 19:41:24 +02:00
% function [res,fjac,domer] = mcp_func(x,jacflag)
% wrapper function for mixed complementarity problem when using PATH
2017-05-16 15:10:20 +02:00
%
% INPUTS
2016-07-05 19:41:24 +02:00
% - x [double] N*T array, paths for the endogenous variables (initial guess).
% - jacflag [scalar] indicator whether Jacobian is requested
%
2017-05-16 15:10:20 +02:00
% OUTPUTS
2016-07-05 19:41:24 +02:00
% - res [double] (N*T)*1 array, residuals of the stacked problem
% - fjac [double] (N*T)*(N*T) array, Jacobian of the stacked problem
% - domer [scalar] errorflag that is 1 if solution is not real
2017-05-18 18:36:38 +02:00
% Copyright (C) 2016-2017 Dynare Team
2016-07-05 19:41:24 +02:00
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
2016-05-05 20:40:14 +02:00
global mcp_data
if jacflag
[res,fjac] = mcp_data.func(x,mcp_data.args{:});
2016-05-10 14:18:34 +02:00
fjac = sparse(fjac);
2016-05-05 20:40:14 +02:00
else
res = mcp_data.func(x,mcp_data.args{:});
fjac = [];
end
2016-05-10 14:18:34 +02:00
if isreal(res)
domer = 0;
else
domer = 1;
end