Advertisement
jacknpoe

Interpolação Forma de Newton

May 5th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale.h>
  3.  
  4. const int TAMANHO = 5;
  5. using namespace std;
  6.  
  7. int main( void)
  8. {
  9.     int l, j;
  10.     double x[ TAMANHO] = { -1,  0,  1,  2,  3 } ;
  11.     double y[ TAMANHO] = {  1,  1,  0, -1, -2 } ;
  12.     double tabela[ TAMANHO][ TAMANHO];
  13.     double p, acum_1, acum_2;
  14.  
  15.  
  16.     setlocale( LC_ALL, "");     // equal caracters in prompt
  17.  
  18.     // MONTA A TABELA
  19.     // primeiro copia os y para a ordem 0
  20.     for( l = 0; l < TAMANHO; l++)
  21.     {
  22.         tabela[ 0][ l] = y[ l];
  23.     }
  24.  
  25.     // calcula os deltas
  26.     for( l = 1; l < TAMANHO; l++)
  27.     {
  28.         for( j = 0; j < ( TAMANHO - l); j++)
  29.         {
  30.             tabela[ l][ j] = ( tabela[ l-1][ j+1] - tabela[ l-1][ j] ) / ( x[ j+l] - x[ j] );
  31.         }
  32.     }
  33.  
  34.     // calcula as somatórias
  35.     p = 3.2;
  36.     acum_1 = 0;
  37.     for( l = 0; l < TAMANHO; l++)
  38.     {
  39.         acum_2 = 1;
  40.         for( j = 0; j < l; j++)
  41.         {
  42.             acum_2 *= ( p - x[ j]);
  43.         }
  44.         cout << "Delta" << l << ": " << tabela[ l][ 0] << ", polinômio: " << acum_2 << endl ;
  45.         acum_2 *= tabela[ l][ 0];
  46.         acum_1 += acum_2;
  47.     }
  48.     cout << "Valor de p: " << acum_1;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement