0% found this document useful (0 votes)
6 views11 pages

Act 11

The document describes using Newton's and Lagrange's interpolation methods to find polynomial approximations. It contains code to calculate interpolation polynomials using matrices for Newton's method and products of differences for Lagrange. The code is run for sample x and y data and the results are printed.

Uploaded by

Janeth Bautista
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Act 11

The document describes using Newton's and Lagrange's interpolation methods to find polynomial approximations. It contains code to calculate interpolation polynomials using matrices for Newton's method and products of differences for Lagrange. The code is run for sample x and y data and the results are printed.

Uploaded by

Janeth Bautista
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

INTRODUCCIÓN:

NEWTON:
double[] x = { -5, -3, -0.7, 0.25, 2.1, 6, 7.46, 19.1, 15.5 };
double[] y = { 6, 5.3, 1.53, -2.7, 4, 9.1, 2.2, 3.5, 6.2 };
double[,] matriz = new double[9, 10];
double pivote, factor;
double x_0 = 6.574;
double y_0 = 0;

for (int i = 0; i < 9; i = i + 1)


{
for (int j = 0; j < 9; j = j + 1)
{
matriz[i, j] = Math.Pow(x[i], j);
}
}
for (int i = 0; i < 9; i = i + 1)
{
matriz[i, 9] = y[i];
}
//Eliminación Gaussiana
//------------------------------
for (int reng = 0; reng < 9; reng = reng + 1)
{
pivote = matriz[reng, reng];
for (int colu = 0; colu < 10; colu = colu + 1)
{
matriz[reng, colu] = matriz[reng, colu] / pivote;
}
for (int reng_elimi = 0; reng_elimi < 9; reng_elimi = reng_elimi + 1)
{
if (reng_elimi != reng)
{
factor = matriz[reng_elimi, reng];
for (int colu_elimi = 0; colu_elimi < 10; colu_elimi = colu_elimi + 1)
{
matriz[reng_elimi, colu_elimi] = matriz[reng_elimi, colu_elimi]
- factor * matriz[reng, colu_elimi];
}
}
}
}
//------------------------------
for (int i = 0; i < 9; i = i + 1)
{
y_0 = y_0 + matriz[i, 9] * Math.Pow(x_0, i);
}

Console.WriteLine("El valor de y en " + x_0 + " es " + y_0);


Console.ReadLine();
RESULTADO:
PASOS:

LAGRANGE:
double[] x = { -5, -3, -0.7, 0.25, 2.1, 6, 7.46, 19.1, 15.5 };
double[] y = { 6, 5.3, 1.53, -2.7, 4, 9.1, 2.2, 3.5, 6.2 };
double[] l = new double[9];
double x_0 = 6.574;
double y_0 = 0;

for (int i = 0; i < 9; i = i + 1)


{
l[i] = 1;
for (int j = 0; j < 9; j = j + 1)
{
if (i != j)
{
l[i] = l[i] * ((x_0 - x[j]) / (x[i] - x[j]));
}
}
y_0 = y_0 + l[i] * y[i];
}
Console.WriteLine("El valor de y en " + x_0 + " es " + y_0);
Console.ReadLine();

PASOS:
Part3:
for (double n = -5; n <= 32; n += 0.4)
{
double[] x = { -5, -3, -0.7, 0.25, 2.1, 6, 7.46, 19.1, 15.5 };
double[] y = { 6, 5.3, 1.53, -2.7, 4, 9.1, 2.2, 3.5, 6.2 };
double[,] matriz = new double[9, 10];
double pivote, factor;
double x_0 = n;
double y_0 = 0;

for (int i = 0; i < 9; i++)


{
for (int j = 0; j < 9; j++)
{
matriz[i, j] = Math.Pow(x[i], j);
}
}
for (int i = 0; i < 9; i++)
{
matriz[i, 9] = y[i];
}
//Eliminación Gaussiana
//------------------------------
for (int reng = 0; reng < 9; reng++)
{
pivote = matriz[reng, reng];
for (int colu = 0; colu < 10; colu++)
{
matriz[reng, colu] /= pivote;
}
for (int reng_elimi = 0; reng_elimi < 6; reng_elimi++)
{
if (reng_elimi != reng)
{
factor = matriz[reng_elimi, reng];
for (int colu_elimi = 0; colu_elimi < 10; colu_elimi++)
{
matriz[reng_elimi, colu_elimi] -= factor * matriz[reng, colu_elimi];
}
}
}
}
//------------------------------
for (int i = 0; i < 9; i++)
{
y_0 += matriz[i, 9] * Math.Pow(x_0, i);
}

Console.WriteLine("El valor de y en " + x_0 + " es " + y_0);


}
Console.ReadLine();
PASOS:

CONCLUSIÓN:

You might also like