Académique Documents
Professionnel Documents
Culture Documents
1
Exemple
Pour illustrer la méthode, recherchons le nombre positif x vérifiant cos( x) = x 3 . Reformulons la question
pour introduire une fonction devant s'annuler : on recherche le zéro positif (la racine) de
f ( x) = cos( x) − x 3 = 0 . La dérivation donne f ' ( x) = − sin( x) − 3 x 2 .
Comme cos( x) ≤ 1 pour tout x et x 3 > 1 pour x > 1 , nous savons que notre zéro se situe entre 0 et 1.
Nous essayons une valeur de départ de x0 = 0.5 .
Script
clc,clear,close all
fct=inline('cos(x)-x.^3');
dfct=inline('-sin(x)-3*x.^2');
x=-2:0.1:2;
f=fct(x);plot(x,f);grid on
clear x
x(1)=input('Donner la valeur initiale x(1) :');
e=1e-5;
N=500;%nombre maximum d'itérations
for n=1:N
f=fct(x(n));
df=dfct(x(n));
x(n+1)=x(n)-f/df;
if(abs(x(n+1)-x(n)))<=e
xp=x(n+1);
fprintf('\nla solution xp = %f\n',xp);
break
end
end
fprintf('\n f(xp)= %e\n',fct(xp));
3. Limites
Cette méthode est très efficace dès qu'on est proche de la racine cherchée. De plus, elle se transpose
"facilement" au cas multi-dimensionnel. Elle a cependant certaines limites.
Le premier inconvénient de la méthode est le besoin de la dérivée de la fonction à calculer. Si on a une
expression analytique de cette fonction, cela ne pose pas de problème. Cependant, il arrive souvent que ce
ne soit pas le cas. Il faut alors évaluer numériquement la dérivée de cette fonction, ce qui est très délicat.
Une des limites de la méthode apparaît clairement dans sa formulation : si on se trouve en un point de
dérivée nulle, la méthode flanche. Numériquement, cela apparaît dès que la dérivée est voisine de zéro,
auquel cas la nouvelle valeur calculée est très grande: Le point d'intersection de la tangente et de l'axe des
x est rejeté à l'infini.
2
Résolution d'équations non linéaires dans Matlab
fonction « fzero »
inline
Construct inline object
Syntax
inline(expr)
inline(expr,arg1,arg2,...)
Description
inline(expr) constructs an inline function object from the MATLAB expression contained in the string
expr. The input argument to the inline function is automatically determined by searching expr for an
isolated lower case alphabetic character, other than i or j, that is not part of a word formed from several
alphabetic characters. If no such character exists, x is used. If the character is not unique, the one closest
to x is used. If two characters are found, the one later in the alphabet is chosen.
inline(expr,arg1,arg2,...) constructs an inline function whose input arguments are specified by the
strings arg1, arg2,.... Multicharacter symbol names may be used.
Example 1
g = inline('t^2')
g =
Inline function:
g(t) = t^2
Example 2
This call to inline defines the function f to be dependent on two variables, alpha and x:
f = inline('sin(alpha*x)')
f =
Inline function:
f(alpha,x) = sin(alpha*x)
If inline does not return the desired function variables or if the function variables are in the wrong order,
you can specify the desired variables explicitly with the inline argument list.
g = inline('sin(alpha*x)','x','alpha')
1. fzero
Find zero of a function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
[x,fval] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. fun is a function. The value x
returned by fzero is near a point where fun changes sign, or NaN if the search fails.
3
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1)) differs from
the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an interval guarantees
fzero will return a value near a point where fun changes sign.
Examples
f = inline(‘x.^3-2*x-5’);
Then find the zero near 2:
z = fzero(f,2)
z=
2.0946
Exercice1
1. Résoudre manuellement l’équation non linéaire x = ln (12 − x ) en utilisant la méthode de
2
3
Newton-Raphson en prenant comme valeur initiale x0 = 1.2000. Arrêter les calculs après 5
itérations.
2. Résoudre l’équation donnée en (1) par les commandes Matlab.
Exercice 2
1