1function d=jacob_element(func,element,args)
2% function d=jacob_element(func,element,args)
3% returns an entry of the finite differences approximation to the jacobian of func
4%
5% INPUTS
6%    func       [function name]    string with name of the function
7%    element    [int]              the index showing the element within the jacobian that should be returned
8%    args       [cell array]       arguments provided to func
9%
10% OUTPUTS
11%    d          [double]           jacobian[element]
12%
13% SPECIAL REQUIREMENTS
14%    none
15
16% Copyright (C) 2010-2011 Dynare Team
17%
18% This file is part of Dynare.
19%
20% Dynare is free software: you can redistribute it and/or modify
21% it under the terms of the GNU General Public License as published by
22% the Free Software Foundation, either version 3 of the License, or
23% (at your option) any later version.
24%
25% Dynare is distributed in the hope that it will be useful,
26% but WITHOUT ANY WARRANTY; without even the implied warranty of
27% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28% GNU General Public License for more details.
29%
30% You should have received a copy of the GNU General Public License
31% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
32
33func = str2func(func);
34
35h=10e-6;
36pargs=args;
37margs=args;
38% length(args) is used instead of size(args, 2) to avoid to transpose column vectors
39for i=1:length(args)
40    if i==element
41        pargs{i} = pargs{i} + h;
42        margs{i} = margs{i} - h;
43    end
44end
45d=(func(pargs{:})...
46   -func(margs{:}))/(2*h);
47