Delphi6
Fermé
dimson
Messages postés
11
Date d'inscription
vendredi 29 août 2003
Statut
Membre
Dernière intervention
25 octobre 2003
-
11 oct. 2003 à 22:48
hicham - 3 nov. 2003 à 12:34
hicham - 3 nov. 2003 à 12:34
3 réponses
Procedure TForm1.Button1Click(Sender: TObject); Var dx, dy, h, y, a, b, x : real ; i : byte; Begin a := 0.7; b := 0.8; h := 0.01; x := a; i := 0; Memo1.Clear; // partie 1 While x <= b Do Begin x := x + h / 2; // partie 2 dx := 0.1 * h; y := cos(x)-x*x*x-0.2; dy := (-sin(x)-(3*x*x))*dx; memo1.lines.add( 'x' + '['+inttostr(i)+']'+'='+' '+floattostr(x)+' '+'y'+'['+inttostr(i)+']'+'='+' ' +floattostr(y)+' '+'dx'+'='+floattostr(dx)+' '+'dy'+'['+inttostr(i)+']'+'='+' '+floattostr(dy)); inc(i); End; End;
les résultats :
x[0] = 0.705 y[0] = 0.211208926762062 dx=0.001 dy[0] = -0.00213910882953561 x[1] = 0.71 y[1] = 0.200450875990508 dx=0.001 dy[1] = -0.00216413377102154 x[2] = 0.715 y[2] = 0.189567366211553 dx=0.001 dy[2] = -0.00218929241669714 x[3] = 0.72 y[3] = 0.178557729140895 dx=0.001 dy[3] = -0.00221458467197147 x[4] = 0.725 y[4] = 0.167421296966165 dx=0.001 dy[4] = -0.00224001044266335 x[5] = 0.73 y[5] = 0.15615740234487 dx=0.001 dy[5] = -0.0022655696350037 x[6] = 0.735 y[6] = 0.144765378402328 dx=0.001 dy[6] = -0.0022912621556379 x[7] = 0.74 y[7] = 0.133244558729588 dx=0.001 dy[7] = -0.00231708791162815 x[8] = 0.745 y[8] = 0.121594277381341 dx=0.001 dy[8] = -0.00234304681045571 x[9] = 0.75 y[9] = 0.109813868873821 dx=0.001 dy[9] = -0.00236913876002333 x[10]= 0.755 y[10]= 0.0979026681826874 dx=0.001 dy[10]= -0.00239536366865746 x[11]= 0.76 y[11]= 0.0858600107409052 dx=0.001 dy[11]= -0.00242172144511055 x[12]= 0.765 y[12]= 0.0736852324366062 dx=0.001 dy[12]= -0.0024482119985634 x[13]= 0.77 y[13]= 0.0613776696109433 dx=0.001 dy[13]= -0.00247483523862736 x[14]= 0.775 y[14]= 0.0489366590559313 dx=0.001 dy[14]= -0.0025015910753466 x[15]= 0.78 y[15]= 0.0363615380122773 dx=0.001 dy[15]= -0.00252847941920041 x[16]= 0.785 y[16]= 0.0236516441671997 dx=0.001 dy[16]= -0.00255550018110537 x[17]= 0.79 y[17]= 0.010806315652236 dx=0.001 dy[17]= -0.00258265327241761 x[18]= 0.795 y[18]= -0.0021751089589604 dx=0.001 dy[18]= -0.00260993860493504 x[19]= 0.8 y[19]= -0.0152932906528347 dx=0.001 dy[19]= -0.00263735609089952 x[20]= 0.805 y[20]= -0.0285488899781559 dx=0.001 dy[20]= -0.0026649056429991
Commentaires :
1- éliminer la variable n car il n'est pas utilisée !!
2- la [ partie 1 ] permet de rafraichir le champ Memo
3- la [ partie 2 ] est celle qui contient l'erreur,
la valeur de x est constante car tu lui affecte une constante !,
par contre x doit être un cumulateur..
bonne chance..
[ Ton Doux Visage. ]
bjr dimson
remplace x:=a+h/2 par x:=x+h/2
et voici le resultat:
x[0]= 0,704999999999927 y[0]= 0,21120892676231 dx=0,00100000000000122 dy[0]= -0,00213910882953883
x[1]= 0,710000000000036 y[1]= 0,200450875990327 dx=0,00100000000000122 dy[1]= -0,00216413377102498
x[2]= 0,715000000000146 y[2]= 0,189567366211122 dx=0,00100000000000122 dy[2]= -0,00218929241670196
x[3]= 0,720000000000255 y[3]= 0,178557729140266 dx=0,00100000000000122 dy[3]= -0,00221458467197522
x[4]= 0,725000000000364 y[4]= 0,167421296965358 dx=0,00100000000000122 dy[4]= -0,00224001044266942
x[5]= 0,730000000000473 y[5]= 0,156157402343752 dx=0,00100000000000122 dy[5]= -0,00226556963500713
x[6]= 0,735000000000582 y[6]= 0,144765378400962 dx=0,00100000000000122 dy[6]= -0,00229126215564435
x[7]= 0,740000000000691 y[7]= 0,133244558727938 dx=0,00100000000000122 dy[7]= -0,00231708791163499
x[8]= 0,7450000000008 y[8]= 0,121594277379472 dx=0,00100000000000122 dy[8]= -0,00234304681046282
x[9]= 0,750000000000909 y[9]= 0,109813868871697 dx=0,00100000000000122 dy[9]= -0,00236913876003086
x[10]= 0,755000000001019 y[10]= 0,0979026681802679 dx=0,00100000000000122 dy[10]= -0,00239536366866488
x[11]= 0,760000000001128 y[11]= 0,0858600107382017 dx=0,00100000000000122 dy[11]= -0,00242172144512054
x[12]= 0,765000000001237 y[12]= 0,0736852324336041 dx=0,00100000000000122 dy[12]= -0,0024482119985727
x[13]= 0,770000000001346 y[13]= 0,0613776696076229 dx=0,00100000000000122 dy[13]= -0,00247483523863679
x[14]= 0,775000000001455 y[14]= 0,0489366590522877 dx=0,00100000000000122 dy[14]= -0,00250159107535808
x[15]= 0,780000000001564 y[15]= 0,0363615380083502 dx=0,00100000000000122 dy[15]= -0,00252847941921175
x[16]= 0,785000000001673 y[16]= 0,0236516441629249 dx=0,00100000000000122 dy[16]= -0,00255550018111705
x[17]= 0,790000000001783 y[17]= 0,0108063156476277 dx=0,00100000000000122 dy[17]= -0,00258265327243024
x[18]= 0,795000000001892 y[18]= -0,00217510896389683 dx=0,00100000000000122 dy[18]= -0,00260993860494807
x[19]= 0,800000000002001 y[19]= -0,0152932906581071 dx=0,00100000000000122 dy[19]= -0,00263735609091498
porte toi bien et a+
remplace x:=a+h/2 par x:=x+h/2
et voici le resultat:
x[0]= 0,704999999999927 y[0]= 0,21120892676231 dx=0,00100000000000122 dy[0]= -0,00213910882953883
x[1]= 0,710000000000036 y[1]= 0,200450875990327 dx=0,00100000000000122 dy[1]= -0,00216413377102498
x[2]= 0,715000000000146 y[2]= 0,189567366211122 dx=0,00100000000000122 dy[2]= -0,00218929241670196
x[3]= 0,720000000000255 y[3]= 0,178557729140266 dx=0,00100000000000122 dy[3]= -0,00221458467197522
x[4]= 0,725000000000364 y[4]= 0,167421296965358 dx=0,00100000000000122 dy[4]= -0,00224001044266942
x[5]= 0,730000000000473 y[5]= 0,156157402343752 dx=0,00100000000000122 dy[5]= -0,00226556963500713
x[6]= 0,735000000000582 y[6]= 0,144765378400962 dx=0,00100000000000122 dy[6]= -0,00229126215564435
x[7]= 0,740000000000691 y[7]= 0,133244558727938 dx=0,00100000000000122 dy[7]= -0,00231708791163499
x[8]= 0,7450000000008 y[8]= 0,121594277379472 dx=0,00100000000000122 dy[8]= -0,00234304681046282
x[9]= 0,750000000000909 y[9]= 0,109813868871697 dx=0,00100000000000122 dy[9]= -0,00236913876003086
x[10]= 0,755000000001019 y[10]= 0,0979026681802679 dx=0,00100000000000122 dy[10]= -0,00239536366866488
x[11]= 0,760000000001128 y[11]= 0,0858600107382017 dx=0,00100000000000122 dy[11]= -0,00242172144512054
x[12]= 0,765000000001237 y[12]= 0,0736852324336041 dx=0,00100000000000122 dy[12]= -0,0024482119985727
x[13]= 0,770000000001346 y[13]= 0,0613776696076229 dx=0,00100000000000122 dy[13]= -0,00247483523863679
x[14]= 0,775000000001455 y[14]= 0,0489366590522877 dx=0,00100000000000122 dy[14]= -0,00250159107535808
x[15]= 0,780000000001564 y[15]= 0,0363615380083502 dx=0,00100000000000122 dy[15]= -0,00252847941921175
x[16]= 0,785000000001673 y[16]= 0,0236516441629249 dx=0,00100000000000122 dy[16]= -0,00255550018111705
x[17]= 0,790000000001783 y[17]= 0,0108063156476277 dx=0,00100000000000122 dy[17]= -0,00258265327243024
x[18]= 0,795000000001892 y[18]= -0,00217510896389683 dx=0,00100000000000122 dy[18]= -0,00260993860494807
x[19]= 0,800000000002001 y[19]= -0,0152932906581071 dx=0,00100000000000122 dy[19]= -0,00263735609091498
porte toi bien et a+