function X=gradientmethod(gradf,h,x0,maxit) %a version of the gradient method which return maxit %succesive aproximations for the minimum of f (given the gradient %gradf of f) X=zeros(length(x0),maxit);%reserving space X(:,1)=x0;%setting the initial aprox. for i=2:maxit x=x0-h*feval(gradf,x0);%next approx. X(:,i)=x;%saving the current aprox. x0=x;%overwriting the previous aprox. end