Académique Documents
Professionnel Documents
Culture Documents
Optimisation
for i=1:h:n
x(i+1)=x(i)-(df(x(i))/ddf(x(i)))
end
end
La fonction :
function y= df(x)
y=2*x-1 ;
end
et
function y= df(x)
y=2;
end
for i=1:h:n
x(i+1)= x(i)+(dg(x(i))*(xq-xp))/(dg(xq)-dg(xp))
1
while abs ((x(i+1)-xp)/x(i+1)) < epsilone
break
end
end
La fonction :
function A= dg(x)
A=2*x-1 ;
end
for i=1:dx:n
x(i+1)=x(i)-(dx/2)*((f(x(i)+dx)- f(x(i)-dx))/(f(x(i)+dx)-2*f(x(i))+f(x(i)-dx)));
while abs((x(i+1)-x(i))/x(i+1))< Epsilone
break
end
end
La fonction
function y= f(x)
y=x^2-x ;
end
2
II. Les méthodes indirectes
II.1. Méthode de la section d’or (Golden-Section Search)
Le script :
clear;clc;
xl=0;
xu=2;
n=10
phi=0.618
e=10^-6;
x1=xu-phi*(xu-xl);
x2=xl+phi*(xu-xl);
while abs(x1-x2)<e
if f(x2)<f(x1)
xl=x1;
x1=xu-phi*(xu-xl);
else if f(x1)<f(x2)
xu=x2;
x2=xl+phi*(xu-xl);
end
end
end
xopt=(x1+x2)/2
La fonction
function y=f( x )
y=(x.*x − 4).^2/8 − 1;
end
3
f1=f(x1);
f2=f(x2);
x3(i)=0.5*(f0*(x1^2-x2^2)+f1*(x2^2-x0^2)+f2*(x0^2-x1^2))/(f0*(x1-x2)+f1*(x2-
x0)+f2*(x0-x1));
f3=f(x3(i));
A=[f0 f1 f2 f3];
Z=max(A)
if f0==Z
x=[x1 x2 x3(i)]
else if f1==Z
x=[x0 x2 x3(i) ]
else if f2==Z
x=[x0 x1 x3(i)]
else x=[x0 x1 x2]
end
end
end
X=sort(x)
x0=X(1) ;x1=X(2);x2=X(3);
if abs(x3(i)-x3(i-1))<e
break
end
end
z=i
x3
la fonctions :
function [ z ] = f( x )
z=(x.*x-4).^2/8-1;
end
4
clc;clear;
X=[1; 1];
n=100;
g=gradient(f)
H=[diff(g(1),x1),diff(g(1),x2);diff(g(2),x1),diff(g(2),x2)]
g=inline(g)
s=-g(X(1),X(2))
for i=1:n
S=s';
nablaf=[4*X(1,1); 2*X(2,1)]
transf=nblaf'
z=S*H*s;
p=-(transf*s);
A=p/z;
X=X+ A*s
s=[1 ;-2*s(1,1)/s(2,1)];
if transf==0
break
end
c=i
end
La fonction :