Advertisement
sajid161

lagrang

Feb 29th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. double x[100];
  4. double y[100];
  5. double f(int p,int y,double x1)
  6. {
  7. double temp=1;
  8. for(int i=0;i<y;i++)
  9. {
  10. if(i!=p)
  11. {
  12. temp*=(x1-x[i]);
  13. }
  14.  
  15. }
  16. return temp;
  17. }
  18. double g(int s,int n)
  19. {
  20. double q=x[s],temp=1;
  21.  
  22. for(int i=0;i<n;i++)
  23. {
  24. if(i!=s)
  25. {
  26. temp*=(q-x[i]);
  27. }
  28. }
  29. return temp;
  30. }
  31. int main()
  32. {
  33. int n;
  34. double x1,sum=0;
  35. cout<<"enter the total value of x and y:";
  36. cin>>n;
  37.  
  38. for(int i=0;i<n;i++)
  39. { cout<<"enter the element of x:";
  40. cin>>x[i];
  41. cout<<"enter the element of y:";
  42. cin>>y[i];
  43.  
  44. }
  45. cout<<"enter the desired value:";
  46. cin>>x1;
  47. for(int i=0;i<n;i++)
  48. {
  49.  
  50. sum+=(f(i,n,x1)*y[i])/g(i,n);
  51.  
  52. }
  53. cout<<sum;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement