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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

    Powered by Blogger.