Académique Documents
Professionnel Documents
Culture Documents
TP N◦ 1 RESOLUTION NUMERIQUE
DES EDO 2020-2021
yn+1 = yn + hf (tn , yn ).
5. Tracer la courbe du log des erreurs d’approximation en fonction du log des pas h;
yn+1/2 = yn + h2 f (tn , yn )
yn+1 = yn + hf (tn + h2 , yn+1/2 ).
2. Tracer les deux solutions approchées (Euler explicite et point milieu) et la solution exacte
sur la même figure
1
ENSAM-MEKNES 3EME ANNEE
TP N◦ 1 RESOLUTION NUMERIQUE
DES EDO 2020-2021
________________________________
%FICHIER : "prg_principal.m"
% Programme principal
clear all
close all
T=2.; % temps final
N=50; % Nombre de pas de temps
y0=2.; % solution initiale
[yap,tps]=EulerExp(@myfunc,y0,N,T);
plot(tps,yap)
xlabel(’temps t’);
ylabel(’y’);
title(’Solution approchee par Euler explicite’);
________________________________
________________________________
%FICHIER : "EulerExp.m"
%
function [liste_y,liste_t]=EulerExp(f,y0,N,T)
t=0; liste_t=[0];
y=y0; liste_y=[y0];
h=T/N;
for i=1:N
y=y+h*f(t,y);
t=t+h;
liste_t=[liste_t,t];
liste_y=[liste_y,y];
end
________________________________
________________________________
%FICHIER : "f1.m"
%
function yp = f1(t,y)
yp=t-t*y;
end
________________________________
________________________________
% Calcul de l’ordre numerique
% liste_h = 10:10:1000
% liste_e : la liste des erreurs correspondantes à liste_h
polyfit(log(liste_h),log(liste_e),1)
________________________________