function hessf
function [h]=hessf(f,x)
ep=1e-5;
for i=1:length(x)
for j=1:length(x)
if i==j
y=x;
z=x;
y(i)=y(i)+2*ep;
z(i)=z(i)+ep;
h(i,j)=(f(y)-2*f(z)+f(x))/ep^2;
if h(i,j)<=0.001
h(i,j)=0;
end;
else
y=x;
z=x;
u=x;
y(i)=y(i)+ep;
y(j)=y(j)+ep;
z(j)=z(j)+ep;
u(i)=u(i)+ep;
h(i,j)=(f(y)-f(z)-f(u)+f(x))/ep^2;
if h(i,j)<=0.001
h(i,j)=0;
end;
end;
end;
end;
Aucun commentaire:
Enregistrer un commentaire