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;
Affichage des articles dont le libellé est étude/cours. Afficher tous les articles
Affichage des articles dont le libellé est étude/cours. Afficher tous les articles
mercredi 18 décembre 2013
Algorithme comment calculer le gradient (sur matlab)
function gradf
function[d]=gradf(f,x)
h=0.00001;
n=length(x);
for i=1:n
y=x;
y(i)=y(i)+h;
df(i)=(f(y)-f(x))/h;
x=y;
end
d=transp(df);
function AlgoNewton
function[x]=AlgoNewton(f,x)
h=0.0001;
d2f=hessf(f,x);
if (det(d2f)==0)
disp('la méthode de newton n''est pas applicable pour les matrices non inversibles');
else
df=gradf(f,x);
while ((norm(df))^2>h)
df=gradf(f,x);
d2f=hessf(f,x);
d=-(inv(d2f))*df;
x=x+d;
end
disp('la solution optimale du problème est: ');
x;
disp('la valeur minimale que peut donc atteindre f est: ');
f(x)
end
Tp Programmation Mathématique (Compilation sur Matlab)
function AlgoFletcher
function[x]=AlgoFletcher(f,D,x,ep)
g=gradf(f,x);
while((norm(g))^2>ep)
g=gradf(f,x);
d=-gradf(f,x);
a=-transp(d)*g;
b=transp(d)*D*d;
alpha=a/b;
x=x+alpha*d;
gs=gradf(f,x);
beta=(norm(gs))^2/(norm(g))^2;
ds=-gs+beta*d;
end
disp('la solution du problème est: ');
x;
disp('la valeur minimale que peut donc atteindre f est: ');
f(x)
end
Inscription à :
Articles (Atom)