Accueil > > > METHODE DE NEWTON
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.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
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 :<<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
|
Derniers Blogs
[TECHDAYS2012] OUI J'Y SERAI![TECHDAYS2012] OUI J'Y SERAI! par JeremyJeanson
Bonsoir, Certes, je l'annonce avec un peu de retard, mais je serai effectivement au Techdays demain. Comme l'an dernier, je participerai au programme ATE (Ask The Expert). Si vous avez des questions Workflow, WCF, AppFabric ou plus généralement .net, n'hé...
Cliquez pour lire la suite de l'article par JeremyJeanson TFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICESTFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICES par vfabing
Afin de s'assurer du bon fonctionnement des différentes synchronisations effectuées par les TFS Integration Tools, 2 rapports sont présents dès l'installation. Il suffit alors d'effectuer les manipulations suivantes pour pouvoir les visualiser : Loca...
Cliquez pour lire la suite de l'article par vfabing CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|