E=inline('(xx-3).^2+cos(xx)+exp(-0.1*xx)','xx');
dE=inline('2*(xx-3)-sin(xx)-0.1*exp(-0.1*xx)','xx');
eta=0.3;

w(1)=5;
for i=1:10
    w(i+1)=w(i)-eta*dE(w(i));
end
w(end)
E(w(end))
dE(w(end))

 

ans =

    3.0717


ans =

   -0.2569


ans =

   1.2706e-09 < 10^-5