Debian Codegraph @

tests/solver-test-functions/discreteintegralequation.m

raw
1 function [fval, fjac] = discreteintegralequation(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 h = 1.0/(n+1);
25 for k=1:n
26 tk = k*h;
27 sum1 = 0;
28 for j=1:k
29 tj = j*h;
30 tmp = (x(j)+tj+1)^3;
31 sum1 = sum1+tj*tmp;
32 end
33 sum2 = 0;
34 kp1 = k+1;
35 if n>=kp1
36 for j=kp1:n
37 tj = j*h;
38 tmp = (x(j)+tj+1)^3;
39 sum2 = sum2+(1-tj)*tmp;
40 end
41 end
42 fval(k) = x(k) + h*((1-tk)*sum1+tk*sum2)/2;
43 end
44 if nargout>1
45 fjac = zeros(n);
46 h = 1.0/(n+1);
47 for k=1:n
48 tk = k*h;
49 for j=1:n
50 tj = j*h;
51 tmp = 3*(x(j)+tj+1)^2;
52 fjac(k,j) = h*min(tj*(1-tk), tk*(1-tj))*tmp/2;
53 end
54 fjac(k,k) = fjac(k,k)+1;
55 end
56 end
57 elseif isnumeric(x) && isvector(x) && all(isnan(x))
58 if nargout==1
59 fval = discreteboundaryvalue(nan(n,1));
60 else
61 error('One output is required for initialization mode.')
62 end
63 else
64 error('Wrong input argument.')
65 end