Removed useless output arguments from numerical gradient routines.

time-shift
Stéphane Adjemian (Scylla) 2014-01-22 17:35:31 +01:00
parent fd5dc8c14a
commit a15808b2ce
5 changed files with 17 additions and 18 deletions

View File

@ -1,11 +1,10 @@
function [g, badg] = numgrad2(fcn,f0,x,epsilon,varargin)
% function [g badg] = numgrad2(fcn,xvarargin)
% Original file downloaded from:
% http://sims.princeton.edu/yftp/optimize/mfiles/numgrad.m
% Copyright (C) 1993-2007 Christopher Sims
% Copyright (C) 2008-2013 Dynare Team
% Copyright (C) 2008-2014 Dynare Team
%
% This file is part of Dynare.
%

View File

@ -1,17 +1,17 @@
function [g, badg, f0, f1, f2] = numgrad3(fcn,f0,x,epsilon,varargin)
function [g, badg] = numgrad3(fcn,f0,x,epsilon,varargin)
% Computes the gradient of the objective function fcn using a three points
% formula if possible.
%
% Adapted from Sims' numgrad routine.
%
% See section 25.3.4 in Abramovitz and Stegun (1972, Tenth Printing, December) Handbook of Mathematical Functions.
% http://www.math.sfu.ca/~cbm/aands/
% http://www.math.sfu.ca/~cbm/aands/
% Original file downloaded from:
% http://sims.princeton.edu/yftp/optimize/mfiles/numgrad.m
% Copyright (C) 1993-2007 Christopher Sims
% Copyright (C) 2008-2012 Dynare Team
% Copyright (C) 2008-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -37,12 +37,12 @@ badg=0;
for i=1:n
xiold = x(i);
x(i) = xiold+h;
x(i) = xiold+h;
f1 = feval(fcn, x, varargin{:});
x(i) = xiold-h;
f2 = feval(fcn, x, varargin{:});
g0 = (f1-f2)/H;
if abs(g0)< 1e15
if abs(g0)< 1e15
g(i)=g0;
else
g(i)=0;

View File

@ -1,17 +1,17 @@
function [g, badg, f0, f1, f2] = numgrad3_(fcn,f0,x,epsilon,varargin)
function [g, badg] = numgrad3_(fcn,f0,x,epsilon,varargin)
% Computes the gradient of the objective function fcn using a three points
% formula if possible.
%
% Adapted from Sims' numgrad routine.
%
% See section 25.3.4 in Abramovitz and Stegun (1972, Tenth Printing, December) Handbook of Mathematical Functions.
% http://www.math.sfu.ca/~cbm/aands/
% http://www.math.sfu.ca/~cbm/aands/
% Original file downloaded from:
% http://sims.princeton.edu/yftp/optimize/mfiles/numgrad.m
% Copyright (C) 1993-2007 Christopher Sims
% Copyright (C) 2008-2012 Dynare Team
% Copyright (C) 2008-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -55,7 +55,7 @@ for i=1:n
else
g0 = (f1 - f2) / (2*h);
end
if abs(g0)< 1e15
if abs(g0)< 1e15
g(i) = g0;
else
disp('Bad gradient -----------------------------------')

View File

@ -1,11 +1,11 @@
function [g, badg, f0, f1, f2, f3, f4] = numgrad5(fcn,f0,x,epsilon,varargin)
function [g, badg] = numgrad5(fcn,f0,x,epsilon,varargin)
% Computes the gradient of the objective function fcn using a five points
% formula if possible.
%
% Adapted from Sims' numgrad.m routine.
%
% See section 25.3.6 Abramovitz and Stegun (1972, Tenth Printing, December) Handbook of Mathematical Functions.
% http://www.math.sfu.ca/~cbm/aands/
% http://www.math.sfu.ca/~cbm/aands/
%
% TODO Try Four points formula when cost_flag3=0 or cost_flag4=0.
@ -13,7 +13,7 @@ function [g, badg, f0, f1, f2, f3, f4] = numgrad5(fcn,f0,x,epsilon,varargin)
% http://sims.princeton.edu/yftp/optimize/mfiles/numgrad.m
% Copyright (C) 1993-2007 Christopher Sims
% Copyright (C) 2008-2012 Dynare Team
% Copyright (C) 2008-2014 Dynare Team
% This file is part of Dynare.
%
@ -48,7 +48,7 @@ for i=1:n
x(i) = xiold-2*h;
f4 = feval(fcn, x, varargin{:});
g0 = (8*(f1-f2)+f4-f3)/H;
if abs(g0)< 1e15
if abs(g0)< 1e15
g(i) = g0;
else
g(i) = 0;

View File

@ -1,11 +1,11 @@
function [g, badg, f0, f1, f2, f3, f4] = numgrad5(fcn,f0,x,epsilon,varargin)
function [g, badg] = numgrad5(fcn,f0,x,epsilon,varargin)
% Computes the gradient of the objective function fcn using a five points
% formula if possible.
%
% Adapted from Sims' numgrad.m routine.
%
% See section 25.3.6 Abramovitz and Stegun (1972, Tenth Printing, December) Handbook of Mathematical Functions.
% http://www.math.sfu.ca/~cbm/aands/
% http://www.math.sfu.ca/~cbm/aands/
%
% TODO Try Four points formula when cost_flag3=0 or cost_flag4=0.
@ -13,7 +13,7 @@ function [g, badg, f0, f1, f2, f3, f4] = numgrad5(fcn,f0,x,epsilon,varargin)
% http://sims.princeton.edu/yftp/optimize/mfiles/numgrad.m
% Copyright (C) 1993-2007 Christopher Sims
% Copyright (C) 2008-2012 Dynare Team
% Copyright (C) 2008-2014 Dynare Team
%
% This file is part of Dynare.
%