Mathc initiation/Fichiers h : c24a5
Installer ce fichier dans votre répertoire de travail.
![]() |
x_nwtn.h utilitaire |
---|
/* ---------------------------------- */
/* save as x_nwtn.h */
/* --------------------------------- */
pt2d newton_fxy(
int n,
double (*P_f)(double x, double y),
double (*P_g)(double x, double y),
double h,
pt2d p
)
{
int k;
double delta;
pt2d delta_p;
for(k=1; k<n; k++)
{
delta = fxy_x((*P_f),h,p) * fxy_y((*P_g),h,p)
-
fxy_x((*P_g),h,p) * fxy_y((*P_f),h,p);
delta_p.x = ( (-(*P_f)(p.x,p.y)) * fxy_y((*P_g),h,p)
-
(-(*P_g)(p.x,p.y)) * fxy_y((*P_f),h,p) )
/
delta;
delta_p.y = ( fxy_x((*P_f),h,p) * (-(*P_g)(p.x,p.y))
-
fxy_x((*P_g),h,p) * (-(*P_f)(p.x,p.y)) )
/
delta;
p.x += delta_p.x;
p.y += delta_p.y;
}
return(p);
}
/* --------------------------------- */
/* --------------------------------- */
pt2d p_newton_fxy(
int n,
double (*P_f)(double x, double y),
double (*P_g)(double x, double y),
double h,
pt2d p
)
{
int k;
double delta;
pt2d delta_p;
for(k=1; k<n; k++)
{
printf(" n = %d \n",k);
printf(" f(%f,%f) = %+f \n",p.x,p.y,((*P_f)(p.x,p.y)) );
printf(" g(%f,%f) = %+f\n\n",p.x,p.y,((*P_g)(p.x,p.y)) );
delta = fxy_x((*P_f),h,p) * fxy_y((*P_g),h,p)
-
fxy_x((*P_g),h,p) * fxy_y((*P_f),h,p);
delta_p.x = ( (-(*P_f)(p.x,p.y)) * fxy_y((*P_g),h,p)
-
(-(*P_g)(p.x,p.y)) * fxy_y((*P_f),h,p) )
/
delta;
delta_p.y = ( fxy_x((*P_f),h,p) * (-(*P_g)(p.x,p.y))
-
fxy_x((*P_g),h,p) * (-(*P_f)(p.x,p.y)) )
/
delta;
p.x += delta_p.x;
p.y += delta_p.y;
}
printf(" n = %d \n",k);
printf(" f(%f,%f) = %+f \n",p.x,p.y,((*P_f)(p.x,p.y)) );
printf(" g(%f,%f) = %+f\n\n",p.x,p.y,((*P_g)(p.x,p.y)) );
return(p);
}
/* --------------------------------- */
L'algorithme est simple : On a ce système d'équation, on utilise la méthode de cramer pour le résoudre :
|f_x f_y| x = -f |g_x g_y| y = -g
x0, y0 sont estimés par rapport à un graphe.
A chaque itérations on introduit la valeur xn qui vient d'être calculée
deter =|f_x(x0,y0) f_y(x0,y0)| |g_x(x0,y0) g_y(x0,y0)| x1 = |-f(x0,y0) f_y(x0,y0)| | | /deter |-g(x0,y0) g_y(x0,y0)| y1 = |f_x(x0,y0) -f(x0,y0)| | | /deter |g_x(x0,y0) -g(x0,y0)| puis x1, y1 remplace x0, et y0 pour calculer x2