//Exercice 2-5: calcul des fonctions d'Airy 
// par le développement en série

C1 = 0.3550281; C2 = 0.2588194; RAC3 = sqrt(3); tol = 1E-6;
NMAX = 100; x0 = -13; pas = 0.1; xmax = 2;
x = x0; j = 1;
while (x <= xmax)
    xx(j) = x;
    it = 0;
    f = 1; g = x;
    terme_f = 1; terme_g = x;
    while ( (abs(terme_f) > tol) & (abs(terme_g) > tol)..
                                 & (it < NMAX))
        i3 = 3*it;
        terme_f = terme_f*x*x*x/((i3 + 2)*(i3 + 3));
        terme_g = terme_g*x*x*x/((i3 + 3)*(i3 + 4));
        f = f + terme_f; g = g + terme_g; 
        it = it + 1;
    end
    Ai(j) = C1*f - C2*g; Bi(j) = RAC3*(C1*f + C2*g);
    x = x + pas; j = j + 1;
end
plot2d(xx,[Ai,Bi],style = [1,2]);
xtitle("fonctions d''Airy")
    
