Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Para hallar la Interpolacion de Lagrange se tiene que seguir ciertas frmulas, nosotros veremos
un algoritmo en el cual no es necesario utilizar las frmulas basta con lo siguiente:
?
#include <cstdlib>
1 #include <iostream>
2
3 using namespace std;
4
5 int main(int argc, char *argv[])
6 {
7 float x[50],y[50],z,l, valor=0;
int n;
8
9 cout<<"ingrese el numero de elementos: "; cin>>n;
10 cout<<"ingrese x: ";
11
12 for(int i=0; i<n; i++){
13 cin>>x[i];
}
14
15 cout<<endl;
16 cout<<"ingrese y: ";
17 for(int i=0; i<n; i++){
18 cin>>y[i];
19
20 }
cout<<endl;
21
22 cout<<endl<<"ingrese z: "; cin>>z;
23
24 for(int i=0; i<n ;i++){
25 l=y[i];
26 for(int j=0; j<n; j++){
if(i!=j){
27
l=(l*(z-x[j]))/(x[i]-x[j]);
28 }
29 }
30 valor=valor+l;
}
31
32 cout<<endl<<endl<<"El valor al polinomio de interpolacion en Z = "<<z<<" es : "<
33 valor<<endl;
34
35
36 system("PAUSE");
37 return EXIT_SUCCESS;
38 }
39
40
41
42
43
(63)^(1/2) = 8* (1 - (1/64))^(1/2)
raiz(63) = 7.9372539...
8:.........................8.000000
1/16 :.................-0.0625000.......7.937...
1/64^2...............-0.000244...........
(1/2)(1/64^3)....-0.000002.........7.9...
etc