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;
} |
Partager