Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- double countY(double x) {
- //return (M_PI * pow(x, 3)) / 2;
- return sin(x);
- //return pow(9, x);
- }
- double factorial(int n)
- {
- if(n > 1) {
- return n * factorial(n - 1);
- }
- else {
- return 1;
- }
- }
- double countS(double x, double eps, int *times) {
- double i = x;
- double a = x;
- double sum = x;
- *times = 1;
- while (fabs(i) > eps) {
- i = pow(x, 2)/(2 * (*times) *(2 * (*times) + 1));
- //i = ((pow(-1, *times + 1) / *times) + ((pow(-1, *times) * 6) / (pow(*times, 3) * pow(M_PI, 2)))) * sin(*times) * M_PI * x;
- //i = (pow(log(9), *times) / factorial(*times)) * pow (x, *times);
- a *= -1 * i;
- sum += a;
- *times = *times + 1;
- }
- return sum;
- }
- int main()
- {
- cout << "LR 3" << endl;
- double a = -0.5;
- double b = 0.5;
- double h = (b - a) / 10;
- double x = a;
- double e = 0.001;
- cout << "a = " << a << ", b = " << b << ", h = " << h << ", x = " << a << endl;
- cout << setw(5) << "X" << setw(15) << "Y(X)" << setw(15) << "S(X)" << setw(15) << "S times" << setw(15) << "Y times" << endl;
- while (x < (b + h) / 2) {
- int *times = new int (0);
- double s = countS(x, e, times);
- cout << fixed << setw(5) << x << setw(15) << countY(x) << setw(15) << s << setw(15) << *times << setw(15) << "1" << endl;
- x += h;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement