Vous êtes sur la page 1sur 7

Compte rendu

TP4 Matlab : RESOLUTION DES EQUATIONS


DIFFERENTIELLES
Méthodes Numériques

REALISE PAR : AYOUB GASSOU


ENCADRE PAR : Pr.Salaheddine Kammouri Alami

TP :Méthodes Numériques IMT S2 2022- 1


2023
Application2 avec la méthode d'Euler :

clear all,close all


f1=inline('(t-y1)/2');
a=0;
b=6;
h=0.1;
N=floor((b-a)/h);
t=[0:0.1:6];
y1=zeros(1,N); y1(1)=1;
for i=1 : N
y1(i+1)=y1(i)+h*f1(t(i),y1(i));
end

plot(t,y1,'o-r')
hold on

Application2 avec method runge kutta ordre 4:

f2=inline('(t-y2)/2');
a=0;
b=6;
h=0.1;
N=floor((b-a)/h);
t=[a:h:b];
y2=zeros(1,N); y2(1)=1;
for i=1 : N
k1=f2(t(i),y2(i));
k2=f2(t(i)+h/2,y2(i)+k1*h/2);
k3=f2(t(i)+h/2,y2(i)+k2*h/2);
k4=f2(t(i)+h,y2(i)+k3*h);
y2(i+1)=y2(i)+(h/6)*(k1+2*k2+2*k3+k4);
end

plot(t,y2,'o-g')
hold on
Application2 avec méthode de heun:

f3=inline('(t-y3)/2');
a=0;
b=6;
h=0.1;
N=floor((b-a)/h);
t=[0:0.1:6];
y3=zeros(1,N); y3(1)=1;
for i=1 :N
y3(i+1)=y3(i)+h/2*(f3(t(i),y3(i))+f3(t(i+1),y3(i)+h*f3(t(i),y3(i))))
end
plot(t,y3,'o-b')

Plote de la fonction exacte :

a=0; b=6; n=60;


h=(b-a)/n;
t=[a:h:b];
plot(t,3*exp(-t/2)+t-2,'o-y')
grid on

Maintenant, On va essayer une nouvelle commande qui donne le résultat d'Algorithme de Runge
kutta ordre 3(ODE23) ou Runge kutta ordre 4(ODE 45):

a=0;
b=6;
h=0.1;
N=floor((b-a)/h);
t=[a:h:b];
eqs=@(t,y3)[(t-y3)/2]
[t,y3]=ode45(eqs,[0;6],1)
plot(t,y3,'o-r')
Application 3: soit le problème de Cauchy :

Y'=y-2x/y

Y(0)=1

Solution avec la méthode d’Euler

clear all,close all


f1=inline('y1-2*t/y1');
a=0;
b=1;
h=0.02;
N=floor((b-a)/h);
t=[0:0.02:1];
y1=zeros(1,N); y1(1)=1;
for i=1 : N
y1(i+1)=y1(i)+h*f1(t(i),y1(i));
end

plot(t,y1,'o-r')
hold on

Solution avec la méthode de Runge kutta d'ordre 4

f2=inline('y2-2*t/y2');
a=0;
b=1;
h=0.02;
N=floor((b-a)/h);
t=[a:h:b];
y2=zeros(1,N); y2(1)=1;
for i=1 : N
k1=f2(t(i),y2(i));
k2=f2(t(i)+h/2,y2(i)+k1*h/2);
k3=f2(t(i)+h/2,y2(i)+k2*h/2);
k4=f2(t(i)+h,y2(i)+k3*h);
y2(i+1)=y2(i)+(h/6)*(k1+2*k2+2*k3+k4)
end
plot(t,y2,'o')
hold on

Application2 avec méthode de heun:

f3=inline('y3-2*t/y3');
a=0;
b=1;
h=0.02;
N=floor((b-a)/h);
t=[0:0.02:1];
y3=zeros(1,N); y3(1)=1;
for i=1 :N
y3(i+1)=y3(i)+h/2*(f3(t(i),y3(i))+f3(t(i+1),y3(i)+h*f3(t(i),y3(i))))
end
plot(t,y3,'o-r')

Plote de la fonction exacte :

a=0; b=1;
h=0.02;
t=[a:h:b];
plot(t,sqrt(2*t+1),'g')
grid on

Maintenant, Avec la commande qui donne le résultat d'Algorithme de Runge kutta ordre 3(ODE23)
ou Runge kutta ordre 4(ODE 45):

a=0;
b=1;
h=0.1;
N=floor((b-a)/h);
t=[a:h:b];
eqs=@(t,y4)[y4-2*t/y4]
[t,y4]=ode45(eqs,[0;1],1)
plot(t,y4,'o-y')

CONCLUSION :
On constate que les 3 méthodes nous donnent un bon approchement à la solution
exacte, Mais cette hypothèse peut être partiellement fausse si on commence à
varier les intervalles ou les nombres d’itérations, et aussi que le cout et la
précision de chacune de ces trois méthodes dépend des paramètres qu’on a
mentionnés

FIN DU COMPTE-RENDU

Vous aimerez peut-être aussi