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 :

Incertitude programmation Lagrange.


Sujet :

C

  1. #1
    Invité
    Invité(e)
    Par défaut Incertitude programmation Lagrange.
    Bonjour,

    J'ai un exercice à faire et j'aimerais savoir si il est juste. Voici l'énoncé :

    http://www.noelshack.com/2022-15-2-1...-modele-un.png

    Je dois également calculer l'erreur (en pour cent) commise par le polynôme d'interpolation pour les fonctions
    f(x) et g(x) en Alpha_1 et Alpha_2 mais je ne sais pas comment faire.

    Ce que j'ai fait :

    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
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
     
    typedef points[Nmax];
    void lire(points data, points x, points y1, points y2, int *n);
    float lagrange(float al, points x, points y, int n);
     
    void lire(points data, points x, points y1, points y2, int *pn){
     
    int lig;
    FILE *pfic; 
    pfic=fopen("exo1.txt", "r");
    lig=0;
    while(!feof(pfic))                         //on continue a lire tant qu'on n'est pas a la fin du ficher, ce qui fait que le nbr d'elements augmente
    {
    fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
    lig ++;
    }
    *pn=lig; //on renvoit le nombre d'elements dans le pointeur n
    }
     
    float lagrange(float al, points x, points y, int n){
     
    float S, L;
    int k, i;
    S=0;
    for (k=0;k<=n;k++){                       // calcul de la somme avec k varie, Lk pour un k donne
    	L=1;
    	if(i!=k)
    		for (i=1; i<=n; i++){                    // ici seul le i varie et commence evidement en un
    			L=L*(((al)-x[i])/(x[k]-x[i])); 
    		}
    		S=S+L*y[k];
    }
    return S;
    }
     
    int main(void){
     
    points[Nmax];
    int Nmax = 10;
    float poly;
    points data, x, y, y1, y2;
    int n;
     
    lire(data, x, y1, y2, n);
    printf("%d", n);
    poly=lag(data[1], x, y, n); //on prend le alpha 1 dans la premiere colonne puisque rien ne doit etre saisi au clavier dans le programme
     
    return 0;
    }
    Fichiers attachés Fichiers attachés
    Dernière modification par Invité ; 12/04/2022 à 19h39. Motif: Ajout des balises [CODE] mon code [/CODE] (bouton #)

  2. #2
    Membre expérimenté Avatar de edgarjacobs
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    623
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 623
    Points : 1 554
    Points
    1 554
    Par défaut
    Hello,

    Avec gcc et les options -Wall -Wextra et -Wunused, voici les nombreuses erreurs qu'on obtient:
    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
     
    ex1.c:5:16: error: 'Nmax' undeclared here (not in a function)
     typedef points[Nmax];
                    ^~~~
    ex1.c:5:9: warning: type defaults to 'int' in declaration of 'points' [-Wimplicit-int]
     typedef points[Nmax];
             ^~~~~~
    ex1.c:6:18: warning: type defaults to 'int' in declaration of 'data' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *n);
                      ^~~~
    ex1.c:6:31: warning: type defaults to 'int' in declaration of 'x' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *n);
                                   ^
    ex1.c:6:41: warning: type defaults to 'int' in declaration of 'y1' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *n);
                                             ^~
    ex1.c:6:52: warning: type defaults to 'int' in declaration of 'y2' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *n);
                                                        ^~
    ex1.c:7:33: warning: type defaults to 'int' in declaration of 'x' [-Wimplicit-int]
     float lagrange(float al, points x, points y, int n);
                                     ^
    ex1.c:7:43: warning: type defaults to 'int' in declaration of 'y' [-Wimplicit-int]
     float lagrange(float al, points x, points y, int n);
                                               ^
    ex1.c:9:18: warning: type defaults to 'int' in declaration of 'data' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *pn){
                      ^~~~
    ex1.c:9:31: warning: type defaults to 'int' in declaration of 'x' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *pn){
                                   ^
    ex1.c:9:41: warning: type defaults to 'int' in declaration of 'y1' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *pn){
                                             ^~
    ex1.c:9:52: warning: type defaults to 'int' in declaration of 'y2' [-Wimplicit-int]
     void lire(points data, points x, points y1, points y2, int *pn){
                                                        ^~
    ex1.c: In function 'lire':
    ex1.c:17:34: error: subscripted value is neither array nor pointer nor vector
     fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
                                      ^
    ex1.c:17:43: error: subscripted value is neither array nor pointer nor vector
     fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
                                               ^
    ex1.c:17:54: error: subscripted value is neither array nor pointer nor vector
     fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
                                                          ^
    ex1.c:17:49: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
                                                     ^
    ex1.c:17:64: error: subscripted value is neither array nor pointer nor vector
     fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
                                                                    ^
    ex1.c:17:59: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
                                                               ^
    ex1.c:17:69: error: expected ';' before ')' token
     fscanf(pfic, "%f %f %f %f", &data[lig], &x[lig]), &y1[lig], &y2[lig]);
                                                                         ^
    ex1.c:17:69: error: expected statement before ')' token
    ex1.c:9:18: warning: parameter 'data' set but not used [-Wunused-but-set-parameter]
     void lire(points data, points x, points y1, points y2, int *pn){
                      ^~~~
    ex1.c:9:31: warning: parameter 'x' set but not used [-Wunused-but-set-parameter]
     void lire(points data, points x, points y1, points y2, int *pn){
                                   ^
    ex1.c:9:41: warning: parameter 'y1' set but not used [-Wunused-but-set-parameter]
     void lire(points data, points x, points y1, points y2, int *pn){
                                             ^~
    ex1.c:9:52: warning: parameter 'y2' set but not used [-Wunused-but-set-parameter]
     void lire(points data, points x, points y1, points y2, int *pn){
                                                        ^~
    ex1.c: At top level:
    ex1.c:23:33: warning: type defaults to 'int' in declaration of 'x' [-Wimplicit-int]
     float lagrange(float al, points x, points y, int n){
                                     ^
    ex1.c:23:43: warning: type defaults to 'int' in declaration of 'y' [-Wimplicit-int]
     float lagrange(float al, points x, points y, int n){
                                               ^
    ex1.c: In function 'lagrange':
    ex1.c:32:16: error: subscripted value is neither array nor pointer nor vector
        L=L*(((al)-x[i])/(x[k]-x[i]));
                    ^
    ex1.c:32:23: error: subscripted value is neither array nor pointer nor vector
        L=L*(((al)-x[i])/(x[k]-x[i]));
                           ^
    ex1.c:32:28: error: subscripted value is neither array nor pointer nor vector
        L=L*(((al)-x[i])/(x[k]-x[i]));
                                ^
    ex1.c:30:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
      if(i!=k)
      ^~
    ex1.c:34:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
       S=S+L*y[k];
       ^
    ex1.c:34:10: error: subscripted value is neither array nor pointer nor vector
       S=S+L*y[k];
              ^
    ex1.c:23:33: warning: parameter 'x' set but not used [-Wunused-but-set-parameter]
     float lagrange(float al, points x, points y, int n){
                                     ^
    ex1.c:23:43: warning: parameter 'y' set but not used [-Wunused-but-set-parameter]
     float lagrange(float al, points x, points y, int n){
                                               ^
    ex1.c: In function 'main':
    ex1.c:41:7: error: expected identifier or '(' before '[' token
     points[Nmax];
           ^
    ex1.c:44:8: warning: type defaults to 'int' in declaration of 'data' [-Wimplicit-int]
     points data, x, y, y1, y2;
            ^~~~
    ex1.c:44:14: warning: type defaults to 'int' in declaration of 'x' [-Wimplicit-int]
     points data, x, y, y1, y2;
                  ^
    ex1.c:44:17: warning: type defaults to 'int' in declaration of 'y' [-Wimplicit-int]
     points data, x, y, y1, y2;
                     ^
    ex1.c:44:20: warning: type defaults to 'int' in declaration of 'y1' [-Wimplicit-int]
     points data, x, y, y1, y2;
                        ^~
    ex1.c:44:24: warning: type defaults to 'int' in declaration of 'y2' [-Wimplicit-int]
     points data, x, y, y1, y2;
                            ^~
    ex1.c:47:23: warning: passing argument 5 of 'lire' makes pointer from integer without a cast [-Wint-conversion]
     lire(data, x, y1, y2, n);
                           ^
    ex1.c:9:6: note: expected 'int *' but argument is of type 'int'
     void lire(points data, points x, points y1, points y2, int *pn){
          ^~~~
    ex1.c:49:6: warning: implicit declaration of function 'lag' [-Wimplicit-function-declaration]
     poly=lag(data[1], x, y, n); //on prend le alpha 1 dans la premiere colonne puisque rien ne doit etre saisi au clavier dans le programme
          ^~~
    ex1.c:49:14: error: subscripted value is neither array nor pointer nor vector
     poly=lag(data[1], x, y, n); //on prend le alpha 1 dans la premiere colonne puisque rien ne doit etre saisi au clavier dans le programme
                  ^
    ex1.c:43:7: warning: variable 'poly' set but not used [-Wunused-but-set-variable]
     float poly;
           ^~~~
    ex1.c:42:5: warning: unused variable 'Nmax' [-Wunused-variable]
     int Nmax = 10;
         ^~~~
    Avant de demander si un code est correct, il faudrait qu'il passe le cap de la compilation et du link.
    On écrit "J'ai tort" ; "tord" est la conjugaison du verbre "tordre" à la 3ème personne de l'indicatif présent

  3. #3
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 687
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 687
    Points : 30 977
    Points
    30 977
    Billets dans le blog
    1
    Par défaut
    Bonjour

    Déjà commence par indenter correctement ton code car là il est totalement illisible. Accessoirement ça ne te dérange pas d'utiliser Nmax avant de l'avoir créé?

    Ensuite on n'utilise pas feof() pour détecter une fin de fichier parce que feof() n'est activé qu'après que le fichier ait été lu, pas pendant.

    Et enfin un pourcentage c'est un rapport de proportionnalité. Si tu as une valeur de x pour y alors le pourcentage consiste à calculer la valeur qu'aurait ce "x" proportionnellement à 100. Pour ça, on le divise par "y" ce qui donne alors le rapport de "x" à 1 ; puis on le multiplie par 100 pour monter ce rapport à 100 d'où le nom "pourcentage" => "pour cent".
    Et cette formule p=x/y*100 (que les règles de calculs à opérateurs de rang égal permettent alors d'écrire aussi p=x*100/y) est nommée "quatrième de proportionnelle" appelée plus communément "règle de trois".
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

Discussions similaires

  1. Algorithme et programme de Lagrange (MATLAB)
    Par TGV6975 dans le forum MATLAB
    Réponses: 6
    Dernier message: 24/05/2009, 21h18
  2. Programme de boot qui passe la main à Windows
    Par Bob dans le forum Assembleur
    Réponses: 7
    Dernier message: 25/11/2002, 03h08
  3. [Kylix] Probleme d'execution de programmes...
    Par yopziggy dans le forum EDI
    Réponses: 19
    Dernier message: 03/05/2002, 14h50
  4. [Kylix] icone associée à un programme
    Par Anonymous dans le forum EDI
    Réponses: 1
    Dernier message: 22/03/2002, 09h43

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