Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

METHODE DE NEWTON


Information sur la source

Description

Un programme écrit en pascal définit la méthode de newton
 

Source

  • program newton;
  • type
  • vect1 = array [1..15] of real;
  • vect2 = array [1..15] of char;
  • vect3 = array [1..15] of integer;
  • var
  • coef,ncoef :vect1;
  • cha:vect2;bol:boolean;
  • pui:vect3;
  • b1,n,i,deg,l,nbr,ln,gen,k:integer;
  • s,p,c,x,y,z,r,d,ep,fd,x0,a,b :real;
  • co,rep:char;op,op1: set of char;
  • ch:string;
  • ca:char;
  • (*fonction de la puissance*)
  • function pow(x:real;n:integer):real;
  • begin
  • p:=1;
  • for i := 1 to abs(n) do begin
  • if n < 0 then p:=p/10
  • else p:=p*x;
  • end;
  • pow:=p;
  • end;
  • (****************)
  • function chifi(chifr:char):integer;
  • begin
  • case chifr of
  • '1':chifi:=1;'2':chifi:=2;'3':chifi:=3;'4':chifi:=4;'5':chifi:=5;
  • '6':chifi:=6;'7':chifi:=7;'8':chifi:=8;'9':chifi:=9;'0':chifi:=0;
  • end;
  • end;
  • (*fonction qui lit la chaine de caractŠre*)
  • function cach(chaine:string):real;
  • var res:real;
  • point,j:integer;
  • begin
  • b1:=0;
  • for i:=1 to length(chaine) do if chaine[i]='.'then b1:=1;
  • if b1 = 0 then chaine:=chaine+'.';
  • if (chaine[1]<>'+') and (chaine[1]<>'-')then chaine:='+'+chaine;
  • point:=length(chaine)+1;
  • j:=1;
  • for i:=2 to length(chaine) do begin
  • if chaine[i]='.'then point:=i
  • else begin cha[j]:=chaine[i];j:=j+1;end;
  • end;
  • for i:=1 to length(chaine)-2 do begin
  • case cha[i] of
  • '1':ncoef[i]:=1;'2':ncoef[i]:=2;'3':ncoef[i]:=3;'4':ncoef[i]:=4;'5':ncoef[i]:=5;
  • '6':ncoef[i]:=6;'7':ncoef[i]:=7;'8':ncoef[i]:=8;'9':ncoef[i]:=9;'0':ncoef[i]:=0;
  • end;
  • end;
  • res:=0;
  • j:=0;
  • for l:=point-2 downto 1 do begin
  • res:= res + ncoef[l] * pow(10,j);
  • j:=j+1;
  • end;
  • j:=1;
  • for l:=point-1 to length(chaine)-2 do begin
  • res:= res + ncoef[l] * pow(10,-j);
  • j:=j+1;
  • end;
  • case chaine[1] of
  • '+':res:=+1*res;
  • '-':res:=-1*res;
  • end;
  • cach:=res;
  • end;
  • (*procedure qui affiche la formule *)
  • procedure tri(st:string);
  • var l,di:integer;
  • mot,mots,chifre:string;
  • begin
  • op1:=['0','1','2','3','4','5','6','7','8','9'];
  • ln:=1;op:=['+','-','='];
  • st:=st+'='+'0';
  • if st[1] in op then else
  • st:='+'+st;
  • for l:=1 to length(st) do begin
  • if l=1 then mot :=st[l]
  • else mot:=mot+st[l];
  • if (st[l]in op) and (st[l+1]='x')then
  • mot:=mot+'1';
  • if (st[l+1]in op) and (st[l]='x')then
  • mot:=mot+'1';
  • end;
  • mots:=mot[1];
  • for l:=2 to length(mot)-2 do mots:=mots+mot[l];
  • st:=mot;writeln('l"‚quation est: [ ', mots,'=0 ]');
  • l:=1;
  • while st[l] <> '=' do
  • begin
  • chifre:=st[l];
  • while (st[l+1]<>'x')and(st[l+1]<>'=') do
  • begin
  • l:=l+1;
  • chifre:=chifre+st[l];
  • end;
  • coef[ln]:=cach(chifre);ln:=ln+1;
  • case st[l+1] of
  • '=':l:=l+1;
  • 'x':begin
  • pui[ln-1]:=chifi(st[l+2]);
  • l:=l+3;
  • end;
  • end;
  • end;
  • end;
  • (*foction qui calcule f(x)*)
  • function f(r:real):real;
  • begin
  • c:=0;
  • case gen of
  • 4:for l:=1 to ln-1 do c:= c + coef[l] * pow(r,(pui[l]));
  • end;
  • f := c;
  • end;
  • {*fonction qui calcule la 1er deriv‚*}
  • function df(var x:real):real;
  • begin
  • c:=0;
  • case gen of
  • 4:for l:=1 to ln-2 do c:=c+pui[l] * coef[l] * pow(x,(pui[l]-1));
  • end;
  • df:=c;
  • end;
  • {*fonction qui calcule la 2eme deriv‚*}
  • function df2(var x:real):real;
  • begin
  • c:=0;
  • case gen of
  • 4:for l:=1 to ln-3 do c:=c+pui[l]*(pui[l]-1)*coef[l]*pow(x,(pui[l]-2));
  • end;
  • df2:=c;
  • end;
  • {*programme principale*}
  • begin
  • rep:='n'; b1:=2;
  • while rep<>'o' do
  • begin
  • writeln('PROGRAMME DE LA SOLUTION D"UNE FONCTION NON LINEAIRE PAR LA METHODE DE NEWTON');writeln(' ');
  • writeln('* * * * * * * * * PRESENTE PAR BACHIR ET SAMIA * * * * * * * ');writeln;
  • if b1<>2 then readln;
  • writeln(' POUR CALCULER LA RACINE DE LA FONCTION: ');writeln('');
  • write(' donner f[x]=');readln(ch);
  • case ch[1] of
  • '1'..'9','+','-','x':begin gen:=4; tri(ch); end;
  • end;
  • begin
  • readln;
  • write('donner la valeur a=');readln(a);
  • write('donner la valeur b=');readln(b);
  • write('donner l"erreur ep=');readln(ep);writeln(''); k:=0;
  • if f(a)=0 then begin writeln(' SOLUTION x=',a);
  • writeln(' f[',a,']=',f(a));
  • writeln('ET LE NOMBRE D"ETERATION EST i=0');
  • end
  • else if f(b)=0 then begin writeln(' SOLUTION x=',b);
  • writeln(' f[',b,']=',f(b));
  • writeln('ET NOMBRE D"ETERATION EST i=0');
  • end
  • else
  • if f(a)*f(b)>0 then begin
  • writeln(' ***************REMARQUE*************** ');
  • writeln('ERREUR!!! LA FONCTION NE ADMET AUCUN ZERO...');end
  • else begin
  • if f(a)*df2(a)>0 then x0:=a
  • else x0:=b;
  • if f(x0)=0 then begin r:=x0;
  • writeln(' SOLUTION x=',r);
  • writeln(' f[',r,']=',f(r));
  • writeln(' ET LE NOMBRE D"ITERATION EST i=',k); end
  • else begin
  • if df(x0)=0 then begin
  • writeln(' ***************REMARQUE*************** ');
  • writeln('ERREUR!!! la derive est NULLE df(x)=0...');end
  • else begin repeat
  • d:=-f(x0)/df(x0);
  • x0:=x0+d;
  • k:=k+1;
  • until abs(d)<abs(ep*x0);
  • r:=x0;
  • writeln(' ');
  • writeln(' SOLUTION x=',r);
  • writeln(' ');
  • writeln(' f[',r,']=',f(r) );
  • writeln(' ');
  • writeln(' ET ');
  • writeln(' ');
  • writeln(' LE NOMBRE D"ITERATUION EST N=',k);
  • writeln(' '); end;end;end;
  • write('voulez vous quiter O/N?'); read(rep);
  • writeln(' ');
  • writeln(' ');
  • writeln(' ');
  • writeln(' ');
  • end;end;
  • end.
program newton;
type
vect1 = array [1..15] of real;
vect2 = array [1..15] of char;
vect3 = array [1..15] of integer;
var
coef,ncoef :vect1;
cha:vect2;bol:boolean;
pui:vect3;
b1,n,i,deg,l,nbr,ln,gen,k:integer;
s,p,c,x,y,z,r,d,ep,fd,x0,a,b :real;
co,rep:char;op,op1: set of char;
ch:string;
ca:char;
(*fonction de la puissance*)
function pow(x:real;n:integer):real;
 begin
    p:=1;

      for i := 1 to abs(n) do begin
                            if n < 0 then p:=p/10
                                   else p:=p*x;
                              end;
    pow:=p;
 end;
(****************)
function chifi(chifr:char):integer;
 begin
   case chifr of
   '1':chifi:=1;'2':chifi:=2;'3':chifi:=3;'4':chifi:=4;'5':chifi:=5;
   '6':chifi:=6;'7':chifi:=7;'8':chifi:=8;'9':chifi:=9;'0':chifi:=0;
  end;
 end;
(*fonction qui lit la chaine de caractŠre*)
function cach(chaine:string):real;
var  res:real;
    point,j:integer;
 begin
  b1:=0;
  for i:=1 to length(chaine) do if chaine[i]='.'then b1:=1;
   if b1 = 0 then chaine:=chaine+'.';
    if (chaine[1]<>'+') and (chaine[1]<>'-')then chaine:='+'+chaine;
  point:=length(chaine)+1;
  j:=1;
    for i:=2 to length(chaine) do begin
             if chaine[i]='.'then point:=i
                             else begin cha[j]:=chaine[i];j:=j+1;end;
                                  end;
    for i:=1 to length(chaine)-2 do begin
     case cha[i] of
      '1':ncoef[i]:=1;'2':ncoef[i]:=2;'3':ncoef[i]:=3;'4':ncoef[i]:=4;'5':ncoef[i]:=5;
      '6':ncoef[i]:=6;'7':ncoef[i]:=7;'8':ncoef[i]:=8;'9':ncoef[i]:=9;'0':ncoef[i]:=0;
     end;
    end;
 res:=0;
 j:=0;
  for l:=point-2 downto 1 do begin
                            res:= res + ncoef[l] * pow(10,j);
                            j:=j+1;
                             end;
 j:=1;
  for l:=point-1 to length(chaine)-2 do begin
                                  res:= res + ncoef[l] * pow(10,-j);
                                  j:=j+1;
                                         end;
   case chaine[1] of
    '+':res:=+1*res;
    '-':res:=-1*res;
   end;
  cach:=res;
 end;
(*procedure qui affiche la formule *)
procedure tri(st:string);
var l,di:integer;
    mot,mots,chifre:string;
 begin
  op1:=['0','1','2','3','4','5','6','7','8','9'];
  ln:=1;op:=['+','-','='];
  st:=st+'='+'0';
     if st[1] in op then else
       st:='+'+st;
         for l:=1 to length(st) do begin
             if l=1 then mot :=st[l]
                    else mot:=mot+st[l];
             if (st[l]in op) and (st[l+1]='x')then
              mot:=mot+'1';
               if (st[l+1]in op) and (st[l]='x')then
                 mot:=mot+'1';
                                    end;
   mots:=mot[1];
   for l:=2 to length(mot)-2 do mots:=mots+mot[l];
   st:=mot;writeln('l"‚quation est:   [ ', mots,'=0 ]');
    l:=1;
     while st[l] <> '=' do
      begin
       chifre:=st[l];
        while (st[l+1]<>'x')and(st[l+1]<>'=') do
        begin
          l:=l+1;
          chifre:=chifre+st[l];
        end;
      coef[ln]:=cach(chifre);ln:=ln+1;
      case st[l+1] of
        '=':l:=l+1;
        'x':begin
            pui[ln-1]:=chifi(st[l+2]);
            l:=l+3;
           end;
      end;
    end;
end;
(*foction qui calcule f(x)*)
function f(r:real):real;
 begin
   c:=0;
    case gen of
         4:for l:=1 to ln-1 do c:= c + coef[l] * pow(r,(pui[l]));
    end;
   f := c;
 end;
{*fonction qui calcule la 1er deriv‚*}
function df(var x:real):real;
 begin
  c:=0;
    case gen of
         4:for l:=1 to ln-2  do c:=c+pui[l] * coef[l] * pow(x,(pui[l]-1));
    end;
   df:=c;
 end;
 {*fonction qui calcule la 2eme deriv‚*}
function df2(var x:real):real;
 begin
   c:=0;
    case gen of
         4:for l:=1 to ln-3 do c:=c+pui[l]*(pui[l]-1)*coef[l]*pow(x,(pui[l]-2));
    end;
  df2:=c;
 end;
{*programme principale*}
begin
 rep:='n'; b1:=2;
 while rep<>'o' do
  begin
  writeln('PROGRAMME DE LA SOLUTION D"UNE FONCTION NON LINEAIRE PAR LA METHODE DE NEWTON');writeln('       ');
  writeln('* * * * * * * * * PRESENTE PAR BACHIR ET SAMIA * * * * * * * ');writeln;
  if b1<>2 then readln;
  writeln('        POUR CALCULER LA RACINE DE LA FONCTION: ');writeln('');
  write('        donner f[x]=');readln(ch);
   case ch[1] of
        '1'..'9','+','-','x':begin gen:=4; tri(ch); end;
   end;
   begin
      readln;
      write('donner la valeur a=');readln(a);
      write('donner la valeur b=');readln(b);
      write('donner l"erreur ep=');readln(ep);writeln(''); k:=0;
      if f(a)=0 then begin writeln(' SOLUTION x=',a);
                     writeln('  f[',a,']=',f(a));
                     writeln('ET LE NOMBRE D"ETERATION EST i=0');
                     end
                else if f(b)=0 then begin writeln(' SOLUTION x=',b);
                                    writeln('  f[',b,']=',f(b));
                                    writeln('ET NOMBRE D"ETERATION EST i=0');
                                    end
                               else
                                if f(a)*f(b)>0 then begin
                                writeln('      ***************REMARQUE***************        ');
                                writeln('ERREUR!!! LA FONCTION NE ADMET AUCUN ZERO...');end
                                               else  begin
                                                 if f(a)*df2(a)>0 then x0:=a
                                                                  else x0:=b;
                           if f(x0)=0 then begin r:=x0;
                           writeln('     SOLUTION x=',r);
                           writeln('  f[',r,']=',f(r));
                           writeln(' ET LE NOMBRE D"ITERATION EST i=',k); end
                                     else begin
                           if df(x0)=0 then begin
                           writeln('      ***************REMARQUE***************        ');
                           writeln('ERREUR!!! la derive est NULLE df(x)=0...');end
                                       else begin repeat
                                                  d:=-f(x0)/df(x0);
                                                  x0:=x0+d;
                                                  k:=k+1;
                                                 until abs(d)<abs(ep*x0);
                                       r:=x0;
    writeln('                                          ');
    writeln('                 SOLUTION x=',r);
    writeln('                                          ');
    writeln('             f[',r,']=',f(r) );
    writeln('                                          ');
    writeln('                          ET                  ');
    writeln('                                         ');
    writeln('                  LE NOMBRE D"ITERATUION EST N=',k);
    writeln('                                          '); end;end;end;
    write('voulez vous quiter O/N?'); read(rep);
    writeln('                                         ');
    writeln('                                          ');
    writeln('                                          ');
    writeln('                                 ');
end;end;
end.

Commentaires et avis

Aucun commentaire pour le moment.

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

Exécution d'une méthode incluse dans un package PL/SQL [ par DeadSoul ] Bonjour,Voici mon problème :Je désire exécuter une méthode PL/SQL incluse dans un package OracleJe connais l'existence de la classe TStoredProcedure, Affichage écran de demarrage [ par lirva ] Bonjour,J'ai suivi la méthode de l'aide pour afficher une Form pendant 3 secondes au démarrage de mon appli :&lt;&lt;procedure TForm1.FormActivate(Sen Appel d'une Form [ par apz ] salut, pour appeler une form, certains utilisent la méthode suivante : ------------------------------------------------------------Form1.Show--------- Choisir la piste d'un cd audio [ par alexistoulotte ] Est-ce que qqn connait une méthode pour aller directement a la piste d'un cd audio que l'utilisateur a choisi (par un edit par exemple).Merci d'avance Libération de ressources [ par nicolaspennaneach ] j'ai une application MDI où chaque fenètre enfant possède un thread pour effectuer certaines opérations. Lorsque j'exécute la méthode formclose d'une pointeur de méthode dans une dll ... [ par silmortes ] Slt !!!!J'ai un soucis j'ai un objet TIBDatabase que je créé dynamiquement dans ma dll : Database := TIBDatabase.Create(NIL); Da Donner une direction à un objet (bitmap ou autre) [ par Yml ] Bonjour,J'aimerai développer un casse brique et pour cela, il me faudrait une méthode pour que la balle puisse se diriger dans toutes les directions.P Méthode AddIndex [ par margout ] MargoutBonjour à tous,J'ai utilisé la methode AddIndex avec une TTable pour ajouter un index secondaire sur un champsTable1.AddIndex ('Indexdate', 'da Code Delphi de méthodes de planification [ par abidcha ] Bonjour,J'aimerai savoir si quelqu'un à le code Delphi des méthodes de planification de la production suivantes:- Méthode MRP - Méthode JIT (Just In T programme de l'integrale par la méthode de Riemann [ par zerrouk.ilyasse ] je cherche le programme qui calcule l'integrale par la méthode de Riemann ....si il y a une réponce favorable contactez moi a mon e-mail :poutchi113@c


Nos sponsors

Sondage...

CalendriCode

Septembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
2930     

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,33 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.