Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- inline double f(const double x, const double a, const double b) {
- return (1-cos(b*x))/(x*x)*exp(-a*x);
- }
- const double pi = acos(-1.0);
- int main() {
- const double a = 0.5, b = 0.4;
- const double h = 0.01;
- const int N = 10000000;
- double s = 0.5 + 4*f(h, a, b) + f(2*h, a, b);
- double s2 = 0.5 + f(2*h, a, b);
- double x = 2*h;
- for (int i = 1; i < N; ++i) {
- s2 += f(x, a, b);
- s += f(x, a, b);
- x += h;
- s += 4*f(x, a, b);
- x += h;
- s += f(x, a, b);
- s2 += f(x, a, b);
- }
- cout << s * h / 3 << " ?= " << " ?= " << s2 * h
- << " ?= (formula) " << b*b/(2*a)*(1-exp(-a*pi/b));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement