function [f,g]=fun(x) % f=scalar function of a vector x and g =gradient at f (a row vector). evaluations are % noisy p=length(x); m=ones(1,p); A=eye(p); % the actual minimum is at m f=(x-m)*A*(x-m)'+randn; g=2*(x-m)*A+randn(1,p);