matthieuheitz
2/2/2017 - 6:42 PM

Compute numerical derivatives on Matlab

Compute numerical derivatives on Matlab

% Jacobian functor
J = @(x,h,F)(F(repmat(x,size(x'))+diag(h))-F(repmat(x,size(x'))))./h';
% Function to differentiate
T = @(x) x./sum(x);
% Evaluation point
x = [0.9134;0.6324;0.0975;0.2785;0.5469];
% Step in each dimension (has to be small enough compared to x)
h = 1e-5*ones(size(x));

% Compute the Jacobian
J(x,h,T)



% Other method to compare the result (need Optimization Toolbox)
[~,~,~,~,~,~,jacobian] = lsqnonlin(T,x,[],[],optimset('MaxFunEvals',0))