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 :

Optimisation de boucles via calcul matriciel


Sujet :

MATLAB

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 134
    Points : 129
    Points
    129
    Par défaut Optimisation de boucles via calcul matriciel
    Bonjour,

    je travaille actuellement sur de l'allocation de portefeuilles (Finance de Marché) et j'ai brièvement codé (à la va-vite) une fonction Matlab qui me permet de définir les allocations initiales en fonction de poids initiaux, finaux et d'un pas d'incrément. Je m'explique : je possède entre 30 et 40 titres de poids initiaux définis (Titre 1 : 0% Titre 2 : 10% ... Titre 40 : 30%) ainsi que finaux (Titre 1 : 100% Titre 2 : 100% ... Titre 40 : 100%) et j'aimerai définir toutes les combinaisons possibles entre les poids selon un pas sur chaque titre...
    Par exemple un portefeuille de 2 titres A et B de poids initiaux (0%, 0%) et finaux (100%, 100%) avec les pas d'incréments (20%, 40%) me donne au final les vecteurs : (0%, 100%) (100%, 0%) (20%, 80%) (60% 40%)
    (sous la condition que la somme des poids est tjrs égale à 100%).

    Voici donc mon 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
    function [Allocations] = PoidsInitiaux4(AllocationInitiale, Incrementation, AllocationFinale)
     
    %--------------------------------------------------------------------------
     
    % Vérification du nombre d'arguments.
      if nargin ~= 3
         error 'Nombre d''arguments incorrect !' 
      end
     
    % Mise en place des allocations.
      Taille = length(AllocationInitiale);
      Allocations = zeros(Taille, 65500);     
     
      Numero = 0;
     
    % Cas d'étude d'un portefeuille constitué de trente et un à quarante fonds.    
      if Taille == 31
         for a = AllocationInitiale(1, 1) : Incrementation(1, 1) : (AllocationFinale(1, 1)+eps*100)  
             for b = AllocationInitiale(2, 1) : Incrementation(2, 1) : (AllocationFinale(2, 1)+eps*100) 
                 for c = AllocationInitiale(3, 1) : Incrementation(3, 1) : (AllocationFinale(3, 1)+eps*100) 
                     for d = AllocationInitiale(4, 1) : Incrementation(4, 1) : (AllocationFinale(4, 1)+eps*100) 
                         for e = AllocationInitiale(5, 1) : Incrementation(5, 1) : (AllocationFinale(5, 1)+eps*100)  
                             for f = AllocationInitiale(6, 1) : Incrementation(6, 1) : (AllocationFinale(6, 1)+eps*100)  
                                 for g = AllocationInitiale(7, 1) : Incrementation(7, 1) : (AllocationFinale(7, 1)+eps*100)
                                     for h = AllocationInitiale(8, 1) : Incrementation(8, 1) : (AllocationFinale(8, 1)+eps*100)
                                         for i = AllocationInitiale(9, 1) : Incrementation(9, 1) : (AllocationFinale(9, 1)+eps*100)   
                                             for j = AllocationInitiale(10, 1) : Incrementation(10, 1) : (AllocationFinale(10, 1)+eps*100)
                                                 for k = AllocationInitiale(11, 1) : Incrementation(11, 1) : (AllocationFinale(11, 1)+eps*100)
                                                     for l = AllocationInitiale(12, 1) : Incrementation(12, 1) : (AllocationFinale(12, 1)+eps*100)
                                                         for m = AllocationInitiale(13, 1) : Incrementation(13, 1) : (AllocationFinale(13, 1)+eps*100)
                                                             for n = AllocationInitiale(14, 1) : Incrementation(14, 1) : (AllocationFinale(14, 1)+eps*100)
                                                                 for o = AllocationInitiale(15, 1) : Incrementation(15, 1) : (AllocationFinale(15, 1)+eps*100)
                                                                     for p = AllocationInitiale(16, 1) : Incrementation(16, 1) : (AllocationFinale(16, 1)+eps*100)
                                                                         for q = AllocationInitiale(17, 1) : Incrementation(17, 1) : (AllocationFinale(17, 1)+eps*100)
                                                                             for r = AllocationInitiale(18, 1) : Incrementation(18, 1) : (AllocationFinale(18, 1)+eps*100)
                                                                                 for s = AllocationInitiale(19, 1) : Incrementation(19, 1) : (AllocationFinale(19, 1)+eps*100)
                                                                                     for t = AllocationInitiale(20, 1) : Incrementation(20, 1) : (AllocationFinale(20, 1)+eps*100)
                                                                                         for u = AllocationInitiale(21, 1) : Incrementation(21, 1) : (AllocationFinale(21, 1)+eps*100)
                                                                                             for v = AllocationInitiale(22, 1) : Incrementation(22, 1) : (AllocationFinale(22, 1)+eps*100)
                                                                                                 for w = AllocationInitiale(23, 1) : Incrementation(23, 1) : (AllocationFinale(23, 1)+eps*100)
                                                                                                     for x = AllocationInitiale(24, 1) : Incrementation(24, 1) : (AllocationFinale(24, 1)+eps*100)
                                                                                                         for y = AllocationInitiale(25, 1) : Incrementation(25, 1) : (AllocationFinale(25, 1)+eps*100) 
                                                                                                             for z = AllocationInitiale(26, 1) : Incrementation(26, 1) : (AllocationFinale(26, 1)+eps*100)   
                                                                                                                 for aa = AllocationInitiale(27, 1) : Incrementation(27, 1) : (AllocationFinale(27, 1)+eps*100)  
                                                                                                                     for bb = AllocationInitiale(28, 1) : Incrementation(28, 1) : (AllocationFinale(28, 1)+eps*100) 
                                                                                                                         for cc = AllocationInitiale(29, 1) : Incrementation(29, 1) : (AllocationFinale(29, 1)+eps*100)
                                                                                                                             for dd = AllocationInitiale(30, 1) : Incrementation(30, 1) : (AllocationFinale(30, 1)+eps*100)
                                                                                                                                 if (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd) > (AllocationInitiale(31, 1)-eps*100) && (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd) < (AllocationFinale(31, 1)+eps*100)
                                                                                                                                    Numero = Numero+1;      
     
                                                                                                                                    if Numero > 65500
                                                                                                                                       error 'Nombre maximal de portefeuilles atteint !';
                                                                                                                                    end
     
                                                                                                                                    Allocations(:, Numero) = [a ; b ; c ; d ; e ; f ; g ; h ; i ; j ; k ; l ; m ; n ; o ; p ; q ; r ; s ; t ; u ; v ; w ; x ; y ; z ; aa ; bb ; cc ; dd ; 1-(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z+aa+bb+cc+dd)]; 
                                                                                                                                 end
                                                                                                                             end
                                                                                                                         end
                                                                                                                     end
                                                                                                                 end
                                                                                                             end
                                                                                                         end
                                                                                                     end
                                                                                                 end
                                                                                             end
                                                                                         end
                                                                                     end
                                                                                 end
                                                                             end
                                                                         end
                                                                     end
                                                                 end
                                                             end
                                                         end
                                                     end
                                                 end
                                             end
                                         end
                                     end
                                 end
                             end
                         end
                     end
                 end  
             end
         end
     
    ....coupe du code...
     
         if Numero == 0
            Allocations = zeros(39, 1); 
         end     
     elseif Taille == 40
         for a = AllocationInitiale(1, 1) : Incrementation(1, 1) : (AllocationFinale(1, 1)+eps*100)  
             for b = AllocationInitiale(2, 1) : Incrementation(2, 1) : (AllocationFinale(2, 1)+eps*100) 
                 for c = AllocationInitiale(3, 1) : Incrementation(3, 1) : (AllocationFinale(3, 1)+eps*100) 
                     for d = AllocationInitiale(4, 1) : Incrementation(4, 1) : (AllocationFinale(4, 1)+eps*100) 
                         for e = AllocationInitiale(5, 1) : Incrementation(5, 1) : (AllocationFinale(5, 1)+eps*100)  
                             for f = AllocationInitiale(6, 1) : Incrementation(6, 1) : (AllocationFinale(6, 1)+eps*100)  
                                 for g = AllocationInitiale(7, 1) : Incrementation(7, 1) : (AllocationFinale(7, 1)+eps*100)
                                     for h = AllocationInitiale(8, 1) : Incrementation(8, 1) : (AllocationFinale(8, 1)+eps*100)
                                         for i = AllocationInitiale(9, 1) : Incrementation(9, 1) : (AllocationFinale(9, 1)+eps*100)   
                                             for j = AllocationInitiale(10, 1) : Incrementation(10, 1) : (AllocationFinale(10, 1)+eps*100)
                                                 for k = AllocationInitiale(11, 1) : Incrementation(11, 1) : (AllocationFinale(11, 1)+eps*100)
                                                     for l = AllocationInitiale(12, 1) : Incrementation(12, 1) : (AllocationFinale(12, 1)+eps*100)
                                                         for m = AllocationInitiale(13, 1) : Incrementation(13, 1) : (AllocationFinale(13, 1)+eps*100)
                                                             for n = AllocationInitiale(14, 1) : Incrementation(14, 1) : (AllocationFinale(14, 1)+eps*100)
                                                                 for o = AllocationInitiale(15, 1) : Incrementation(15, 1) : (AllocationFinale(15, 1)+eps*100)
                                                                     for p = AllocationInitiale(16, 1) : Incrementation(16, 1) : (AllocationFinale(16, 1)+eps*100)
                                                                         for q = AllocationInitiale(17, 1) : Incrementation(17, 1) : (AllocationFinale(17, 1)+eps*100)
                                                                             for r = AllocationInitiale(18, 1) : Incrementation(18, 1) : (AllocationFinale(18, 1)+eps*100)
                                                                                 for s = AllocationInitiale(19, 1) : Incrementation(19, 1) : (AllocationFinale(19, 1)+eps*100)
                                                                                     for t = AllocationInitiale(20, 1) : Incrementation(20, 1) : (AllocationFinale(20, 1)+eps*100)
                                                                                         for u = AllocationInitiale(21, 1) : Incrementation(21, 1) : (AllocationFinale(21, 1)+eps*100)
                                                                                             for v = AllocationInitiale(22, 1) : Incrementation(22, 1) : (AllocationFinale(22, 1)+eps*100)
                                                                                                 for w = AllocationInitiale(23, 1) : Incrementation(23, 1) : (AllocationFinale(23, 1)+eps*100)
                                                                                                     for x = AllocationInitiale(24, 1) : Incrementation(24, 1) : (AllocationFinale(24, 1)+eps*100)
                                                                                                         for y = AllocationInitiale(25, 1) : Incrementation(25, 1) : (AllocationFinale(25, 1)+eps*100) 
                                                                                                             for z = AllocationInitiale(26, 1) : Incrementation(26, 1) : (AllocationFinale(26, 1)+eps*100)   
                                                                                                                 for aa = AllocationInitiale(27, 1) : Incrementation(27, 1) : (AllocationFinale(27, 1)+eps*100)  
                                                                                                                     for bb = AllocationInitiale(28, 1) : Incrementation(28, 1) : (AllocationFinale(28, 1)+eps*100) 
                                                                                                                         for cc = AllocationInitiale(29, 1) : Incrementation(29, 1) : (AllocationFinale(29, 1)+eps*100)
                                                                                                                             for dd = AllocationInitiale(30, 1) : Incrementation(30, 1) : (AllocationFinale(30, 1)+eps*100)
                                                                                                                                 for ee = AllocationInitiale(31, 1) : Incrementation(31, 1) : (AllocationFinale(31, 1)+eps*100)
                                                                                                                                     for ff = AllocationInitiale(32, 1) : Incrementation(32, 1) : (AllocationFinale(32, 1)+eps*100)
                                                                                                                                         for gg = AllocationInitiale(33, 1) : Incrementation(33, 1) : (AllocationFinale(33, 1)+eps*100)
                                                                                                                                             for hh = AllocationInitiale(34, 1) : Incrementation(34, 1) : (AllocationFinale(34, 1)+eps*100)
                                                                                                                                                 for ii = AllocationInitiale(35, 1) : Incrementation(35, 1) : (AllocationFinale(35, 1)+eps*100)
                                                                                                                                                     for jj = AllocationInitiale(36, 1) : Incrementation(36, 1) : (AllocationFinale(36, 1)+eps*100)
                                                                                                                                                         for kk = AllocationInitiale(37, 1) : Incrementation(37, 1) : (AllocationFinale(37, 1)+eps*100)
                                                                                                                                                             for ll = AllocationInitiale(38, 1) : Incrementation(38, 1) : (AllocationFinale(38, 1)+eps*100)
                                                                                                                                                                 for mm = AllocationInitiale(39, 1) : Incrementation(39, 1) : (AllocationFinale(39, 1)+eps*100)
                                                                                                                                                                     if (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd-ee-ff-gg-hh-ii-jj-kk-ll-mm) > (AllocationInitiale(40, 1)-eps*100) && (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd-ee-ff-gg-hh-ii-jj-kk-ll-mm) < (AllocationFinale(40, 1)+eps*100)
                                                                                                                                                                        Numero = Numero+1;      
     
                                                                                                                                                                        if Numero > 65500
                                                                                                                                                                           error 'Nombre maximal de portefeuilles atteint !';
                                                                                                                                                                        end
     
                                                                                                                                                                        Allocations(:, Numero) = [a ; b ; c ; d ; e ; f ; g ; h ; i ; j ; k ; l ; m ; n ; o ; p ; q ; r ; s ; t ; u ; v ; w ; x ; y ; z ; aa ; bb ; cc ; dd ; ee ; ff ; gg ; hh ; ii ; jj ; kk ; ll ; mm ; 1-(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z+aa+bb+cc+dd+ee+ff+gg+hh+ii+jj+kk+ll+mm)]; 
                                                                                                                                                                     end
                                                                                                                                                                 end
                                                                                                                                                             end
                                                                                                                                                         end
                                                                                                                                                     end
                                                                                                                                                 end
                                                                                                                                             end
                                                                                                                                         end
                                                                                                                                     end
                                                                                                                                 end
                                                                                                                             end
                                                                                                                         end
                                                                                                                     end
                                                                                                                 end
                                                                                                             end
                                                                                                         end
                                                                                                     end
                                                                                                 end
                                                                                             end
                                                                                         end
                                                                                     end
                                                                                 end
                                                                             end
                                                                         end
                                                                     end
                                                                 end
                                                             end
                                                         end
                                                     end
                                                 end
                                             end
                                         end
                                     end
                                 end
                             end
                         end
                     end
                 end  
             end
         end
         if Numero == 0
            Allocations = zeros(40, 1); 
         end      
      end 
     
      AllocationsFin = Allocations(:, sum(Allocations, 1) ~= 0);
      Allocations = AllocationsFin;
    Le soucis est que ce dernier n'est pas du tout optimisé et prend énormément de temps à s'executer...

    Avez-vous quelques pistes à me donner afin d'améliorer le temps d'execution de cette fonction ?

    Je vous remercie de votre attention.
    Au taf : Quad Core/8Go de RAM sous Win Seven 64 - Matlab 2009b 64bit.
    Perso : Core 2 Duo/8Go de RAM Mac OS X 10.6 - Matlab 2009b 64bit

  2. #2
    Membre chevronné
    Avatar de kmaniche
    Inscrit en
    Janvier 2006
    Messages
    1 717
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 1 717
    Points : 1 884
    Points
    1 884
    Par défaut


    Je penses que je n'ai jamais eu l'occasion de voir un code pareil. Combien y-a-il de boucles, un, deux,... 31 bouclesx2 imbriquées pour deux conditions


    Du premier coup, il semblerait plus efficace si tu utilises les tableaux à plusieurs dimensions, et de lire ceci :

    Comment créer des variables nommées A1, A2, A3, ...,AN ?

    Les tableaux de cellules (cell array)

    Commences par faire des essais, on t'aidera au fur et à mesure
    Les règles Les cours La fonction rechercher

    N'oubliez pas de mettre en et de voter.

    La terre n'est pas un héritage de nos parents, mais un emprunt que nous faisons à nos enfants. La protection de notre environnement est la responsabilité de tous. Ne reculez plus devant l'urgence, agissez !

  3. #3
    Expert confirmé
    Avatar de duf42
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Novembre 2007
    Messages
    3 111
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 111
    Points : 4 661
    Points
    4 661
    Par défaut
    Bonjour,

    Pour ton besoin, je pense que les fonctions suivantes devraient pouvoir t'aider:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    help nchoosek
    help perm
    help repmat
    Bon courage,
    Duf
    Simulink & Embedded Coder

    Au boulot : Windows 7 , MATLAB r2016b
    A la maison : ArchLinux mais pas MATLAB

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 134
    Points : 129
    Points
    129
    Par défaut
    @ Duff42 :

    Merci pour les trois fonctions (que je ne connaissais pas). Seulement celles-ci ne me sont pas de grande utilité, mis à part si mes pas d'incrémentation sur mes 40 actifs sont égaux... mais ce n'est jamais le cas.

    Ce qui me semble étrange c'est que pour 10 actifs par exemple, les calculs s'effectuent convenablement sous Matlab avec un temps d'execution tout à fait correct...

    Exemple :

    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
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
     
    >> PoidsInitiaux = [0;0;0;0;0;0;0;0;0;0];
    >> Increments = [0.6;0.5;0.4;0.1;0.9;0.5;0.6;0.4;0.1;0.9];
    >> PoidsFinaux = [1;1;1;1;1;1;1;1;1;1];
     
    >> tic; [Allocations] = PoidsInitiaux1(PoidsInitiaux, Increments, PoidsFinaux); toc
    Elapsed time is 0.060530 seconds.
     
    Allocations =
     
      Columns 1 through 4
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       1.000000000000000   0.900000000000000   0.800000000000000   0.700000000000000
     
      Columns 5 through 8
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.500000000000000   0.600000000000000   0.700000000000000
       0.600000000000000   0.500000000000000   0.400000000000000   0.300000000000000
     
      Columns 9 through 12
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0   0.400000000000000
       0.800000000000000   0.900000000000000   1.000000000000000                   0
       0.200000000000000   0.100000000000000                   0   0.600000000000000
     
      Columns 13 through 16
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
       0.100000000000000   0.200000000000000   0.300000000000000   0.400000000000000
       0.500000000000000   0.400000000000000   0.300000000000000   0.200000000000000
     
      Columns 17 through 20
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.800000000000000   0.800000000000000
       0.500000000000000   0.600000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.200000000000000   0.100000000000000
     
      Columns 21 through 24
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.600000000000000   0.600000000000000   0.600000000000000
       0.800000000000000                   0                   0                   0
       0.200000000000000                   0   0.100000000000000   0.200000000000000
                       0   0.400000000000000   0.300000000000000   0.200000000000000
     
      Columns 25 through 28
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0   0.500000000000000
       0.600000000000000   0.600000000000000   0.600000000000000                   0
                       0                   0   0.400000000000000                   0
       0.300000000000000   0.400000000000000                   0                   0
       0.100000000000000                   0                   0   0.500000000000000
     
      Columns 29 through 32
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000   0.300000000000000   0.400000000000000
       0.400000000000000   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 33 through 36
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   1.000000000000000
                       0                   0                   0                   0
                       0   0.400000000000000   0.400000000000000                   0
       0.500000000000000                   0   0.100000000000000                   0
                       0   0.100000000000000                   0                   0
     
      Columns 37 through 40
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.100000000000000   0.100000000000000
       0.900000000000000   0.900000000000000                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.900000000000000   0.800000000000000
     
      Columns 41 through 44
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.300000000000000   0.400000000000000   0.500000000000000
       0.700000000000000   0.600000000000000   0.500000000000000   0.400000000000000
     
      Columns 45 through 48
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.600000000000000   0.700000000000000   0.800000000000000   0.900000000000000
       0.300000000000000   0.200000000000000   0.100000000000000                   0
     
      Columns 49 through 52
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.500000000000000   0.400000000000000   0.300000000000000   0.200000000000000
     
      Columns 53 through 56
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.800000000000000   0.800000000000000
       0.400000000000000   0.500000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.100000000000000                   0
     
      Columns 57 through 60
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.600000000000000   0.600000000000000   0.600000000000000   0.600000000000000
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.300000000000000   0.200000000000000   0.100000000000000                   0
     
      Columns 61 through 64
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.400000000000000   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 65 through 68
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.200000000000000
                       0                   0   0.900000000000000                   0
       0.500000000000000   0.500000000000000                   0                   0
                       0                   0                   0                   0
                       0   0.400000000000000                   0                   0
       0.400000000000000                   0                   0                   0
                       0                   0                   0   0.800000000000000
     
      Columns 69 through 72
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.200000000000000   0.200000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000   0.300000000000000   0.400000000000000
       0.700000000000000   0.600000000000000   0.500000000000000   0.400000000000000
     
      Columns 73 through 76
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.200000000000000   0.200000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.500000000000000   0.600000000000000   0.700000000000000   0.800000000000000
       0.300000000000000   0.200000000000000   0.100000000000000                   0
     
      Columns 77 through 80
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.200000000000000   0.200000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.400000000000000   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 81 through 84
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.200000000000000   0.200000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.600000000000000   0.600000000000000
       0.400000000000000   0.800000000000000                   0                   0
       0.400000000000000                   0                   0   0.100000000000000
                       0                   0   0.200000000000000   0.100000000000000
     
      Columns 85 through 88
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.200000000000000   0.200000000000000   0.200000000000000
                       0                   0                   0                   0
                       0   0.500000000000000   0.500000000000000   0.500000000000000
       0.600000000000000                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000                   0   0.100000000000000   0.200000000000000
                       0   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 89 through 92
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.300000000000000   0.300000000000000   0.300000000000000
                       0                   0                   0                   0
       0.500000000000000                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.300000000000000                   0   0.100000000000000   0.200000000000000
                       0   0.700000000000000   0.600000000000000   0.500000000000000
     
      Columns 93 through 96
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.300000000000000   0.300000000000000   0.300000000000000   0.300000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.300000000000000   0.400000000000000   0.500000000000000   0.600000000000000
       0.400000000000000   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 97 through 100
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.300000000000000   0.300000000000000   0.300000000000000   0.300000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.400000000000000   0.400000000000000   0.400000000000000
       0.700000000000000                   0   0.100000000000000   0.200000000000000
                       0   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 101 through 104
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.300000000000000   0.300000000000000   0.300000000000000   0.300000000000000
                       0                   0                   0                   0
                       0                   0                   0   0.500000000000000
                       0   0.600000000000000   0.600000000000000                   0
       0.400000000000000                   0                   0                   0
       0.300000000000000                   0   0.100000000000000                   0
                       0   0.100000000000000                   0   0.200000000000000
     
      Columns 105 through 108
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.300000000000000   0.300000000000000   0.400000000000000   0.400000000000000
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.600000000000000   0.500000000000000
     
      Columns 109 through 112
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.300000000000000   0.400000000000000   0.500000000000000
       0.400000000000000   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 113 through 116
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.400000000000000   0.400000000000000   0.400000000000000
       0.600000000000000                   0   0.100000000000000   0.200000000000000
                       0   0.200000000000000   0.100000000000000                   0
     
      Columns 117 through 120
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.500000000000000
                       0                   0                   0                   0
                       0   0.500000000000000   0.500000000000000                   0
       0.600000000000000                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.100000000000000                   0
                       0   0.100000000000000                   0   0.500000000000000
     
      Columns 121 through 124
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000   0.300000000000000   0.400000000000000
       0.400000000000000   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 125 through 128
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
                       0                   0                   0   0.500000000000000
                       0                   0                   0                   0
                       0   0.400000000000000   0.400000000000000                   0
       0.500000000000000                   0   0.100000000000000                   0
                       0   0.100000000000000                   0                   0
     
      Columns 129 through 132
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.600000000000000   0.600000000000000   0.600000000000000   0.600000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.400000000000000   0.300000000000000   0.200000000000000   0.100000000000000
     
      Columns 133 through 136
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.600000000000000   0.600000000000000   0.700000000000000   0.700000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.400000000000000                   0                   0
       0.400000000000000                   0                   0   0.100000000000000
                       0                   0   0.300000000000000   0.200000000000000
     
      Columns 137 through 140
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.700000000000000   0.700000000000000   0.800000000000000   0.800000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.300000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.200000000000000   0.100000000000000
     
      Columns 141 through 144
     
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.800000000000000   0.900000000000000   0.900000000000000   1.000000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000                   0   0.100000000000000                   0
                       0   0.100000000000000                   0                   0
     
      Columns 145 through 148
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.600000000000000   0.500000000000000   0.400000000000000   0.300000000000000
     
      Columns 149 through 152
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0   0.400000000000000
       0.400000000000000   0.500000000000000   0.600000000000000                   0
       0.200000000000000   0.100000000000000                   0   0.200000000000000
     
      Columns 153 through 156
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0   0.500000000000000
                       0                   0   0.600000000000000                   0
       0.400000000000000   0.400000000000000                   0                   0
       0.100000000000000   0.200000000000000                   0                   0
       0.100000000000000                   0                   0   0.100000000000000
     
      Columns 157 through 160
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
                       0   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
       0.500000000000000                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000                   0   0.100000000000000   0.200000000000000
                       0   0.500000000000000   0.400000000000000   0.300000000000000
     
      Columns 161 through 164
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
       0.100000000000000   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0   0.400000000000000
       0.300000000000000   0.400000000000000   0.500000000000000                   0
       0.200000000000000   0.100000000000000                   0   0.100000000000000
     
      Columns 165 through 168
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
       0.100000000000000   0.100000000000000   0.200000000000000   0.200000000000000
                       0                   0                   0                   0
                       0   0.500000000000000                   0                   0
                       0                   0                   0                   0
       0.400000000000000                   0                   0                   0
       0.100000000000000                   0                   0   0.100000000000000
                       0                   0   0.400000000000000   0.300000000000000
     
      Columns 169 through 172
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
       0.200000000000000   0.200000000000000   0.200000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0   0.400000000000000
       0.200000000000000   0.300000000000000   0.400000000000000                   0
       0.200000000000000   0.100000000000000                   0                   0
     
      Columns 173 through 176
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
       0.300000000000000   0.300000000000000   0.300000000000000   0.300000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.300000000000000   0.200000000000000   0.100000000000000                   0
     
      Columns 177 through 180
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.400000000000000   0.400000000000000
       0.400000000000000   0.400000000000000   0.400000000000000   0.500000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000                   0
       0.200000000000000   0.100000000000000                   0   0.100000000000000
     
      Columns 181 through 184
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.400000000000000   0.400000000000000   0.800000000000000   0.800000000000000
       0.500000000000000   0.600000000000000                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000                   0                   0   0.100000000000000
                       0                   0   0.200000000000000   0.100000000000000
     
      Columns 185 through 188
     
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.800000000000000   0.800000000000000   0.800000000000000   0.800000000000000
                       0   0.100000000000000   0.100000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000                   0   0.100000000000000                   0
                       0   0.100000000000000                   0                   0
     
      Columns 189 through 192
     
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0   0.100000000000000   0.200000000000000   0.300000000000000
       0.500000000000000   0.400000000000000   0.300000000000000   0.200000000000000
     
      Columns 193 through 196
     
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.400000000000000   0.400000000000000
       0.400000000000000   0.500000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.100000000000000                   0
     
      Columns 197 through 200
     
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
                       0   0.100000000000000   0.100000000000000   0.100000000000000
                       0                   0                   0                   0
       0.500000000000000                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.100000000000000   0.200000000000000
                       0   0.400000000000000   0.300000000000000   0.200000000000000
     
      Columns 201 through 204
     
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.400000000000000                   0
       0.300000000000000   0.400000000000000                   0                   0
       0.100000000000000                   0                   0   0.300000000000000
     
      Columns 205 through 208
     
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
       0.200000000000000   0.200000000000000   0.200000000000000   0.300000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000   0.300000000000000                   0
       0.200000000000000   0.100000000000000                   0   0.200000000000000
     
      Columns 209 through 212
     
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0                   0                   0                   0
       0.300000000000000   0.300000000000000   0.400000000000000   0.400000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.100000000000000                   0
     
      Columns 213 through 216
     
                       0                   0                   0                   0
       0.500000000000000   0.500000000000000   0.500000000000000   0.500000000000000
                       0   0.400000000000000   0.400000000000000   0.400000000000000
       0.500000000000000                   0                   0   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.100000000000000                   0
                       0   0.100000000000000                   0                   0
     
      Columns 217 through 220
     
                       0   0.600000000000000   0.600000000000000   0.600000000000000
       1.000000000000000                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.100000000000000   0.200000000000000
                       0   0.400000000000000   0.300000000000000   0.200000000000000
     
      Columns 221 through 224
     
       0.600000000000000   0.600000000000000   0.600000000000000   0.600000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0   0.100000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0   0.400000000000000                   0
       0.300000000000000   0.400000000000000                   0                   0
       0.100000000000000                   0                   0   0.300000000000000
     
      Columns 225 through 228
     
       0.600000000000000   0.600000000000000   0.600000000000000   0.600000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.100000000000000   0.100000000000000   0.200000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000   0.300000000000000                   0
       0.200000000000000   0.100000000000000                   0   0.200000000000000
     
      Columns 229 through 232
     
       0.600000000000000   0.600000000000000   0.600000000000000   0.600000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.200000000000000   0.200000000000000   0.300000000000000   0.300000000000000
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
                       0                   0                   0                   0
       0.100000000000000   0.200000000000000                   0   0.100000000000000
       0.100000000000000                   0   0.100000000000000                   0
     
      Columns 233 through 234
     
       0.600000000000000   0.600000000000000
                       0                   0
                       0   0.400000000000000
       0.400000000000000                   0
                       0                   0
                       0                   0
                       0                   0
                       0                   0
                       0                   0
                       0                   0
    Peut-être m'orienter vers une approche tabulaire comme le suggère kmaniche... Je vais faire des tests...
    Au taf : Quad Core/8Go de RAM sous Win Seven 64 - Matlab 2009b 64bit.
    Perso : Core 2 Duo/8Go de RAM Mac OS X 10.6 - Matlab 2009b 64bit

  5. #5
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 52 884
    Points
    52 884
    Par défaut
    Citation Envoyé par HAL-9000 Voir le message
    Je m'explique : je possède entre 30 et 40 titres de poids initiaux définis (Titre 1 : 0% Titre 2 : 10% ... Titre 40 : 30%) ainsi que finaux (Titre 1 : 100% Titre 2 : 100% ... Titre 40 : 100%) et j'aimerai définir toutes les combinaisons possibles entre les poids selon un pas sur chaque titre...
    Par exemple un portefeuille de 2 titres A et B de poids initiaux (0%, 0%) et finaux (100%, 100%) avec les pas d'incréments (20%, 40%) me donne au final les vecteurs : (0%, 100%) (100%, 0%) (20%, 80%) (60% 40%)
    (sous la condition que la somme des poids est tjrs égale à 100%).
    Tu pourrais ré-expliquer

    Donne nous un cas concret avec des valeurs réelles sur 3 ou 4 titres et le résultat que tu souhaites obtenir en sortie
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 134
    Points : 129
    Points
    129
    Par défaut
    Citation Envoyé par Dut Voir le message
    Tu pourrais ré-expliquer

    Donne nous un cas concret avec des valeurs réelles sur 3 ou 4 titres et le résultat que tu souhaites obtenir en sortie
    Mon post juste au dessus par exemple, avec 10 titres... En fait je veux juste calculer toutes les combinansons possibles T1+T2+...+T10 = 1 selon les conditions initiales et finales de T1, ... , T10 et selon un pas d'incrément sur chaque T...

    En gros, sur 3 titres, conditions Tmin : T1 = 0, T2 = 0 et T3 = 0.
    Conditions Tmax : T1 = 1, T2 = 1 et T3 = 1. Pas de variation : T1 : de 0.1 en 0.1, T2 : de 0.2 en 0.2 et T3 de 0.5 en 0.5 (par exemple).

    Je veux calculer toutes les combinaisons (T1,T2,T3) satisfaisant T1+T2+T3=1... Pas sur d'être clair, si ?
    Au taf : Quad Core/8Go de RAM sous Win Seven 64 - Matlab 2009b 64bit.
    Perso : Core 2 Duo/8Go de RAM Mac OS X 10.6 - Matlab 2009b 64bit

  7. #7
    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
    Bonjour,

    Tout d'abord félicitations pour ton record de boucle for imbriquée! Moi, en tant que fan des boucles for, je n'ai jamais réussi à faire aussi bien!

    Pour ton problème, il est évident que si tu tests toutes les combinaisons, ton programme va ramer. Une première amélioration serait de faire des tests : dès que tu dépasses 1, pas la peine de continuer. Mais bon plutôt que de surcharger ton code, je te propose un autre point de vue : la récursivité. Cela permet de parcourir toute les combinaisons en imposant des conditions, mais au lieu d'écrire 50 boucles, tu ne fait qu'une seule fonction.

    Voici un exemple sur le cas des 3 portefeuilles que tu as décrits (aussi fait à la va-vite, donc à toi de l'améliorer) :
    Le programme principal :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    t{1} = 0:0.1:1;
    t{2} = 0:0.2:1;
    t{3} = 0:0.5:1;
    resultattemporaire = [];
    resultat = [];
    resultat = allocation(t,resultattemporaire,resultat);
    Et la fonction récursive allocation :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    function resultat = allocation(t,resultattemporaire,resultat)
     
    indice = length(resultattemporaire)+1;
    for k=1:length(t{indice})
        if sum(resultattemporaire)+t{indice}(k)<=1 && indice<numel(t)
            resultattemporaire2 = [resultattemporaire t{indice}(k)];
            resultat = allocation(t,resultattemporaire2,resultat);
        elseif sum(resultattemporaire)+t{indice}(k)==1 && indice==numel(t)
            resultat = [resultat;[resultattemporaire t{indice}(k)]];
        end
    end
    Et j'obtiens ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    >> resultat
     
    resultat =
     
             0         0    1.0000
             0    1.0000         0
        0.1000    0.4000    0.5000
        0.2000    0.8000         0
        0.3000    0.2000    0.5000
        0.4000    0.6000         0
        0.5000         0    0.5000
        0.6000    0.4000         0
        0.8000    0.2000         0
        1.0000         0         0
    Je ne suis pas sûr que l'on ait besoin de 2 variables (resultattemporaire et resultat) mais c'est le seul moyen que j'ai trouvé.

    Pour ton cas initial, tu dois placer tous tes vecteurs dans un tableau de cellule, une seule boucle for devrait suffire.
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  8. #8
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 134
    Points : 129
    Points
    129
    Par défaut
    Un grand merci pour ta réponse magelan, c'est tout à fait ce que je recherchais...

    En fait je ne pensais pas que l'on pouvait utiliser une fonction à l'interieur de cette même fonction (dans ton exemple allocation)...
    Du coup cela aide beaucoup

    Pour la variable resultattemporaire j'en fais mon affaire...

    Encore merci
    Au taf : Quad Core/8Go de RAM sous Win Seven 64 - Matlab 2009b 64bit.
    Perso : Core 2 Duo/8Go de RAM Mac OS X 10.6 - Matlab 2009b 64bit

  9. #9
    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
    Citation Envoyé par HAL-9000 Voir le message
    En fait je ne pensais pas que l'on pouvait utiliser une fonction à l'interieur de cette même fonction (dans ton exemple allocation)...
    Du coup cela aide beaucoup
    C'est le principe des fonctions récursives (fait une recherche sur google, tu trouveras des exemples simples). Il faut juste faire attention à la condition d'arrêt sinon tu te retrouves avec une fonction qui s'appelle indéfiniment...
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  10. #10
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 134
    Points : 129
    Points
    129
    Par défaut
    Bon, petit retour sur la fonction ci-dessus

    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
    >> [Poids1, Pas, Poids2]
     
    ans =
     
                       0   0.010000000000000   0.015000000000000
       0.025000000000000   0.010000000000000   0.050000000000000
                       0   0.010000000000000   0.015000000000000
       0.005000000000000   0.010000000000000   0.030000000000000
       0.030000000000000   0.010000000000000   0.045000000000000
       0.030000000000000   0.010000000000000   0.045000000000000
       0.060000000000000   0.010000000000000   0.080000000000000
       0.005000000000000   0.010000000000000   0.025000000000000
                       0   0.010000000000000   0.015000000000000
       0.020000000000000   0.010000000000000   0.040000000000000
       0.005000000000000   0.010000000000000   0.025000000000000
       0.020000000000000   0.010000000000000   0.050000000000000
                       0   0.010000000000000   0.030000000000000
                       0   0.010000000000000   0.020000000000000
       0.005000000000000   0.010000000000000   0.020000000000000
                       0   0.010000000000000   0.020000000000000
       0.020000000000000   0.010000000000000   0.040000000000000
       0.020000000000000   0.010000000000000   0.040000000000000
       0.005000000000000   0.010000000000000   0.030000000000000
       0.005000000000000   0.010000000000000   0.030000000000000
                       0   0.010000000000000   0.020000000000000
       0.015000000000000   0.010000000000000   0.040000000000000
                       0   0.010000000000000   0.020000000000000
       0.010000000000000   0.010000000000000   0.030000000000000
                       0   0.010000000000000   0.020000000000000
                       0   0.010000000000000   0.020000000000000
                       0   0.010000000000000   0.020000000000000
       0.015000000000000   0.010000000000000   0.030000000000000
       0.015000000000000   0.010000000000000   0.030000000000000
       0.070000000000000   0.010000000000000   0.090000000000000
       0.015000000000000   0.010000000000000   0.030000000000000
       0.030000000000000   0.010000000000000   0.050000000000000
                       0   0.010000000000000   0.020000000000000
                       0   0.010000000000000   0.020000000000000
                       0   0.010000000000000   0.020000000000000
       0.110000000000000   0.010000000000000   0.130000000000000
       0.010000000000000   0.010000000000000   0.030000000000000
       0.005000000000000   0.010000000000000   0.030000000000000
       0.015000000000000   0.010000000000000   0.030000000000000
       0.015000000000000   0.010000000000000   0.030000000000000
     
    >> t = Poids(Poids1, Pas, Poids2); % Ici touts les pas calculés, sous forme de structure donc.
     
    >>resultattemporaire = [];
    resultat = [];
    resultat = allocation(t, resultattemporaire, resultat);
    Et bien cela fait une bonne heure de calcul, et ça calcul encore...
    Je ne sais pas si c'est plus efficace, in fine, que le morceau de code barbare du départ
    Au taf : Quad Core/8Go de RAM sous Win Seven 64 - Matlab 2009b 64bit.
    Perso : Core 2 Duo/8Go de RAM Mac OS X 10.6 - Matlab 2009b 64bit

  11. #11
    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
    Et c'est normal : imaginons que tes 31 vecteurs d'entrées soient de dimension 3, alors le nombre de combinaisons possibles est :
    3^31 = 6.1767e+14

    Ton premier programme aurait testé toutes ces combinaisons, celui que je t'ai donné réduit un peu le nombre de combinaions mais peut-être pas de beaucoup... le seul moyen de l'optimiser serait de trouver des conditions supplémentaires pour enlever des combinaisons... ou alors de l'écrire en C ou de trouver un algo plus rapide dans les algos de recherche dans un graphe
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  12. #12
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 134
    Points : 129
    Points
    129
    Par défaut
    Bon, la suite de cet épisode donc

    Sous mon Snow Leopard Mac OS X, avec la version Matlab R2009a 64bit j'ai essayé de transformer la fonction allocation.m en fonction C via la commande suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mcc -B csharedlib:allocation allocation.m
    La création des fichiers allocation.c, allocation_mcc_component_data.c, allocation.h etc. sont OK.
    Maintenant, quand j'essaie de créer un fichier .Mex correspondant, via la commande :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    >> mex allocation.c
     
    mex: link of '"allocation.mexmaci64"' failed.
    (j'ai bien Xcode d'installé)

    Une personne aurait une idée sur cette erreur ?
    Au taf : Quad Core/8Go de RAM sous Win Seven 64 - Matlab 2009b 64bit.
    Perso : Core 2 Duo/8Go de RAM Mac OS X 10.6 - Matlab 2009b 64bit

  13. #13
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 134
    Points : 129
    Points
    129
    Par défaut
    De mon coté j'ai decidé de passer sous C++ afin d'augmenter la vitesse de calcul de la fonction allocation puis de transformer la fonction en fichier MEX. Toutefois j'avoue avoir énormément de mal à encoder cette fonction récursive en C++. Si une personne pouvait m'apporter un début d'aide, je suis preneur...

    Merci à vous.
    Au taf : Quad Core/8Go de RAM sous Win Seven 64 - Matlab 2009b 64bit.
    Perso : Core 2 Duo/8Go de RAM Mac OS X 10.6 - Matlab 2009b 64bit

Discussions similaires

  1. Optimisation boucles pour calcul Quantiles
    Par popsmelove dans le forum R
    Réponses: 3
    Dernier message: 22/02/2012, 11h44
  2. Boucles for -> Calcul matriciel
    Par Sylvain_F dans le forum MATLAB
    Réponses: 8
    Dernier message: 19/01/2012, 16h40
  3. Optimisation Vitesse d'Exécution Calcul matriciel
    Par olivier21c dans le forum Langage
    Réponses: 33
    Dernier message: 02/09/2011, 11h46
  4. [MySQL] Calcul d'une somme dans une boucle VERSUS Calcul via la fonction MySQL SUM
    Par 2o1oo dans le forum PHP & Base de données
    Réponses: 17
    Dernier message: 13/10/2010, 09h32
  5. [Débutant] Remplacement boucle for pour calcul matriciel
    Par LoicS dans le forum MATLAB
    Réponses: 3
    Dernier message: 26/03/2009, 19h26

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