function [fx,gx,Hx] = fcombine(x,f,g,H)
% FCOMBINE Combine multiple functions into a single call
%
% FCOMBINE adapts routines that compute functions, gradients, and Hessians
% independently into a combined routine.  Ideally, this would be possible
% with Matlab's DEAL function, but that has problems when only a subset of
% the results are requested.
%
% Examples
%
%   Implement a subset of the ROSENBROCK function using fcombine
%
%   f = @(x) (1-x(1))^2 + 100*(x(2) - x(1)^2)^2;
%   g = @(x) [100*2*(x(2) - x(1)^2)*(-2)*x(1) - 2*(1-x(1)); 200*(x(2) - x(1)^2)];
%   fullf = @(x) fcombine(x,f,g);
%   [fx1,gx1] = fullf([0,0])
%   [fx2,gx2] = rosenbrock([0,0])
%
% See also DEAL

fx = f(x);
if nargout > 1
    gx = g(x);
    if nargout > 2
        Hx = H(x);
    end
end
