function [x, fmin]=SD(f,x0,tol)
% Computes a minimum point x of the function f.
% 
%   Syntax: 
%           x = SD(f,x0,tol)
%   Arguments: 
%           f  - function handle that evaluates  
%                a scalar value y=f(x).  
%           x0 - an nx1 matrix containing the intial guess of
%                the minimum point
%           tol- tolerance for the iteration
%   Returns: 
%           x   - nx1 matrix with a minimum point of f 
%           fmin- the minimum value of f at the computed point
%   Description:
%           The program SD uses the steepest descent method by
%           performing fixpoint iteration over the equation
%           x = x - alpha*grad(f) where alpha is a damping factor.
%           The file f.m must return a scalar value y=f(x).
%
%   Examples: 
%           >> [x,fmin]=SD(@sin,pi,0.01)
%
%           x =
%
%               4.7031
%
%           fmin =
%
%              -1.0000
%
%         If the m-file funk1.m contains
%           function y = funk1(x)
%           y=x(1).^2-2*x(1)+x(2).^2;
%
%
%         then we get 
%           >> [x,fmin]=SD(@funk1,[1;0],0.01)
%
%           x =
%
%               1.0000
%                    0
%
%           fmin =
%
%               -1
%
%   See also:
%

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

alpha = .075;

grad = x0+tol/alpha;
x = x0;

while norm(alpha*grad) > tol
  grad = Jacobi(f,x);
  x = x - alpha*grad';
end
fmin = f(x);
