Vous êtes sur la page 1sur 6

REPUBLIQUE ALGERIENNE DEMOCRATIQUE ET POPULAIRE

Ministère de l’enseignement supérieur et


de la recherche scientifique ‫وزارة التعليــم العالــي والبحــث العلمـي‬
Ecole nationale polytechnique de ‫المدرسة الوطنية المتعددة التقنيات‬
Constantine ‫قسنطينة‬

Département Génie des procédés

Optimisation

Programmation sur MATLAB des méthodes numériques

morsi abir katar nada


5ème année GP
2020/2021
I. Les méthodes directes
I.1. Méthode de Newton Raphson
Le script :
clear;clc;
n=10;
h=1
x(1)=1
Epsilone=10^-6;

for i=1:h:n
x(i+1)=x(i)-(df(x(i))/ddf(x(i)))

while abs(x(i+1)-x(i))< Epsilone


break

end
end

La fonction :
function y= df(x)
y=2*x-1 ;
end
et
function y= df(x)
y=2;
end

I.2. Méthode de la sécante


Le script :
clear;clc;
n=10
h=1
x(1)=1
xp=-3 ;
xq=3;
epsilone=10^-6;

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

I.3. Méthode de Quasi-Newton


Le script:
clear;clc;
n=10
dx=1
x(1)=1
Epsilone=10^-6 ;

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

II.2. méthode d’approximation quadratique


Le script :
clear;clc;
x0=0 ; x1=1.5 ; x2=3;
h=1.5 ;
n=10 ;
e=10^-6;
for i=2:n
f0=f(x0);

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

II.3. Méthode de gradients conjugués


Le script :

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 :

function [y] = f( x1,x2 )


z= 2.*x1.^2+x2.^2-3
end

Vous aimerez peut-être aussi