Debian Codegraph @

tests/solver-test-functions/trigonometric.m

raw
1 function [fval, fjac] = trigonometric(x)
2
3 % Copyright © 2021 Dynare Team
4 %
5 % This file is part of Dynare.
6 %
7 % Dynare is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % Dynare is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
19
20 n = length(x);
21
22 if isnumeric(x) && isvector(x) && all(~isnan(x))
23 fval = zeros(n, 1);
24 sum = 0;
25 for j=1:n
26 fval(j) = cos(x(j));
27 sum = sum+fval(j);
28 end
29 for k=1:n
30 fval(k) = (n+k)-sin(x(k))-sum-k*fval(k);
31 end
32 if nargout>1
33 fjac = zeros(n);
34 for j=1:n
35 tmp = sin(x(j));
36 for k=1:n
37 fjac(k,j) = tmp;
38 end
39 fjac(j,j) = (j+1)*tmp-cos(x(j));
40 end
41 end
42 elseif isnumeric(x) && isvector(x) && all(isnan(x))
43 if nargout==1
44 fval = (1/n)*ones(n, 1);
45 else
46 error('One output is required for initialization mode.')
47 end
48 else
49 error('Wrong input argument.')
50 end