function A=Jacobi(f,x)
% Computes the derivative (Jacobi matrix) A=Df(x) of the function f at x.
% 
%   Syntax: 
%           A = Jacobi(f,x)
%   Arguments: 
%           f - a function handle that evaluates 
%               mx1 matrix y=f(x).  
%           x - an nx1 matrix
%   Returns: 
%           A - an mxn matrix, the Jacobian of f 
%   Description:
%           The program Jacobi uses a central difference quotient
%           to compute an approximation of the Jacobi matrix A=Df(x)
%           The file f.m must return an mx1 matrix y=f(x).  
%           The stepsize is h=1e-6.  
%   Examples: 
%          z = Jacobi(@sin, 0) returns 1.
%
%          If the m-file funk1.m contains 
%            function y = funk1(x)
%            y=x.^2-2;
%
%          then the command 
%            z = Jacobi(@funk1, 3) returns 6.
%
%          If the m-file funk2.m contains 
%            function y = funk2(x)
%            y=x'*x;
%
%          then the command 
%            A = Jacobi(@funk2, [1;2;3]) returns [2 4 6]. 
%   See also:
%

%----------------------------------------------------------------------
%   Date created: 
%
%   Author:  
%------------------------------+---------------------------------------+

h = 1e-6;
n=length(x);

for i=1:n
  x1 = x;
  x1(i) = x1(i) + h;
  x2 = x;
  x2(i) = x2(i) - h;
   A(:,i)=(f(x1)-f(x2))/(2*h);
end
  