function [f,d] = sigmoid(a,k)
%
%  This version treats k as a vector and returns
%  also the derivative using the formula from the
%  lecture notes.
%
error(nargchk(1,2,nargin));
if nargin<2
   k = 1;
end

if ~isempty(find(k < 1))
   error('k should be greater or equal to 1.');
end

f = 1./(1 + exp(-k.*a));
d = k .* f.*(1 - f);
