• API
• FAQ
• Tools
• Archive
daily pastebin goal
72%
SHARE
TWEET

realanton12345 Jan 18th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <stdlib.h>
3. #include <iomanip>
4. #include <cmath>
5.
6. using namespace std;
7.
8.
9. double countY(double x) {
10.     //return (M_PI * pow(x, 3)) / 2;
11.     return sin(x);
12.     //return pow(9, x);
13. }
14.
15. double factorial(int n)
16. {
17.     if(n > 1) {
18.         return n * factorial(n - 1);
19.     }
20.     else {
21.         return 1;
22.     }
23. }
24.
25. double countS(double x, double eps, int *times) {
26.     double i = x;
27.     double a = x;
28.     double sum = x;
29.     *times = 1;
30.     while (fabs(i) > eps) {
31.         i =  pow(x, 2)/(2 * (*times) *(2 * (*times) + 1));
32.         //i = ((pow(-1, *times + 1) / *times) + ((pow(-1, *times) * 6) / (pow(*times, 3) * pow(M_PI, 2)))) * sin(*times) * M_PI * x;
33.         //i = (pow(log(9), *times) / factorial(*times)) * pow (x, *times);
34.         a *= -1 * i;
35.         sum += a;
36.         *times = *times + 1;
37.     }
38.     return sum;
39. }
40.
41. int main()
42. {
43.     cout << "LR 3" << endl;
44.
45.     double a = -0.5;
46.     double b = 0.5;
47.     double h = (b - a) / 10;
48.     double x = a;
49.     double e = 0.001;
50.
51.
52.     cout << "a = " << a << ", b = " << b << ", h = " << h << ", x = " << a << endl;
53.
54.     cout << setw(5) << "X" << setw(15) << "Y(X)" << setw(15) << "S(X)" << setw(15) << "S times" << setw(15) << "Y times" << endl;
55.     while (x < (b + h) / 2) {
56.         int *times = new int (0);
57.         double s = countS(x, e, times);
58.         cout << fixed << setw(5) << x << setw(15) << countY(x) << setw(15) << s << setw(15) << *times << setw(15) << "1" << endl;
59.         x += h;
60.     }
61.     system("pause");
62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top