Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int silnia(int n)
  7. {
  8.     if(n<=1)
  9.         return 1;
  10.     else
  11.         return silnia(n-1)*n;
  12. }
  13.  
  14.  
  15. int main(int argc, char** argv) {
  16.     double x0=2.5;
  17.     double x[] = {1,2,3,4};
  18.     double y[] = {3,7,8,15};
  19.     double h=x[1]-x[0];
  20.     vector<double> wsp;
  21.     int n=4;
  22.     wsp.push_back(y[0]);
  23.     for(int i=0;i<(n-1);i++)
  24.     {
  25.         for(int j=0;j<(n-1-i);j++)
  26.            y[j]=y[j+1]-y[j];
  27.         wsp.push_back(y[0]);
  28.     }
  29.  
  30.     double l;
  31.     double s=0;
  32.     for(int i=0;i<wsp.size();i++)
  33.     {
  34.         l=1;
  35.         for(int j=0;j<i;j++)
  36.         {
  37.             l*=(x0-x[j]);
  38.         }
  39.         s+=wsp[i]*l/(silnia(i)*h);
  40.         h*=h;
  41.     }
  42.  
  43.     cout << "f(" << x0 << ") = " << s << endl;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement