Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int silnia(int n)
- {
- if(n<=1)
- return 1;
- else
- return silnia(n-1)*n;
- }
- int main(int argc, char** argv) {
- double x0=2.5;
- double x[] = {1,2,3,4};
- double y[] = {3,7,8,15};
- double h=x[1]-x[0];
- vector<double> wsp;
- int n=4;
- wsp.push_back(y[0]);
- for(int i=0;i<(n-1);i++)
- {
- for(int j=0;j<(n-1-i);j++)
- y[j]=y[j+1]-y[j];
- wsp.push_back(y[0]);
- }
- double l;
- double s=0;
- for(int i=0;i<wsp.size();i++)
- {
- l=1;
- for(int j=0;j<i;j++)
- {
- l*=(x0-x[j]);
- }
- s+=wsp[i]*l/(silnia(i)*h);
- h*=h;
- }
- cout << "f(" << x0 << ") = " << s << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement