Last active
February 2, 2017 18:45
-
-
Save matthieuheitz/c79300ab99de832e7549640a2a77848e to your computer and use it in GitHub Desktop.
Compute numerical derivatives on Matlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment