Debian Codegraph @

tests/solver-test-functions/powell1.m

raw
1 function [fval, fjac] = powell1(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 if nargin==1
21 fval = zeros(4, 1);
22 fval(1) = x(1)+10*x(2);
23 fval(2) = sqrt(5)*(x(3)-x(4));
24 tmp = x(2)-2*x(3);
25 fval(3) = tmp*tmp;
26 tmp = x(1)-x(4);
27 fval(4) = sqrt(10)*tmp*tmp;
28 if nargout>1
29 fjac = zeros(4);
30 fjac(1,1) = 1;
31 fjac(1,2) = 10;
32 fjac(2,3) = sqrt(5);
33 fjac(2,4) = -fjac(2,3);
34 fjac(3,2) = 2*(x(2)-2*x(3));
35 fjac(3,3) = -2*fjac(3,2);
36 fjac(4,1) = 2*sqrt(10)*(x(1)-x(4));
37 fjac(4,4) = -fjac(4,1);
38 end
39 elseif ~nargin
40 if nargout==1
41 fval = [3; -1; 0; 1];
42 else
43 error('One output is required for initialization mode.')
44 end
45 else
46 error('Wrong number of input arguments.')
47 end