* fichier : mma_06.dgibi ************************************************************************ * Section : Mathematiques Fonctions ************************************************************************ ************************************************************************ * Test de la procedure MOCA_MMA et de l'operateur MMA * * Application au fit d'une fonction afin de * * passer au mieux par une serie de points * * * * On cherche a optimiser les parametres w=(a,b,c,d) de la fonction : * * h(x,w) = a * (log ((b*x) + c)) + (exp (d*x)) * * passant au mieux par une serie de P points (Xi ; Hi) connus * * * ************************************************************************ * Options OPTI 'ECHO' 0 ; itrac = FAUX ; * Procedure pour calculer la fonction h(w,X) ainsi que les * derivees partielles de h selon chaque composante de w (en option) DEBP H x*'LISTREEL' w*'LISTREEL' mot1/'MOT' ; ideri = VRAI ; a = EXTR w 1 ; b = EXTR w 2 ; c = EXTR w 3 ; d = EXTR w 4 ; h0 = (a * (LOG ((b * x) + c))) + (EXP (d * x)) ; SI (EGA (TYPE mot1) 'MOT') ; SI (EGA mot1 'VISU') ; ideri = FAUX ; FINSI ; FINSI ; SI ideri ; dval = ENUM ; REPE b1 (DIME x) ; x1 = EXTR x &b1 ; dhdw = PROG (LOG ((b * x1) + c)) ((a * x1) / ((b * x1) + c)) (a / ((b * x1) + c)) (x1 * (EXP (d * x1))) ; dval = dval ET dhdw ; FIN b1 ; RESP h0 dval ; SINON ; RESP h0 ; FINSI ; FINP ; * Choix des points connus (Xi,Hi) * ici on prend des points definits exactement par la fonction h * avec comme parametres wref wref = PROG 3. 2. 1. 0.1 ; xmes = PROG 0.2 'PAS' 0.1 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. ; hmes = H xmes wref 'VISU' ; * Valeurs initiales w0 w0 = PROG 0.1 0.1 0.1 0.1 ; * Optimisation SI itrac ; xplot = PROG 0.01 'PAS' 0.01 14. ; w mse lw = MOCA_MMA 'X0' w0 'ABSC' xmes 'ORDO' hmes 'PROC' (MOT 'H') 'XMIN' (PROG 4*0.001) 'XMAX' (PROG 4*10.) 'ECHO' 2 'VISU' xplot ; SINON ; w mse lw = MOCA_MMA 'X0' w0 'ABSC' xmes 'ORDO' hmes 'PROC' (MOT 'H') 'XMIN' (PROG 4*0.001) 'XMAX' (PROG 4*10.) 'ECHO' 2 ; FINSI ; * Historique des parametres (au cours de l'optimisation) SI itrac ; lahist = PROG ; lbhist = PROG ; lchist = PROG ; ldhist = PROG ; lwa = EXTR lw 1 ; REPE b1 (DIME lw) ; lw1 = EXTR lw &b1 ; lahist = lahist ET (EXTR lw1 1) ; lbhist = lbhist ET (EXTR lw1 2) ; lchist = lchist ET (EXTR lw1 3) ; ldhist = ldhist ET (EXTR lw1 4) ; FIN b1 ; SI itrac ; nit = (DIME lahist) - 1 ; lit = LECT 0 'PAS' 1 nit ; evmse = EVOL 'ROUG' 'MANU' 'Iteration' lit 'Erreur S(x)' mse ; DESS evmse 'TITR' 'Erreur quadratique VS Iterations' ; aref = EXTR wref 1 ; bref = EXTR wref 2 ; cref = EXTR wref 3 ; dref = EXTR wref 4 ; eva = EVOL 'ROUG' 'MANU' 'LEGE' 'a calcule' 'Iteration' lit 'w' lahist ; evb = EVOL 'ORAN' 'MANU' 'LEGE' 'b calcule' 'Iteration' lit 'w' lbhist ; evc = EVOL 'VERT' 'MANU' 'LEGE' 'c calcule' 'Iteration' lit 'w' lchist ; evd = EVOL 'BLEU' 'MANU' 'LEGE' 'd calcule' 'Iteration' lit 'w' ldhist ; evar = EVOL 'ROUG' 'MANU' 'LEGE' 'a ref.' 'STYL' 'TIRR' 'Iteration' (PROG 0. nit) 'Parametres' (PROG aref aref) ; evbr = EVOL 'ORAN' 'MANU' 'LEGE' 'b ref.' 'STYL' 'TIRR' 'Iteration' (PROG 0. nit) 'Parametres' (PROG bref bref) ; evcr = EVOL 'VERT' 'MANU' 'LEGE' 'c ref.' 'STYL' 'TIRR' 'Iteration' (PROG 0. nit) 'Parametres' (PROG cref cref) ; evdr = EVOL 'BLEU' 'MANU' 'LEGE' 'd ref.' 'STYL' 'TIRR' 'Iteration' (PROG 0. nit) 'Parametres' (PROG dref dref) ; DESS (eva ET evar ET evb ET evbr ET evc ET evcr ET evd ET evdr) 'TITR' 'Valeurs VS Iterations' 'LEGE' ; FINSI ; FINSI ; * Bilan et verification des parametres finaux err1 = EXTR mse (DIME mse) ; err2 = MAXI 'ABS' ((w - wref) / wref) ; MESS ; MESS 'Erreur quadratique finale =' err1 ; MESS 'Erreur sur les parametres finaux =' err2 ; ierr = (err1 > 1.E-10) OU (err2 > 2.E-6) ; SI ierr ; ERRE 'Erreur dans l''optimisation' ; FINSI ; SAUT 2 'LIGNE' ; * Fin du cas test SI (NON ierr) ; MESS 'Cas test passe avec succes !' ; FINSI ; FIN ;