C_A=0;
C_B=0;
g_A=9.832186; % m.s-2
g_B=9.780327; % m.s-2

% denivellee
Dn_AC=500; % m

% gradient normal
dgdH=-3.086e-6; %s-2

printf('\n1. Calculer les cotes geopotentielles de A1 et B1 en SI et en UGP.\n\n')

% pesanteur au point A1
g_C=g_A + Dn_AC*dgdH;
printf("g_C = %12.8f m.s-2\n",g_C)

printf("cote geopotentielle en C\n")
C_C=C_A+ 0.5*(g_A+g_C)*Dn_AC;

printf("C_C = %12.3f m2.s-2\n",C_C)
printf("C_C = %12.3f UGP\n",C_C/10)

C_D=C_C;
printf("C_D = %12.3f m2.s-2\n",C_D)
printf("C_D = %12.3f UGP\n",C_D/10)

printf('\n2. Calculer la distance BD.\n\n')

printf('C_D-C_B=0.5*(g_B+g_D)*DN\n')
printf('or g_D=g_B + dgdH * DN\n')
printf('d''ou C_D-C_B = 0.5 * (g_B + g_B + dgdH * DN) * DN\n')
printf('dgdH * DN^2 + 2*g_B * DN - 2 * (C_D-C_B)= 0\n')
a=dgdH;
b=2*g_B;
c=-2*(C_D-C_B);

a=0.5*dgdH;
b=g_B;
c=-C_D;

printf('discriminant : \n')
delta=b^2 -4*a*c
printf('Racines :\n')
x1=(-b-sqrt(delta))/2/a
x2=(-b+sqrt(delta))/2/a

printf("\nDn_BD = %12.3f m\n",x2)