% La méthode de Newton clear all; close all; clc; % Les parametres d'entrée a=input('Donner a= '); b=input('Donner b= '); eps=input('Donner eps= '); Nmax=input('Pour la boucle for, donner Nmax= '); x=0:0.01:1; f=inline('cos(x)-x.^3'); df=inline('-sin(x)-3*x.^2'); ddf=inline('-cos(x)-6*x'); plot(x,f(x));grid %df=inline('tan(x) - sinh(x) + x.*(tan(x)^2 + 1)'); %ddf=inline('2*tan(x)^2 - cosh(x) + 2*x.*tan(x).*(tan(x)^2 + 1) + 2'); % % Le programme principal if (df(a)== 0 && df(b)== 0 || f(a)*f(b)>0) disp('On ne peut pas calculer la racine'); end % Initialisation de x0 if (f(a)*ddf(a)>0)% Fonction convexe x0=a; else % Fonction concave x0=b; end for i=1:Nmax x0 = x0 - f(x0)/df(x0); err=abs(f(x0)/df(x0)); % Affichage des resultats if err<=eps fprintf('i=%d\t racine=%2.6f\t f(x0)=%2.6f\t err=%2.6f\n',i,x0,f(x0),err); break; end end