| 1 |
function [fval, fjac] = helicalvalley(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 |
C7 = 0.25; |
| 21 |
C8 = 0.5; |
| 22 |
TPI = 8*atan(1); |
| 23 |
|
| 24 |
if nargin==1 |
| 25 |
fval = zeros(3, 1); |
| 26 |
tmp1 = C7*sign(x(2)); |
| 27 |
if x(1)>0 |
| 28 |
tmp1 = atan(x(2)/x(1))/TPI; |
| 29 |
end |
| 30 |
if x(1)<0 |
| 31 |
tmp1 = atan(x(2)/x(1))/TPI+C8; |
| 32 |
end |
| 33 |
tmp2 = sqrt(x(1)*x(1)+x(2)*x(2)); |
| 34 |
fval(1) = 10*(x(3)-10*tmp1); |
| 35 |
fval(2) = 10*(tmp2-1); |
| 36 |
fval(3) = x(3); |
| 37 |
if nargout>1 |
| 38 |
fjac = zeros(3); |
| 39 |
tmp = x(1)*x(1)+x(2)*x(2); |
| 40 |
tmp1 = TPI*tmp; |
| 41 |
tmp2 = sqrt(tmp); |
| 42 |
fjac(1,1) = 100*x(2)/tmp1; |
| 43 |
fjac(1,2) = -100*x(1)/tmp1; |
| 44 |
fjac(1,3) = 10; |
| 45 |
fjac(2,1) = 10*x(1)/tmp2; |
| 46 |
fjac(2,2) = 10*x(2)/tmp2; |
| 47 |
fjac(2,3) = 0; |
| 48 |
fjac(3,1) = 0; |
| 49 |
fjac(3,2) = 0; |
| 50 |
fjac(3,3) = 1; |
| 51 |
end |
| 52 |
elseif ~nargin |
| 53 |
if nargout==1 |
| 54 |
fval = [-1; 0; 0]; |
| 55 |
else |
| 56 |
error('One output is required for initialization mode.') |
| 57 |
end |
| 58 |
else |
| 59 |
error('Wrong number of input arguments.') |
| 60 |
end |