2021-01-12 16:48:49 +01:00
|
|
|
function d=jacob_element(func,element,args)
|
|
|
|
% function d=jacob_element(func,element,args)
|
2010-02-22 17:33:38 +01:00
|
|
|
% returns an entry of the finite differences approximation to the jacobian of func
|
|
|
|
%
|
|
|
|
% INPUTS
|
2010-10-07 14:15:56 +02:00
|
|
|
% func [function name] string with name of the function
|
2021-01-12 16:48:49 +01:00
|
|
|
% element [int] the index showing the element within the jacobian that should be returned
|
2010-02-22 17:33:38 +01:00
|
|
|
% args [cell array] arguments provided to func
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
2021-01-12 16:48:49 +01:00
|
|
|
% d [double] jacobian[element]
|
2010-02-22 17:33:38 +01:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2020-05-04 18:12:41 +02:00
|
|
|
% Copyright (C) 2010-2020 Dynare Team
|
2010-02-22 17:33:38 +01: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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2010-02-22 17:33:38 +01:00
|
|
|
|
2021-01-12 16:48:49 +01:00
|
|
|
assert(element <= length(args));
|
2020-05-04 18:12:41 +02:00
|
|
|
|
2010-10-07 14:15:56 +02:00
|
|
|
func = str2func(func);
|
|
|
|
|
2020-07-06 18:42:21 +02:00
|
|
|
h=1e-6;
|
2010-02-22 17:33:38 +01:00
|
|
|
margs=args;
|
2020-05-04 18:12:41 +02:00
|
|
|
|
2021-01-12 16:48:49 +01:00
|
|
|
args{element} = args{element} + h;
|
|
|
|
margs{element} = margs{element} - h;
|
2020-05-04 18:12:41 +02:00
|
|
|
|
|
|
|
d=(func(args{:})-func(margs{:}))/(2*h);
|
2010-02-22 17:33:38 +01:00
|
|
|
end
|