IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

minimiser l'erreur entre deux courbes expérimentales et numériques


Sujet :

MATLAB

  1. #1
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut minimiser l'erreur entre deux courbes expérimentales et numériques
    bonjour
    j'ai de nouveau un problème :
    voila le code que j'ai utilisé pour minimiser l'erreur entre deux courbes expérimentales et numériques:
    le code principal est (minas):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    clear;
    lam0=[0.01 0.05 0.05 ]
    t0=clock;
    optio=optimset('TolFun',10e-8,'TolX',10e-7,'MaxFunEvals',2000,'MaxIter' ,1500,'display','iter','DiffMi nChange',0.04,'DiffMaxChange', 0.51);
    %[lam,FVAL,EXITFLAG,OUTPUT] = fminunc('fonct',e,optio);
    [lam,FVAL,EXITFLAG,output] = fminsearch('fonct',lam0,optio) ;
     
    lam
    output
    execution_time=etime(clock, t0);
    disp(sprintf(' L''algoritme= %s \r',output.algorithm));
    disp(sprintf(' Le temps d''exécution= %g \r',execution_time));
    disp(sprintf(' Le nombre d''itérations=%g \r',output.iterations));
    disp(sprintf(' lam=%g \r',lam));
    disp(sprintf(' FVAL =%g \r',FVAL));
    disp(sprintf(' ______________________________ ______________________________ ______________________________ __'));
    le problème est si je veux lancer le programme principal il m'affiche cette erreur :
    ??? Attempted to access Fint(14); index out of bounds because numel(Fint)=13.
    
    Error in ==> fonct at 17
    X=(Fint(i)-Fsim(i)).^2;
    
    Error in ==> fminsearch at 326
    x( = xe; fxe = funfcn(x,varargin{:});
    
    Error in ==> minas at 10
    [lam,FVAL,EXITFLAG,output] = fminsearch('fonct',lam0,optio) ;
    alors y-a-t'il quelqu’un qui peut m'aider à résoudre ce problème merci

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    L'erreur est assez explicite: ta variable Fint contient 13 valeurs (numel(Fint) = 13) et toi tu fais une boucle allant de 1 à 40, donc dès la valeur i = 14, ça plante.
    Quelque chose du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    for i=1:length(Fint)
            X=(Fint(i)-Fsim(i)).^2;
            b=b+X
    end
    serait plus juste, voire b = sum((Fint-Fsim).^2);
    Dernière modification par Invité ; 22/05/2011 à 00h22.

  3. #3
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut salut
    salut
    bon je pense pas que c'est ca le problème car Fint contient surement 40 valeurs plutôt le problème est dans l'algorithme d’optimisation lui même c’est a dire dans minas car il ne converge pas dés la valeur 13, en fait tout ce code c'est pour démarrer abaqus afin de déterminer des paramètres de matériau alors si l'optimisation donne une valeur négatif ABAQUS ne va pas accepter ca et donc le programme diverge tu voit
    donc je doit essayer de trouver un autre algorithme qui est diffèrent de simplex(fminsearch) et qui donne le résultat le plus convenable
    et merci ;

  4. #4
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut optimisation
    y'a t'il quelqu'un qui connait qu'est ce qu'on utilise pour faire l'optimisation d'un probléme avec des contraintes en fait l'utilisation de simplex(fmnsearch) ne tient pas compte des contraintes
    et donc?????
    MERCI pr tout le monde

  5. #5
    Invité
    Invité(e)
    Par défaut
    Bonsoir,

    Si tu possèdes l'Optimization Toolbox, tu peux regarder la fonction doc fmincon

  6. #6
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut
    malheureusement
    je l'ai utilisé maais sans resultat il m'affiche un message d'erreur

  7. #7
    Invité
    Invité(e)
    Par défaut
    Et si tu nous montrais ton code ainsi que l'erreur que tu obtiens?
    Je vois mal comment on pourrait t'aider sinon

  8. #8
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut
    bonjour voila le code que j'ai utilisé :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    clear;
    lam0=[0.01 0.05 0.05 ]
    LB=[0 0 0];
    UB=[10 1 +inf];
     t0=clock;
    optio=optimset('TolFun',10e-8,'TolX',10e-7,'MaxFunEvals',2000,'MaxIter',1500,'display','iter','DiffMinChange',0.04,'DiffMaxChange',0.51);
    %[lam,FVAL,EXITFLAG,OUTPUT] = fminsearchbnd('fonct',e,optio);
    [lam,fval,exitflag,output] = fminsearchbnd(@fonct,lam0,LB,UB,optio);
     
    output
    execution_time=etime(clock, t0);
    disp(sprintf(' L''algoritme= %s \r',output.algorithm));
    disp(sprintf(' Le temps d''exécution= %g \r',execution_time));
    disp(sprintf(' Le nombre d''itérations=%g \r',output.iterations));
    disp(sprintf(' lam=%g \r',lam));
    disp(sprintf(' FVAL =%g \r',FVAL));
       disp(sprintf(' ____________________________________________________________________________________________'));
     
       function b = fonct(lam)
    global Uexp RFexp
    %lecture des données expérimentaux 
    fid =fopen('données expérimentaux.m','r');
    M = fscanf(fid,'%e',[1,1]);
    xy=fscanf(fid,'%e%e',[2,M]);
    xy1=xy';
    Uexp=xy1(:,1) ;   %vesteur colonne U2- déplacement 
    RFexp=xy1(:,2) ;  %vecteur colonne RF2- réaction
    mef(lam);
    rf4;
    Fint=interp1(Uexp,RFexp,-c(:,3),'spline');
    Fsim= - c(:,5);
    b=0;
    for i=1:40
        X=(Fint(i)-Fsim(i)).^2;
        b=b+X;
    end
     
    %ouvrir fichier .dat
    fid=fopen('essai1force.dat');
    %lire fichier.dat
    i=0;
     c=[];    
     while 1
               i=i+1;
                tline = fgetl(fid);
     
                xy1=fscanf(fid,'%c',[1,16]);
                a=xy1;
                C = strcmp(xy1,'            NOTE');
                y=i;
                if strcmp(xy1,'            NOTE')==1,
                   y=i;    
                   xy=fscanf(fid,'%12e  ',[1,5]);
                   a=xy';
    %                react1(1,:)=rx(xy(2:3,:)'); 
      react1=xy(1,:);
     
                   c= [c;react1];
                end
     
             if ~ischar(tline), break, end
    %             disp(tline);
     
            end
            fclose(fid);  
     
     
    function mef(lam)
     readwrite(lam); 
    !exec2
     
    %-------------------------------------------------------
    %-------------------------------------------------------
    function readwrite(lam)
     E1=lam(:,1);
     E2=lam(:,2);
     nu=lam(:,3);
     E0=E1+E2;
     K=(E1+E2)/0.12;
     G=(3*K*E1)/(9*K-E1);
     G0=(3*K*(E1+E2))/(9*K-(E1+E2));
     g1=1-G/G0;
     taux=(nu*(9*K-E1-E2))/(E2*(9*K-E1));
     fid8=fopen('pp.inp','w');
     fprintf(fid8,'%s \n','*PARAMETER');
     fprintf(fid8,'%s %12.9e\n','E0=',E0);
     fprintf(fid8,'%s %12.9e\n','g1=',g1);
     fprintf(fid8,'%s %12.9e\n','taux=',taux);
    fclose(fid8);
    % fclose(fid8);
    %fcrit
    la fonction fminsearchbnd je l'ai trouvé par hasard normalement c'est pour fminsearch borné parce que moi j'ai des conditions sur le variable tu peut voir le lien suivant :
    http://www.mathworks.com/matlabcentr...minsearchbnd.m

    l'erreur que me donne matlab c'est bien ca :

    ??? Undefined function or method 'fminsearchbnd' for input arguments of type 'function_handle'.
    
    Error in ==> minas at 10
    [lam,fval,exitflag,output] = fminsearchbnd(@fonct,lam0,LB,UB,optio);
     
    Fichiers attachés Fichiers attachés

  9. #9
    Invité
    Invité(e)
    Par défaut
    As-tu copié et placé la fonction fminsearchbnd de façon à ce qu'elle soit accessible par Matlab?
    Par exemple dans le répertoire courant ou l'un des dossiers retournés par path.

  10. #10
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut
    je t'ai pas compris oui j'ai recopier ça et 'ai changer le contraintes pour qu'il s'adapte avec mon problème.

  11. #11
    Invité
    Invité(e)
    Par défaut
    Je parle de recopier le contenu de la fonction fminsearchbnd de ton lien dans un fichier .m du même nom et de mettre ce fichier au bon endroit pour que Matlab y ait accès.
    Dernière modification par Invité ; 22/05/2011 à 16h02.

  12. #12
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut
    et pourquoi faire???? normalement dans mon programme principal je vait juste changer un peu les parametres de la fonction et c'est tout .

  13. #13
    Invité
    Invité(e)
    Par défaut
    La fonction fminsearchbnd n'existe par sur Matlab, on est d'accord?
    Donc si tu ne la crées pas, comme comptes-tu l'utiliser? C'est bien ce que fait la ligne [lam,fval,exitflag,output] = fminsearchbnd(@fonct,lam0,LB,UB,optio); non?

  14. #14
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut
    ah oui alors si j'ai bien compris je doit moi même créer cette fonction comme c'est indiquée dans le lien,?

  15. #15
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut salut
    malheureusement j'ai pas réussi a l'utiliser

  16. #16
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    C'est un peu maigre pour pouvoir t'aider... Qu'obtiens-tu? un message d'erreur? un résultat inattendu?

  17. #17
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut
    oui c'est bien un message d'erreur :
    ??? Error using ==> feval
    Argument must contain a string or function_handle.
    
    Error in ==> fminsearchbnd>intrafonct at 259
    fval = feval(reshape(lamtrans,params.lamsize),params.args{:});
    
    Error in ==> fminsearch at 205
    fv(:,1) = funfcn(x,varargin{:});
    
    Error in ==> fminsearchbnd at 229
    [lamu,fval,exitflag,output] = fminsearch(@intrafonct,lam0u,options,params);
    et voila le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    function [lam,fval,exitflag,output]=fminsearchbnd(fonct,lam0,LB,UB,options,varargin)
    % FMINSEARCHBND: FMINSEARCH, but with bound constraints by transformation
    % usage: x=FMINSEARCHBND(fun,x0)
    % usage: x=FMINSEARCHBND(fun,x0,LB)
    % usage: x=FMINSEARCHBND(fun,x0,LB,UB)
    % usage: x=FMINSEARCHBND(fun,x0,LB,UB,options)
    % usage: x=FMINSEARCHBND(fun,x0,LB,UB,options,p1,p2,...)
    % usage: [x,fval,exitflag,output]=FMINSEARCHBND(fun,x0,...)
    % 
    % arguments:
    %  fun, x0, options - see the help for FMINSEARCH
    %
    %  LB - lower bound vector or array, must be the same size as x0
    %
    %       If no lower bounds exist for one of the variables, then
    %       supply -inf for that variable.
    %
    %       If no lower bounds at all, then LB may be left empty.
    %
    %       Variables may be fixed in value by setting the corresponding
    %       lower and upper bounds to exactly the same value.
    %
    %  UB - upper bound vector or array, must be the same size as x0
    %
    %       If no upper bounds exist for one of the variables, then
    %       supply +inf for that variable.
    %
    %       If no upper bounds at all, then UB may be left empty.
    %
    %       Variables may be fixed in value by setting the corresponding
    %       lower and upper bounds to exactly the same value.
    %
    % Notes:
    %
    %  If options is supplied, then TolX will apply to the transformed
    %  variables. All other FMINSEARCH parameters should be unaffected.
    %
    %  Variables which are constrained by both a lower and an upper
    %  bound will use a sin transformation. Those constrained by
    %  only a lower or an upper bound will use a quadratic
    %  transformation, and unconstrained variables will be left alone.
    %
    %  Variables may be fixed by setting their respective bounds equal.
    %  In this case, the problem will be reduced in size for FMINSEARCH.
    %
    %  The bounds are inclusive inequalities, which admit the
    %  boundary values themselves, but will not permit ANY function
    %  evaluations outside the bounds. These constraints are strictly
    %  followed.
    %
    %  If your problem has an EXCLUSIVE (strict) constraint which will
    %  not admit evaluation at the bound itself, then you must provide
    %  a slightly offset bound. An example of this is a function which
    %  contains the log of one of its parameters. If you constrain the
    %  variable to have a lower bound of zero, then FMINSEARCHBND may
    %  try to evaluate the function exactly at zero.
    %
    %
    % Example usage:
    % rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;
    %
    % fminsearch(rosen,[3 3])     % unconstrained
    % ans =
    %    1.0000    1.0000
    %
    % fminsearchbnd(rosen,[3 3],[2 2],[])     % constrained
    % ans =
    %    2.0000    4.0000
    %
    % See test_main.m for other examples of use.
    %
    %
    % See also: fminsearch, fminspleas
    %
    %
    % Author: John D'Errico
    % E-mail: woodchips@rochester.rr.com
    % Release: 4
    % Release date: 7/23/06
     
    % size checks
     
    lam0 = [0.01 0.05 0.05];
    lamsize = size(lam0);
    n=length(lam0);
     
    if (nargin<3) || isempty(LB)
      LB = repmat(-inf,n,1);
    else
      LB = LB(:);
    end
    if (nargin<4) || isempty(UB)
      UB = repmat(inf,n,1);
    else
      UB = UB(:);
    end
     
    if (n~=length(LB)) || (n~=length(UB))
      error 'lam0 is incompatible in size with either LB or UB.'
    end
     
    % set default options if necessary
    if (nargin<5) || isempty(options)
      options = optimset('fminsearch');
    end
     
    % stuff into a struct to pass around
    params.args = varargin;
    params.LB = LB;
    params.UB = UB;
    params.n = n;
    % note that the number of parameters may actually vary if 
    % a user has chosen to fix one or more parameters
    params.lamsize = lamsize;
    params.OutputFcn = [];
     
    % 0 --> unconstrained variable
    % 1 --> lower bound only
    % 2 --> upper bound only
    % 3 --> dual finite bounds
    % 4 --> fixed variable
    params.BoundClass = zeros(n,1);
    for i=1:n
      k = isfinite(LB(i)) + 2*isfinite(UB(i));
      params.BoundClass(i) = k;
      if (k==3) && (LB(i)==UB(i))
        params.BoundClass(i) = 4;
      end
    end
     
    % transform starting values into their unconstrained
    % surrogates. Check for infeasible starting guesses.
    lam0u = lam0;
    k=1;
    for i = 1:n
      switch params.BoundClass(i)
        case 1
          % lower bound only
          if lam0(i)<=LB(i)
            % infeasible starting value. Use bound.
            lam0u(k) = 0;
          else
            lam0u(k) = sqrt(lam0(i) - LB(i));
          end
     
          % increment k
          k=k+1;
        case 2
          % upper bound only
          if lam0(i)>=UB(i)
            % infeasible starting value. use bound.
            lam0u(k) = 0;
          else
            lam0u(k) = sqrt(UB(i) - lam0(i));
          end
     
          % increment k
          k=k+1;
        case 3
          % lower and upper bounds
          if lam0(i)<=LB(i)
            % infeasible starting value
            lam0u(k) = -pi/2;
          elseif lam0(i)>=UB(i)
            % infeasible starting value
            lam0u(k) = pi/2;
          else
            lam0u(k) = 2*(lam0(i) - LB(i))/(UB(i)-LB(i)) - 1;
            % shift by 2*pi to avoid problems at zero in fminsearch
            % otherwise, the initial simplex is vanishingly small
            lam0u(k) = 2*pi+asin(max(-1,min(1,lam0u(k))));
          end
     
          % increment k
          k=k+1;
        case 0
          % unconstrained variable. x0u(i) is set.
          lam0u(k) = lam0(i);
     
          % increment k
          k=k+1;
        case 4
          % fixed variable. drop it before fminsearch sees it.
          % k is not incremented for this variable.
      end
     
    end
    % if any of the unknowns were fixed, then we need to shorten
    % x0u now.
    if k<=n
      lam0u(k:n) = [];
    end
     
    % were all the variables fixed?
    if isempty(lam0u)
      % All variables were fixed. quit immediately, setting the
      % appropriate parameters, then return.
     
      % undo the variable transformations into the original space
      lam = lamtransform(lam0u,params);
     
      % final reshape
      lam = reshape(lam,lamsize);
     
      % stuff fval with the final value
      fval = feval(lam,params.args{:});
     
      % fminsearchbnd was not called
      exitflag = 0;
     
      output.iterations = 0;
      output.funcount = 1;
      output.algorithm = 'fminsearch';
      output.message = 'All variables were held fixed by the applied bounds';
     
      % return with no call at all to fminsearch
      return
    end
     
    % Check for an outputfcn. If there is any, then substitute my
    % own wrapper function.
    if ~isempty(options.OutputFcn)
      params.OutputFcn = options.OutputFcn;
      options.OutputFcn = @outfonct_wrapper;
    end
     
    % now we can call fminsearch, but with our own
    % intra-objective function.
    [lamu,fval,exitflag,output] = fminsearch(@intrafonct,lam0u,options,params);
     
    % undo the variable transformations into the original space
    lam = lamtransform(lamu,params);
     
    % final reshape to make sure the result has the proper shape
    lam = reshape(lam,lamsize);
     
    % Use a nested function as the OutputFcn wrapper
      function stop = outfonct_wrapper(lam,varargin);
        % we need to transform x first
        lamtrans = lamtransform(lam,params);
     
        % then call the user supplied OutputFcn
        stop = params.OutputFcn(lamtrans,varargin{1:(end-1)});
     
      end
     
    end % mainline end
     
    % ======================================
    % ========= begin subfunctions =========
    % ======================================
    function fval = intrafonct(lam,params)
    % transform variables, then call original function
     
    % transform
    lamtrans = lamtransform(lam,params);
     
    % and call fun
    fval = feval(reshape(lamtrans,params.lamsize),params.args{:});
     
    end % sub function intrafun end
     
    % ======================================
    function lamtrans = lamtransform(lam,params)
    % converts unconstrained variables into their original domains
     
    lamtrans = zeros(params.lamsize);
    % k allows some variables to be fixed, thus dropped from the
    % optimization.
    k=1;
    for i = 1:params.n
      switch params.BoundClass(i)
        case 1
          % lower bound only
          lamtrans(i) = params.LB(i) + lam(k).^2;
     
          k=k+1;
        case 2
          % upper bound only
          lamtrans(i) = params.UB(i) - lam(k).^2;
     
          k=k+1;
        case 3
          % lower and upper bounds
          lamtrans(i) = (sin(lam(k))+1)/2;
          lamtrans(i) = lamtrans(i)*(params.UB(i) - params.LB(i)) + params.LB(i);
          % just in case of any floating point problems
          lamtrans(i) = max(params.LB(i),min(params.UB(i),lamtrans(i)));
     
          k=k+1;
        case 4
          % fixed variable, bounds are equal, set it at either bound
          lamtrans(i) = params.LB(i);
        case 0
          % unconstrained variable.
          lamtrans(i) = lam(k);
     
          k=k+1;
      end
    end
     
    end % sub function xtransform end

  18. #18
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    Peux-tu nous montrer le code que tu utilises pour appeler fminsearchbnd?

  19. #19
    Membre à l'essai
    Femme Profil pro
    Mécanique
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Mécanique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Points : 18
    Points
    18
    Par défaut
    je l'ai déjà mis le code

  20. #20
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par foufi86 Voir le message
    je l'ai déjà mis le code
    C'est le code de la fonction fminsearchbnd, que l'on pouvait très bien regarder dans ton lien, nous on te demande le code qui utilise cette fonction.

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [Débutant] Calcul d'erreur entre deux courbes
    Par louftansa dans le forum MATLAB
    Réponses: 14
    Dernier message: 03/06/2009, 15h10
  2. [patch][fill] Coloriage entre deux courbes
    Par kis93 dans le forum MATLAB
    Réponses: 6
    Dernier message: 02/10/2008, 22h01
  3. Différence entre deux courbes
    Par malokox dans le forum Signal
    Réponses: 2
    Dernier message: 24/06/2008, 10h15
  4. Calcul erreur entre deux images noir et blanc
    Par b4sols dans le forum Images
    Réponses: 1
    Dernier message: 22/03/2007, 08h59
  5. [VBA E]Colorier l'espace entre deux courbes
    Par conconbrr dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 25/07/2006, 09h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo