/* Programa de Interpolacion_Lagrange */ #include #include float X[10]; float Fx[10]; int N; float Xinc; int k,j,i; float Multi; float Sum; int Lee_Datos(); /* PROGRAMA PRINCIPAL */ int main(void) { clrscr(); printf("\n METODO DE INTERPOLACIONDE LAGRANGE "); printf("\n=================================================="); N=Lee_Datos(); Sum =0; printf("\n Resultados del desarrollo:"); printf("\n i Multi Fx[i]"); printf("\n--------------------------------"); for (i = 0;i <= N ;i++) { Multi=1; for (j=0;j <= N; j++) { if (j != i) Multi = Multi * ( (Xinc - X[j]) / (X[i] - X[j]) ); } Sum += Multi * Fx[i]; printf("\n%4d %10.4f %10.4f %10.4f",i,Multi,Fx[i],Multi*Fx[i]); } printf("\n--------------------------------------"); printf("\n Para X= %10.4f La Fx es =>%10.4f",Xinc,Sum); getche(); } int Lee_Datos() { printf("\n Grado del Polinomio ="); scanf("%d",&N); printf("\n Valor a interpolar =>"); scanf("%f",&Xinc); printf("\n"); printf("\n Valores Tabulados "); printf("\n--------------------------------"); printf("\n i X Fx"); printf("\n--------------------------------"); X[0] = 20; Fx[0]= 103; X[1] = 25; Fx[1]= 107; X[2] = 30; Fx[2]= 112; X[3] = 35; Fx[3]= 116; for (k=0; k <=N ; k++) { printf("\n%d %10.4f | %10.4f",k,X[k],Fx[k]); } printf("\n--------------------------------"); return N; }