0% ont trouvé ce document utile (0 vote)
11 vues9 pages

Analyse numérique par Mohammed Babi

Transféré par

Moustafa Fanè
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
11 vues9 pages

Analyse numérique par Mohammed Babi

Transféré par

Moustafa Fanè
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd

COMPTE RENDUE TP ANALYSE NUMERIQUE 

:
Réalisé par : MOHAMMED BABI (groupe :1)
I. TP1 :
Exercice 1 :
On considère les trois fonctions suivantes :
F1(x)=sin(x)*√ x+1 
F2(x)=exp(x)+x²
F3(x)=1/1+IxI
1)
>>x=0:0.1:1

x=

0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000

>> f1=sin(x).*sqrt(x+1)

f1 =

0 0.1047 0.2176 0.3369 0.4608 0.5872 0.7142 0.8400 0.9624 1.0797 1.1900

>> plot(x,f1)
>> f2=exp(x)+x.*x

f2 =

1.0000 1.1152 1.2614 1.4399 1.6518 1.8987 2.1821 2.5038 2.8655 3.2696
3.7183

>> plot(x,f2)
>> f3=1/1+abs(x)

f3 =

1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000
2.0000

plot(x,f3)
 Présentation de trois fonctions dans la même figure :
>> plot(x,f1);

>> hold all

>> plot(x,f2);

>> hold all

>> plot(x,f3);

2) Présentation de trois fonctions dans la même fenêtre :


>> subplot(311);
>> plot(x,f1)
>> subplot(312);
>> plot(x,f2);
>> subplot(313);
>> plot(x,f3);
Exercice 2 :
1) if(a>b & a>c)

a=impact('max')

else if (b>a & b>c)

b=impact('max')

else c=impact('max')

end

2) fonction[P]=parente(a)

If mod(a,2)==0

P=impact(‘a est pair’)

else

P=impact(‘a est impair’)

end

end

Exercice 3 :
1)
A- (condition : i<100)
5
(While) ∑ ¿1+2+3+4+5
i=1

i =1 ; s=0
while (i<=5)
s= s + i
i=i + 1
end

(for ) : s=0 ;

for i=1 :5
s=s + i

end

B-
(while) : i=1 ;s=0 ;
while (i<=100)
s=s + 2*sin(i)
i=i+1
end
100

(for) : s=∑ ¿2sin(i)


i=1

s=0 ;
for i=1 :100
s=s+2*sin(i) ;
end
2)
for i=60 :100
if mod(i,2)==0
i
end
end

Exercice4 :
>> U0=1;
V=[];
U1=0.5*U0+(1/5)
e=abs(U1-U0);
while (e>10^(-3))
U0=1 ;
>> U1=0.5*U0+(1/5);
>> e=abs(U1-U0);
>> v=[v u0]

Exercice5 :
1) U1 est une matrice triangulaire sup de U
U1=triu(U) ;
A=I-U*U ;
A=eye(4)-U.*U ;
Série TP2 :
I. Méthode d’Horner :
Function S=Horner(a,x)
K=length(a) ;
S=a(k) ;
For i=k-1 :-1 :1
S=S*x+a(i) ;
end
S ;
End
II. Matrice de Vandermonde :
function a= vandermande(x,y)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=length(x);
n=length(y);
A=zeros(n);
for i=1:n
for j=1:n
A(i,j)=x(i)^((j-1));
end
end
a=inv(A)*y;
end

III. Matrice de Lagrange :


function L = lagrange(X,x)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes her
L=[];
for i=1:1:length(X)
l=1;
for j=1:1:length(X)
if (i~=j)
l=l*((x-X(j))/(X(i)-X(j)));
end
L(i)=l;
end
L;
end
end
Série TP3 :
Objectif de la série :

Le but de ce chapitre est aborder le calcul général de


l’intégrale d’une fonction f(x) sur un domaine fini
délimité par des bornes finies a et b ( les cas des
a
bornes infinies n’est donc pas couvert ici ) :I=∫ f ( x ) dx
b

I) Méthode des rectangles :

-D’abord on doit indiquer la fonction sin :


function f = f(x)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
f=sin(x);
end

- Algorithme matlab des rectangles est :


function S = rectangle(a,b)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
S = 0;
S= S+(b-a)*f(b);
end
-
II) Méthode des Trapèzes :
function S = trapezes(a,b)
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
S=0;
S=S+((b-a)*(f(a)+f(b)))/2;
end

III) Méthode des Simpson :


function S = Simpson(a,b)
%UNTITLED9 Summary of this function goes here
% Detailed explanation goes here
S=0;
S=S+((b-a)/6)*(f(a)+4*f((a+b)/2)+f(b));
end
Série TP4 :
I) Méthode de dichotomie :
La méthode de dichotomie ou bissection est un algorithme de recherche d’un zéro d’une fonction,
recherche de x telle que f(x)=0, qui consiste à répéter des partages d’un intervalle en deux parties
puis à sélectionner le sous intervalle dans lequel existe un zéro de la fonction.

.D’abord on doit saisir la fonction : f(x)=exp(x)-1 +x


function f = f(x)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
f = exp(x)+x-1 ;
end

.Après on détermine son domaine de définition : Df


function Df = Df(x)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
Df = exp(x)+1 ;
end

.Algorithme de Dichotomie est :


function m = Dichotomie(a,b)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
eps=10^(-3);
m=0;
n=1;
while (abs(b-a))>eps || n<100
m=(a+b)/2 ;
L=f(m) ;
if ((f(a)*L)>0)
a=m;
else
b=m;
n=n+1;
end
end
end

II) Méthode de Newton :


Aussi on détermine la fonction f(x)=exp(x)-1+x, et son domaine de définition .

Algorithme de Newton est :


function x = Newton(x0)
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
n=1;
eps=10^(-3);
L=f(x0);
k=Df(x0);
x=x0-L/k;
while ( abs(x-x0)>eps || n<100 )
x0=x ;
L=f(x0);
k=Df(x0);
x=x0-L/k;
n=n+1;
end
end

Série TP5 :
I) Méthode de Gauss :
C’est une méthode pour transformer un système équivalant qui est
triangulaire et est donc facile à résoudre.

-Algorithme de Gauss :
function x = Gauss(A,b)
%UNTITLED8 Summary of this function goes here
% Detailed explanation goes here
x=[];
U=[A b];
n=length(U);
for k=1:n-2
for i=k+1:n-1
w=U(i,k)/U(k,k);
for j=k:n-1
U(i,j)=U(i,j)-(w*U(k,j));
end
end
end
for i=n-1:-1:1
s=0;
for j=i+1:n-1
s=s+(U(i,j)*x(j));
end
x(i)=(U(i,i)-s)/U(i,i);
end
end

II) Méthode de DLU :


function [L,U] = decomposition(A)
%UNTITLED9 Summary of this function goes here
% Detailed explanation goes here
n=size(A,1);
L=eye(n);
U=zeros(n);
U(1,1:n)=A(1,1:n);
L(2:n,1)=A(2:n,1)/U(1,1);
for k=2:n
U(k,k:n)=A(k,k:n)-(L(k,1:k-1)*U(1:k-1,k:n));
L(k+1:n,k)=(A(k+1:n,k)-(L(k+1:n,1:k-1)*U(1:k-1,k)))/U(k,k);
end
L, U
end

I) Méthode de RLU :
function x = RLU(A,b)
%UNTITLED11 Summary of this function goes here
% Detailed explanation goes here
n=length(A);
L=[];
U=[];
[L,U]=decomposition(A);
y=[];
y(1)=b(1);
for i=2:n
s=0;
for k=1:i-1
s=s+(L(i,k)*y(k));
end
y(i)=b(i)-s;
end
x=[];
x(n)=y(n)/U(n,n);
for i=n-1:-1:1
s=0;
for j=i+1:n
s=s+(U(i,j)*x(j));
end
x(i)=(y(i)-s)/U(i,i);
end
x

end

Vous aimerez peut-être aussi