Installer et compiler ces fichiers dans votre répertoire de travail.
![]() |
c3f.c ' |
---|
/* --------------------------------- */
/* save as c3f.c */
/* --------------------------------- */
#include "x_hfile.h"
#include "ff.h"
/* --------------------------------- */
int main(void)
{
int n = 6;
double FirstApproximation = -0.8;
clrscrn();
printf(" Use Newton's method to approximate \n"
" the intersection point of :\n\n"
" g : x-> %s and\n"
" h : x-> %s\n\n\n"
" On a graph, you can see that, the intersection \n"
" point is between -1.0 and 0.0.\n\n"
" Choose x = %.1f as a first approximation.\n\n"
, geq, heq, FirstApproximation);
stop();
clrscrn();
printf(" In fact we want find x**2 = cos(x) or x**2 - cos(x) = 0\n\n"
" We want find the root of\n\n"
" f : x-> %s\n\n", feq);
printf(" As a first approximation x = %.1f \n\n",FirstApproximation);
printf(" The Newton's method give : \n\n");
p_Newton_s_Method(FirstApproximation, n, f, Df);
Newton_s_Method(FirstApproximation, n, f, Df);
printf(" f(%.15f) = %.15f\n\n",
Newton_s_Method(FirstApproximation, n, f, Df)
,f(Newton_s_Method(FirstApproximation, n, f, Df)));
stop();
return 0;
}
Vous pouvez choisir votre logiciel de traçage de courbes pour pouvoir repérer les racines et ensuite faire juste un encadrement comme précédemment.
Exemple de sortie écran :
Use Newton's method to approximate
the intersection point of :
g : x-> x**2 and
h : x-> cos(x)
On a graph, you can see that, the intersection
point is between -1.0 and 0.0.
Choose x = -0.8 as a first approximation.
Press return to continue.
Exemple de sortie écran :
In fact we want find x**2 = cos(x) or x**2 - cos(x) = 0
We want find the root of
f : x-> x**2- cos(x)
As a first approximation x = -0.8
The Newton's method give :
x[1] = -0.800000000000000
x[2] = -0.824470434030341
x[3] = -0.824132376563292
x[4] = -0.824132312302525
x[5] = -0.824132312302522
x[6] = -0.824132312302522
f(-0.824132312302522) = -0.000000000000000
Press return to continue.
Cet article est issu de Wikibooks. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.