Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. double NewtonCotes(double a,double b, int n)
  2. {
  3. double Bk = 2.0/45;
  4. double h=(b-a)/n;
  5. double res=0;
  6. vector <double> coef(n+1,0);
  7. coef[0] = 7;
  8. coef[1] = 32;
  9. coef[2] = 12;
  10. coef[3] = 32;
  11. coef[4] = 7;
  12. for(int i=0;i<=n;++i)
  13. {
  14. res+=(func(a+i*h))*Bk*coef[i]*h;
  15. }
  16. return res;
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement