function [ opt, seq] = gradDesc2( x0, df)
%The gradient descent with functions.
%df is a cellarray of the derivative function handles
alpha = 0.05; 
grad = zeros(length(x0),1);
nofIterations = 20000;
seq = zeros(2,nofIterations);
seq(:,1) = x0;

optMeth = -1; %+1 if maximizing, -1 if minimizing

for i=2:nofIterations
    for j=1:length(grad)
        grad(j) = df{j}(seq(:,i-1));
    end
    seq(:,i) = seq(:,i-1) + optMeth .* alpha .* grad./norm(grad);
end

opt = seq(:,end);

end

