You are on page 1of 2

Sánchez Castillo Paola Elizabeth

Fernandez Mora Jose Enrique


Ángeles Cruz María Fernanda
Xinel Lorca Karla Mille
Samano Vargas Uriel

#define DIM 10
#include <stdio.h>
#include <stdlib.h>
#include "matriz.c"

double Lagrange (double x[DIM],double y[DIM],int n,double xint) {


int i,j;
double suma,prod;

suma= 0;
for (i= 0; i < n; i++)
{
prod= 1;
for (j= 0; j < n; j++)
if (j != i)
prod= prod * (xint-x[j])/(x[i]-x[j]);
suma= suma + y[i]*prod;
}
return suma;
}
main () {
char r;
int n;
double xint,yint,x[DIM],y[DIM];

// Entrada de datos: No. de puntos


do {
printf ("No. de puntos (MAX. %d): ", DIM);
scanf ("%d",&n);
if (n >= 2 && n <= DIM) break;
printf ("Valor invalido\n");
} while (1);
// Datos de la tabla
printf ("Valores de x\n");
leeVector (x,n);
printf ("Valores de y\n");
leeVector (y,n);
do {
printf ("Valor de x: ");
scanf ("%lf",&xint);
yint= Lagrange (x,y,n,xint);
printf ("Valor de y= %lf\n",yint);
printf ("Calcular otro valor (s/n): ");
fflush (stdin);
r= getchar ();
} while (r == 's');
// Proceso
// Salida o Resultados
}
Sánchez Castillo Paola Elizabeth
Fernandez Mora Jose Enrique
Ángeles Cruz María Fernanda
Xinel Lorca Karla Mille
Samano Vargas Uriel

double **memoriaMatriz (int n,int m) {

int i;

double **mat;
mat= (double **) calloc (n,sizeof (double *));
for (i= 0; i < n; i++)
mat[i]= (double *) calloc (m,sizeof (double));
return mat;
}
void leeMatriz (double **mat, int n, int m) {
int i,j;
for (i= 0; i < n; i++)
for (j= 0; j < m; j++) {
printf ("Elemento %d,%d: ",i+1,j+1);
scanf ("%lf",&mat[i][j]);
}
}
void imprimeMatriz (double **mat, int n, int m) {
int i,j;
for (i= 0; i < n; i++) {
for (j= 0; j < m; j++)
printf ("%lf\t",mat[i][j]);
printf ("\n");
}
}