La interpolación de Lagrange
Esta interpolación pasa por los puntosn+1 dados:
Para hallar la Interpolacion de Lagrange se tiene que seguir ciertas fórmulas, nosotros veremos un algoritmo en el cual no es necesario utilizar las fórmulas basta con lo siguiente:Ahora vemos como sería el código en C++:
?
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
#include
#include
void main(){
floatx[50],y[50],z,l, valor=0;
int n;
cout<<"ingrese el numero de elementos: "; cin>>n;
cout<<"ingrese x: ";
for(int i=0; i
}
cout<
}
cout<
for(int i=0; i
for(int j=0; j
}
}
valor=valor+l;
}
cout<
}
En Dev c++sería de la siguiente forma:
?
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
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
float x[50],y[50],z,l, valor=0;
int n;
cout<<"ingrese el numero de elementos: "; cin>>n;
cout<<"ingrese x: ";
for(int i=0; i
}
cout<
for(int i=0; i
}
cout<
cout<
for(int i=0; i
l=(l*(z-x[j]))/(x[i]-x[j]);
}
}
valor=valor+l;
}
cout<
Regístrate para leer el documento completo.