Advertisement
jacknpoe

Interpolação Forma de Lagrange

May 5th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. const int TAMANHO = 5;
  4. using namespace std;
  5.  
  6. int main( void)
  7. {
  8.     int l, j;
  9.     double x[ TAMANHO] = { -1,  0,  1,  2,  3 } ;
  10.     double y[ TAMANHO] = {  1,  1,  0, -1, -2 } ;
  11.     double p, acum_1, acum_2;
  12.  
  13.     p = 3.2;
  14.     acum_1 = 0;
  15.     for( l = 0; l < TAMANHO; l++)
  16.     {
  17.         acum_2 = 1;
  18.         for( j = 0; j < TAMANHO; j++)
  19.         {
  20.             if( j != l)
  21.             {
  22.                 acum_2 *= ( p - x[ j]);
  23.                 acum_2 /= ( x[ l] - x[ j]);
  24.             }
  25.         }
  26.         cout << "y" << l << "L" << l << ": " << y[ l] << ", " << acum_2 << endl ;
  27.         acum_2 *= y[ l];
  28.         acum_1 += acum_2;
  29.     }
  30.     cout << "Valor de p: " << acum_1;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement