ximothov  | Bonjour, voilà j'ai un programme a C à faire pour les cours, cependant j'ai un pu**** d'erreur et j'arrive vraiment pas a voir ou elle est   ca fait bien 1H que je suis dessus ca doit vraiment etre un truc a la con je pense  , je dois afficher des float et il me sort ca : Valeur de ty[49] : -1.#IND00, impossible de trouver  
   Si quelqu'un veut bien y jetter un coup d'oeil ca m'arrangerais   c'est la méthode d'interpolation de lagrange
  
  Code :
 - #include <stdio.h>
 - #define Nmax 50
 - #include <stdlib.h>
 - typedef float pivots[Nmax];
 - typedef float vect[5];
 - void lecture(int *pn, pivots pl);
 - float lag(int pn, pivots pX, pivots pY, float pal);
 - int maximum(int pn,pivots pY);
 - // Fonction Lecture //
 - void lecture (int *pn, pivots pl)
 - {
 - float a;   
 - int i;
 - i=0;
 - FILE *f1;
 - f1 = fopen("c:/rampe1.txt","r" );
 - if(f1==NULL)
 - {
 -    printf("Erreur de fichier\n" );
 -    exit(1);       
 - }
 - *pn=1;
 - while (!feof(f1))
 - {
 -       i++;
 -       fscanf(f1,"%f %f %f",&a,&a,pl+i);
 -       printf("%f\n",*(pl+i));
 -       *pn=*pn+1;
 -      
 - }
 - printf("Nombre de lignes : %d \n",*pn);
 - }
 
  |  
 
   
 ERREURS :   
  Code :
 - // Fonction lag //
 - float lag(int pn, pivots pX, pivots pY, float pal)
 - {
 - int i,j;
 - float L,x,som,pol;
 - pol=0;
 - for(i=0;i<pn;i++)
 - {
 -     L=1;
 -     x=1;
 -     for(j=0;j<pn;j++)
 -     {
 -      if(j!=i)
 -      {
 -      x= (pal-pX[j]) / (pX[i]-pX[j]);
 -      L=L*x;
 -      }
 -     }
 - som=L*pY[i]; 
 - pol=pol+som;
 - }
 - return(pol);
 - }
 
  |  
 
  Code :
 - // Fonction maximum //
 - int maximum(int pn,pivots pY)
 - {
 - int i,b;
 - float a;
 - a=pY[0];
 - for(i=1;i<pn;i++) 
 - {
 -  if(pY[i]>a)
 -  { a=pY[i]; b=i; }
 - }
 - return(b);
 - }
 - // Fonction main //
 - int main (void)
 - {
 - int a,b,i,c,g;
 - float tt;
 - pivots l,tx,ty;
 - pivots PivX={0,1,2,3,4};
 - lecture(&a,l);
 - b=maximum(a,l);
 - printf("\nNumero de ligne de la valeur max : %d \n",b+1);
 - //pivots PivY={l[b-2],l[b-1],l,l[b+1],l[b+2]};
 - pivots PivY={0,1,2,3,4};
 - tx[0]=0;
 - for(i=1;i<50;i++)
 - tx[i]=tx[i-1]+0.081632653061224489795918367346939;
 
  |  
 
   [b]Erreurs :
  
  Code :
 - for(g=0;g<50;g++)
 - {
 - tt=tx[g];
 - ty[g]=lag(a,PivX,PivY,tt);
 - printf("\nValeur de ty[%d] : %f ",g,ty[g]);
 - }
 
  |  
 
     Suite du programme
  Code :
 - c=maximum(a,ty);
 - printf("\nNouvelle valeur du max : %f ",ty[32]);
 - return(0);
 - }
 
  |  
 
     Désolé pour le pavé j'ai mis en gras la ou se situent les problemes, enfin je pense  , merci de votre aide    Message édité par gilou le 13-05-2008 à 20:07:39
  |