Lagrange interpolation formula in c++

  Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
         double x[1000], y[1000], xp,findpoint, yp=0,p,fxsum;
         int i,j,n;
         cout<<"Enter number of data: ";
         cin>>n;
         cout<<"Enter data:"<< endl;
         for(i=1;i<=n;i++)
         {
              cout<<"x["<< i<<"] = ";
              cin>>x[i];
              cout<<"y["<< i<<"] = ";
              cin>>y[i];
         }
         cout<<"Enter interpolation point: ";
         cin>>findpoint;
         //  Lagrange Interpolation implement
         for(i=1;i<=n;i++)
         {
              p=1;
              for(j=1;j<=n;j++)
              {
                   if(i!=j)
                   {
                        p = p* (findpoint - x[j])/(x[i] - x[j]);
                   }
              }
              fxsum=fxsum + p * y[i];
         }
         cout<< endl<<"  Interpolated value at  "<< findpoint<< "  is    "<< fxsum;

         return 0;
    }

    No comments

    Most View Post

    Recent post

    Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.