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

 C Discussion :

Votre avis pour améliorer mon code (opérations matricielles)


Sujet :

C

  1. #41
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2010
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 42
    Points : 21
    Points
    21
    Par défaut
    Bonjour,

    Merci pour ta réponse, j'avoue qu'au départ je ne m'étais pas penché à fond sur la technique mathématique, mon but était surtout de m'exercer à la programmation matriciel et a la gestion des pointeurs et de l'allocation dynamique, ce que j'ai pu faire au travers de ces différent codes.

    Pour ce qui est de la méthode des moindre carré, je vais surement en fin de compte l'exporter vers un projet codé en python (langage que j'ai découvert entre temps), ce qui me permettra une utilisation plus facile pour tout ce qui est fenêtre graphique et visualisation des courbes.

    Merci en tout cas pour tes remarques que je vais étudier dès que je me relancerais dans ce projet.

  2. #42
    Membre confirmé
    Homme Profil pro
    amateur
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : amateur

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 460
    Points
    460
    Par défaut
    Salut, je me permets d'ajouter ce que j'avais fais sur les matrices si cela peut t'aider où t'inspirer.

    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
    #include<stdio.h>
    #include<stdlib.h>
    #include<windows.h>
     
     
    void   Allouer_Matrice               ( int ***Matrice, int Colonne, int Ligne                                                                  );
    void   Sommer_Matrice                ( int **Matrice, int **Matrice_A, int **Matrice_B, int Ligne, int Colonne                                 );
    void   Soustraire_Matrice            ( int **Matrice, int **Matrice_A, int **Matrice_B, int Ligne, int Colonne                                 );
    void   Initialiser_Matrice           ( int **Matrice, int Ligne, int Colonne, int Valeur                                                       );
    void   Remplir_Matrice_Aleatoirement ( int **Matrice, int Ligne, int Colonne, int OFFSET, int Valeur                                           );
    void   Multiplier_Matrice            ( int **Matrice, int **Matrice_A, int **Matrice_B, int Ligne_A, int Colonne_A, int Ligne_B, int Colonne_B );
    void   Multiplier_Matrice_Constante  ( int Constante, int **Matrice, int Ligne, int Colonne                                                    );
    void   Afficher_Matrice              ( int **Matrice, int Ligne, int Colonne                                                                   );
    void   Desallouer_Matrice            ( int **Matrice, int Colonne                                                                              );
    int    Sont_Multipliables            ( int Colonne_A, int Ligne_B                                                                              );
     
    int main (void)
    {
        int **MatriceA=NULL;
        int **MatriceB=NULL;
        int **Matrice =NULL;
     
        Allouer_Matrice( &MatriceA, 7, 4 );
        Allouer_Matrice( &MatriceB, 4, 7 );
        Allouer_Matrice( &Matrice , 4, 4 );
     
        Remplir_Matrice_Aleatoirement( MatriceA, 7, 4, 5, 10 );
        Remplir_Matrice_Aleatoirement( MatriceB, 4, 7, 5, 10 );
     
        Initialiser_Matrice          ( Matrice , 4, 4, 0     );
     
        printf("\n\n///////////////////MATRICE A///////////////////\n");
        Afficher_Matrice( MatriceA, 4, 4 );
        printf("\n\n///////////////////MATRICE B///////////////////\n");
        Afficher_Matrice( MatriceB, 4, 4 );
     
        Sommer_Matrice( Matrice, MatriceA, MatriceB, 4, 4 );
        printf("\n\n/////////////////MATRICE SOMMEE////////////////\n");
        Afficher_Matrice( Matrice, 4, 4 );
     
        Soustraire_Matrice( Matrice, MatriceA, MatriceB, 4, 4 );
        printf("\n\n///////////////MATRICE SOUSTRAITE//////////////\n");
        Afficher_Matrice( Matrice, 4, 4 );
     
        Multiplier_Matrice( Matrice, MatriceA, MatriceB, 4, 4, 4, 4 );
        printf("\n\n///////////////MATRICE MULTIPLIEE//////////////\n");
        Afficher_Matrice( Matrice, 4, 4 );
     
        Multiplier_Matrice_Constante( 2, MatriceA, 4, 4 );
        printf("\n\n//////////MATRICE MULTIPLIEE CONSTANTE/////////\n");
        Afficher_Matrice( MatriceA, 4, 4 );
     
        Desallouer_Matrice( MatriceA, 4 );
        Desallouer_Matrice( MatriceB, 4 );
        Desallouer_Matrice( Matrice,  5 );
     
        getchar();
     
    }
     
    void Allouer_Matrice(int ***Matrice, int Ligne, int Colonne)
    {
            if ( Matrice != NULL )
                 {
                      int i=0;
     
                      // Allouer les colonnes
                      *Matrice = (int **)malloc( Ligne*sizeof(int*) );
     
                      // Allouer les lignes
                      for ( i=0 ; i<Ligne ; i++)
                          {
                             (*Matrice)[i]=(int *)malloc( Colonne*sizeof(int) );
                          }
                 }
    }
     
    void Initialiser_Matrice(int **Matrice, int Ligne, int Colonne, int Valeur)
    {
     
         if ( Matrice != NULL )
            {
                 int i, j;
                 for ( i=0 ; i<Ligne ; i++ )
                     {
                           for ( j=0 ; j<Colonne ; j++ )
                               {
                                    Matrice[i][j]=Valeur;
                               }
                     }
            }
     
        else printf("\n\nERREUR DANS LA FONCTION Initialiser_Matrice\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEE\n\n");
    }
     
    void Remplir_Matrice_Aleatoirement(int **Matrice, int Ligne, int Colonne, int OFFSET, int Valeur)
    {
         if ( Matrice != NULL )
            {
                 int i, j;
                 for ( i=0 ; i<Ligne ; i++ )
                     {
                           for ( j=0 ; j<Colonne ; j++ )
                               {
                                    Matrice[i][j]=OFFSET + rand()%(Valeur+1);
                               }
                     }
            }
     
        else printf("\n\nERREUR DANS LA FONCTION Remplir_Matrice_Aleatoirement\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEE\n\n");
    }
     
    void Sommer_Matrice( int **Matrice, int **Matrice_A, int **Matrice_B, int Ligne, int Colonne)
    {
         if ( Matrice !=NULL && Matrice_A != NULL && Matrice_B != NULL )
            {
                 int i,j;
                 for ( i=0 ; i<Ligne ; i++ )
                     {
                         for ( j=0 ; j<Colonne ; j++ )
                             {
                                 Matrice[i][j]=Matrice_A[i][j]+Matrice_B[i][j];
                             }
                     }
            }
     
        else printf("\n\nERREUR DANS LA FONCTION Sommer_Matrice\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEE\n\n");
    }
     
    void Soustraire_Matrice( int **Matrice, int **Matrice_A, int **Matrice_B, int Ligne, int Colonne)
    {
         if ( Matrice !=NULL && Matrice_A != NULL && Matrice_B != NULL )
            {
                 int i,j;
                 for ( i=0 ; i<Ligne ; i++ )
                     {
                         for ( j=0 ; j<Colonne ; j++ )
                             {
                                 Matrice[i][j]=Matrice_A[i][j]-Matrice_B[i][j];
                             }
                     }
            }
     
         else printf("\n\nERREUR DANS LA FONCTION Soustraire_Matrice\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEE\n\n");
    }
     
    void Afficher_Matrice(int **Matrice, int Ligne, int Colonne)
    {
        if ( Matrice != NULL )
           {
                int i, j;
                for ( i=0 ; i<Ligne ; i++ )
                    {
                          for ( j=0 ; j<Colonne ; j++)
                              {
                                    printf("\nMatrice[%d][%d]=%d", i+1, j+1, Matrice[i][j]);
                              }
                    }
           }
     
        else printf("\n\nERREUR DANS LA FONCTION Afficher_Matrice\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEE\n\n");
    }
     
     
    void Desallouer_Matrice( int **Matrice, int Colonne )
    {
        if ( Matrice != NULL )
           {
                int i;
                for ( i=1 ; i<Colonne ; i++ )
                   {
                         free(Matrice[i]);
                   }
     
                free(Matrice);
           }
     
        else printf("\n\nERREUR DANS LA FONCTION Desallouer_Matrice\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEEn\n");
    }
     
    int Sont_Multipliables( int Colonne_A, int Ligne_B )
    {
        if ( Colonne_A == Ligne_B )
           {
                       return 1;
           }
     
        else return 0;
    }
     
    void Multiplier_Matrice( int **Matrice, int **Matrice_A, int **Matrice_B, int Ligne_A, int Colonne_A, int Ligne_B, int Colonne_B )
    {
         if ( Matrice != NULL && Matrice_A != NULL && Matrice_B != NULL && Sont_Multipliables( Colonne_A, Ligne_B ) == 1 )
            {
                int i,j;
                int Repeter=0;
                for ( i=0 ; i<Ligne_A ; i++ )
                 {
                     for ( j=0 ; j<Colonne_B ; j++ )
                         {
                             while ( Repeter != Colonne_A )
                                   {
                                             Matrice[i][j]=Matrice[i][j]+ Matrice_A[i][Repeter]*Matrice_B[Repeter][j];
                                             Repeter++;
                                   }
                             Repeter=0;
                         }
                 }
             }
     
         else printf("\n\nERREUR DANS LA FONCTION Multiplier_Matrice\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEE\n   + LES DIMENSIONS DES MATRICES NE SONT PAS COMPATIBLES POUR LA MULTIPLICATION\n\n");
    }
     
    void Multiplier_Matrice_Constante( int Constante, int **Matrice, int Ligne, int Colonne )
    {
           if ( Matrice != NULL )
              {
                        int i;
                        for ( i=0 ; i<Ligne ; i++ )
                            {
                                  int j;
                                  for ( j=0 ; j<Colonne ; j++ )
                                      {
                                            Matrice[i][j]=Constante*Matrice[i][j];
                                      }
                            }
              }
     
           else printf("\n\nERREUR DANS LA FONCTION Multiplier_Matrice_Constante\n   + VERIFIEZ QUE MATRICE EST CORRECTEMENT REFERENCEE\n\n");
    }

  3. #43
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2010
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 42
    Points : 21
    Points
    21
    Par défaut
    Merci c'est sympa !

Discussions similaires

  1. [Débutant] idée pour améliorer mon code ?
    Par Imène_23 dans le forum MATLAB
    Réponses: 7
    Dernier message: 27/08/2011, 23h54
  2. avis pour améliorer mon cv
    Par Nath_k dans le forum CV
    Réponses: 4
    Dernier message: 20/09/2009, 12h45
  3. Réponses: 30
    Dernier message: 05/08/2009, 19h25
  4. [CV] Avis pour améliorer mon cv
    Par lapanne dans le forum CV
    Réponses: 7
    Dernier message: 17/10/2007, 15h04
  5. Réponses: 4
    Dernier message: 26/04/2006, 14h36

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