La méthode de la dichotomie : Méthode de Newton :
f=@(x) exp(x)-4*x; clear all;
a=0; close all;
b=1/2; clc
iteration=0; g=@(x) x+exp(x)+1;
tol=1e-7; dg=@(x) 1+exp(x);
c=(a+b)/2; f=@(x) x-g(x)/dg(x);
while((b-a)/2>tol || abs(f(c))>tol ) x0=-1/2;
if f(a)*f(c)<0 x1=f(x0);
b=c; tol=10^(-10);
end iter=1;
if f(b)*f(c)<0 while (abs(x1-x0)>tol )
a=c; x0=x1;
end x1=f(x0);
c=(a+b)/2; iter=iter+1;
iteration=iteration+1; end
end fprintf('la solution de g(x)=0 est %.15f \n' ,x0)
c fprintf(' le nombre d''itérations %d \n',iter)
x=-2:0.01:1;
La méthode du point fixe : y=g(x);
F=@(t) 20./(t.^2+2*t+10); y1=dg(x0)*(x-x0)+g(x0);
t=1:0.01:2; plot(x,y)
y1=F(t); hold on
y2=t; plot(x0,g(x0),'*')
plot(t,y1); hold on
hold on plot(x,y1)
plot(t,y2) hold off
grid on grid on
hold off
format long La méthode de la sécante :
x=zeros(9,1); f=@(x) x-0.2*sin(4*x)-1/2;
x(1)=1; g=@(x,y) x-f(x).*((x-y)./(f(x)-f(y)));
for i=1:8 x0=-1;
x(i+1)=F(x(i)); x1=2 ;
end tol=10^(-10);
x iter=1;
while (abs(x1-x0)>tol )
x2=g(x1,x0);
Méthode de Simpson x0=x1;
f=@(x) sin(x); x1=x2;
a=0; iter=iter+1;
b=pi/2; end
n=2 ; x1
h=(b-a)/n; iter
x=a:h:b;
val=0;
for i=1:n
val=val+f(x(i)) + 4*f((x(i)+x(i+1))/2) +f(x(i+1));
end
val=val*h/6
erreur = abs(1-val)
La Méthode d’interpolation de Newton Interpolation de Lagrange avec points de Tchebychev
f=@(x) 1./(1+x.^2); x=-5:1:5;
x = [-5:1:5]; n=length(x);
fx = f(x); t=-5:0.01:5;
n=length(x)-1; polyn=0;
D = zeros(n+1, n+1); xChe=5*cos((2*(n-(1:n))+1)*pi/(2*n));
D(:, 1) = fx; y=1./(1+xChe.^2);
for i=1:n for i=1:n
for j=1:i lag=1;
D(i+1,j+1) = (D(i+1,j)-D(i,j)) / (x(i+1)-x(i-j+1)); for j=1:n
end if(i~=j)
end lag=(t-xChe(j))./(xChe(i)-xChe(j)).*lag;
a = diag(D) end
t = -5:0.1:5; end
yy = a(n+1)*ones(size(t)); polyn=polyn+lag.*y(i);
for i=n:(-1):1 end
yy = a(i) + yy.*(t-x(i)); figure(1);
end plot(xChe,y,'*k');
figure(1); hold on;
plot(t, yy, '-', x, fx, '*',t,f(t),'r'); plot(t,polyn,'b');
axis([-5 5 -1.5 2]); hold on;
plot(t,1./(1+t.^2),'r')
xlabel('x')
Interpolation de Lagrange ylabel('y')
x=-5:1:5; title('Interpolation de Lagrange pour n=10')
t=-5:0.01:5; legend('Points de TChebychev','Polynôme
polyn=0; interpolant','Fonction
n=length(x); 1/(1+x^2)')
y=1./(1+x.^2); axis([-5 5 -1.5 2]);
for i=1:n
lag=1;
for j=1:n Méthode des Trapèzes
if(i~=j) f=@(x) sin(x);
lag=(t-x(j))./(x(i)-x(j)).*lag; a=0 ; b=pi/2 ; n=4 ;
end h=(b-a)/n ;
end x=a:h:b ;
polyn=polyn+lag.*y(i); F=f(x);
end val=(F(1)+F(n+1))/2 ;
figure(1); for i=2 :n
plot(x,y,'*k'); val=val+F(i);
hold on; end
plot(t,polyn,'b'); val=val*h
hold on; erreur = abs(1-val)
plot(t,1./(1+t.^2),'r')
xlabel('x')
ylabel('y')
title('Interpolation selon Lagrange')
legend('Points d''interpolation','Polynôme
interpolant','Fonction 1/(1+x^2)')
axis([-5 5 -1.5 2]);