Operator AJUSTE
                                             DATE     99/08/17
                                               date    21/03/95

    procédure AJUSTE
    ----------------

    Q P = AJUSTE  TAB1  TAB2; 
 
                           TAB1.'X'     TAB2.'PMIN'
                           TAB1.'F'     TAB2.'PMAX'
                           TAB1.'K'     TAB2.'PRECISION' (facultatif)    
                           TAB1.'L'     TAB2.'MXTER'     (facultatif)
                                        TAB2.'POIDS'     (facultatif)
                           TAB1.'IMPRESSION' (facultatif)          



     Description :
     -------------
   
     Let F(x,y,z,..,p1,..pk) a function explicited as follows :
     form

       F(x,p)=q1*f1(x,y,z,.,p1,..,pk) + q2*f2(x,y,z,.,p1,..,pk) +
                q3*f3(x,y,z,.,p1,..,pk) +..
                  ..+ ql*fl(x,y,z,.,p1,..,pk) + g(x,y,z,.,p1,..,pk)


     qi (i=1,l) are linear parameters
     pj (j=1,k) are non linear parameters

     The procedure adjustes these different parameters so that the
     function is best represented in a series of ( n couples)
     ( (x,y,z,...);Fdi (x,y,z,..) ) sets defined by the user.
     In fact, the function G is to be minimized.
         G =[ ((poids(i)*(F(x,p)-Fdi(x,y,z..)))**2 ]
             summation with i=1,n


     Data :
     ------
       TAB1.'X':TABLE indexed by integers i=1,n who contains the 
                LISTREEL(s) x,y,z,.....
       TAB1.'F':LISTREEL of the values of F(x,y,z...).
       TAB1.'K':ENTIER(integer), number of non linear parameters.  
       TAB1.'L':ENTIER(integer), number of linear parameters.
   
       TAB2.'PMIN' :LISTREEL of the minimum values of p.
       TAB2.'PMAX' :LISTREEL of the maximum values of p.
       
       An optional integer : TAB1.'IMPRESSION' give the frequence of
       printing(if not used the value is 20).
       An optional listreel : TAB2.'PRECISION' can be created, it's
       the precision of convergence criterium for the k non linear
       parameters (if not used the precision is 1.e-7).     
      
       An optional integer TAB2.'MXTER' can be created, it's the
       maximum number of iterations (default : 100).
       
       TAB2.'PMAX' :LISTREEL of the values of poidsto be given 
                    for each given values of Fdi. ( Default : each  
                    points has the same poids)
   
    Output :
    --------
      Q and P are objects LISTREEL which contains values of
      parameters  qi and pi.

  
    Use :
    -----
       Before using this AJUSTE procedure, the user must create 
       two procedures :

       - procedure FCT : 
         It's goal is to calculate the function to
         adjust knowing the values of the abscissas x,y,z,.. and 
         that for a given set of parameters p. In fact, the procedure
         is asked to calculate the functions f1,f2,..,fl and the
         function g.
         For each function fi, the procedure calculate s as many
         values as there are in x,y,z,.. The results must be
         presented as a TABLE object.
         As entry argument, FCT will receive the TABLE object
         which is in TAB2.'X', as well as the set of values of p 
         presented in a LISTREEL object. 
         As output the TABLE object must be presented in the 
         following way : 

                    tbfonc.'F'. i  =  listréel of the fi values
          
                    tbfonc.'G'     =  listréel the g value       

         The linear parameters qi dont have to be written down.


       - procedure DERI :
         It builds a TABLEZ object containing a list of LISTREEL
         objects which are the values of functions f1,f2,..,fl and
         g derivated following the nonlinear parameters pjfor each 
         values of x,y,z... and of p.

         As input, DERI will receive the TABLE object in TAB2.'X',
         as well as the LISTREEL containing p.

         As output, the TABLE object must be presented as follows :

                 tbderi.'F'. j . i = LISTREEL of the values of dfi/dpj
           
                 tbderi.'G'. j     = LISTREEL of the values of dg/dpj


    Remarks :
    ---------

     - The abscissas being in a LISTREEL, the constants must be
       expressed as a LISTREEL for algebraic operations. 

         ex: f1(x)=x+1  will be  f1(x)=x+(prog n*1);               
             n being the dimension of x.

     - If the g function doesn't exist it is still necessary to 
       introduce null values in the procedures FCT and DERI.

         ex : g(x) = prog n*0. ;   ( n : dimension of x)

     - If sinusoidal functions are used be aware that CASTEM2000
       operators use degrees.

*  EXEMPLE : 
*     On cherche a interpoler un nuage de points avec la fonction
*      suivante:
*     the given sets of points ( x , f(x)) must be adjusted with
*     a function as follows :
* 
*       f(x) =( A * (x**B ))+ (C * sin(D*x + B)) + (E * x)
*
*   les deux parametres p1 et p2 non linéaires sont B et D. 
*   The two non linear parameters p1 and p2 are B and D.
*
*   les autres A,C,E  sont linéaires.On peut donc mettre la 
*   fonction sous la forme :
*   A,C,E are linear parameters. It is possible to write the function
*   in the following way :
*    f(x)= A*f1(x) +C*f2(x)+E*f3(x)
*
*     PROCEDURES:  FCT   
*      
     debproc fct  xtab*table  p*listreel;
            tab1=table; tab2=table; x = xtab . 1;
            n=dime x;
* fonction f1
             tab1 . 1=x**(extr p 1);
* fonction f2
             aa=(((extr p 2)*x) + (prog n*(extr p 1)))*180. / PI;
             tab1 . 2=sin(aa );
* fonction f3
             tab1 . 3 = x;
*remplissage de la table résultat
* filling of the result  table
             tab2.'F'=tab1;
* fonction g
             tab2.'G'=prog n*0;
            finproc tab2;

*     PROCEDURES:  DERI       
      debproc deri  xtab*table  p*listreel;

            tab1=table;tab2=table; tabg=table;tabf=table;tab=table;
            x = xtab . 1; n=dime x;
* fonction  df1/dp1
             tab1 . 1=(log x)*(x**(extr p 1));
* fonction df2/dp1
             aa = (((extr p 2)*x) + (prog n*(extr p 1)))*180. / PI;
             tab1 . 2=cos ( aa);
* fonction df3/dp1
             tab1 . 3=prog n*0;

* fonction df1/dp2
             tab2 . 1=prog n*0; 
* fonction df2/dp2     
             tab2 . 2 = x * ( cos (aa));
* fonction df3/dp2
             tab2 . 3=prog n*0;

* fonction dg/dp1
             tabg . 1=prog n*0;
* fonction dg/dp2
             tabg . 2=prog n*0;

   tabf . 1=tab1; tabf . 2=tab2; tab.'F'=tabf;tab.'G'=tabg;         
   finproc tab;
*     ***** Exemple éxécution   
* definition de la fonction pour le calcul des couples x,F(x) 
            x=prog  0.01 pas 0.01 1.;
*  posons A = 1 ; B=0.5 ; C=1; D=1; E=3.14159...(pi)  
   af1 = x ** 0.5;
   aa = (X + ( prog 100*0.5))* 180.  / PI;cf2 = sin aa;            
   ef3 = pi * x;y = af1 + cf2 + ef3;

            k=2; l=3; xtab = table; xtab . 1 = x;
            tab1=table; tab2=table;
            tab1.'X'=xtab;     tab1.'F'=y;
            tab1.'K'=k;        tab1.'L'=l;  
            tab2.'PMIN'=prog k*0;
            tab2.'PMAX'=prog k*10;
            tab2.'POIDS' = prog 0.75 pas 0.01 1.74;
            q p=ajuste tab1 tab2;

* recalcul de F(x) pour comparaison avec courbe initiale
* computation of f(x) for comparison with initial curve       
  n=dime x;B = extraire p 1;D = extraire p 2;
  A = extraire q 1;C = extraire q 2;E = extraire q 3;
  f1=  A * ( x **B);aa = ((D*x) + (prog n*B))*180. / PI;
  f2 = C * ( sin (aa));f3 = E * x;y1 = f1 + f2 + f3;
  ev = evol roug manu 'X' x 'Y' y ;
  ev1 = evol bleu manu  'X' x 'Y1' y1;     
  evt = ev et ev1;dess evt;