You are on page 1of 9

Publique algérienne démocratique et

Populaire
Ministère de l'Enseignement Supérieur et de la Recherche
Université de khenchela
Département de Génie Civile_ travaux public

TP : méthode
numérique

_ Complété par l'étudiant :


_ BLAGHMAS Fateh

_ Professeur :
_CHERGUI Ahmed

Année scolaire : 2017/2018

1
TP1 : La Méthode de bissection

close all
clear all
clc
f=@(x)(x^3-x-4)
a=input('la valeur de a:')
b=input('la valeur de b:')
while((f(a)*f(b))>0)
a=input('la valeur de a')
b=input('la valeur de b')
end
while(abs(b-a)>eps)
x=(a+b)/2;
if f(a)*f(x)<0
b=x
else
a=x
end
end
fprintf('la solution et =%f',x)
x=0:0.001:3
f=x.^3-x.^2-x-1
plot(x,f)

2
TP2 : La Méthode de Newton :

clear all
close all
clc
% f=x.^3+x-4
% f@(x)(x^3+x-4)
%df=@(x)(3*x^2+1)
%a=1;b=1
x=-1:0.1:3;
f=x.^3+x-4;
figure(1)
plot(x,f);
grid on;
title('fonction : f(x)=x.^3+x-4');
f=@(x)(x^3+x-4)
df=@(x)(3*x^2+1)
a=1; b=2;
x=a;
for i=1;20
x1=x-(f(x)/df(x));
x=x1
end
sol=x
fprintf('approximate root is %.15f',sol)
a=1;b=2;x=a;
er(5)=0;
for i=1:1:5
x1=x-(f(x)/df(x));
x=x1;
er(i)
end
er
figure(2)
plot(er)
xlabel('nombre of iturations')

3
4
TP3 : La Méthode de point fixe :
clear all
clc
g=inline('sqrt(1./(x.*exp(x)))');
x0=input('x0=');
n=input('n=');
for i=1:n
x1=g(x0);
disp(x0)
if abs(x1-x0)<0.00001
break
else
x0=x1;
end
end
x=-1:0.001:5;
plot(x,sqrt(1./(x.*exp(x))),'--', x, x, '--')
grid on;
ylabel('y');
xlabel('x');
title('point fixe');

TP4 :
5
clear all
clc
A=[-8 4 -2 1;1 1 1 1;8 4 2 1;27 9 3 1];
b=[1;0;3;4];
X = A^(-1)*b
%%
X=[-4:0.01:4]
p= -0.3667 * X.^3 + 1.2 * X.^2 + 1.9667 *
X.^1 - 2.8
plot(p)
xlabel('X')
ylabel('Y')
title('p(x)')

TP 5: La Méthode de la grange :
clc
6
syms x
p=0
%interpolation de lagange eme année TP

s=[2 0 1]
f=[27 -1 0]
n=length(s);
for i=1:n;
l=1;
for j=1:n;

if (i~=j);
l=((x-s(j))/(s(i)-s(j)))*1;
end
end
p=l.*f(i)+p
end
p=collect(p)
x=[-2:0.001:2];
p=13*x.^2 - 12*x - 1;
plot(x,p)

TP 6 :

7
%createvectore of 11 aqually spaced points in
[-5,5]
x=linspace(-5,5,11);
y=1./(1+x.^2);
p=polyfit(x,y,10);
xx=linspace(-5,5);
yy=1./(1+xx.^2);
plot(xx,yy)
hold on
plot(xx,polyval(p,xx),'r--')
plot(x,y,'o')
xlabel('x')
ylabel('y')

TP 7:méthode d’aleur
clc

8
clear
syms f x y
h=input('step size=');
f=input('the fonction f(x,y)=');
X(1)=input('x0)=');
Y(1)=input('y0=');
xf=input('xf');
for i=1:(xf-X(1))/h
X(i+1)=X(i)+h
y=Y(i);
x=X(i);
Y(i+1)=Y(i)+h-subs(f);
end
Y
plot (X,Y,'r.')

You might also like