Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double eps = 0.00001; //точность вычисления
- double sum = 0;
- double temp = x;
- int i = 1;
- while (abs(temp) >= eps)
- {
- sum += temp;
- temp = temp * (x*x) / ((2 * i + 1) * (2 * i));
- i++;
- }
- cout << "x = " << x << "ty = " << 2 * x + sum << endl;
- double calc(double x, int i)
- {
- if (i > 1000) return 1; // Критерий останова рекурсии
- return 1+x*x/(2*i+1)/(2*i)*calc(x,i+1);
- }
- double Sinh(double x)
- {
- return x*calc(x,1);
- }
- int main(int argc, const char * argv[])
- {
- for(double x = 0; x < 2; x += 0.1)
- {
- cout << setw(4) << x << setw(15) << Sinh(x) << setw(15) << sinh(x) << endl;
- }
- }
- double calc(double x, int i, double term)
- {
- double fact = x*x/(2*i+1)/(2*i);
- term *= fact;
- if (fact < 1e-8) return 1; // Критерий останова рекурсии
- return 1+fact*calc(x,i+1, term);
- }
- double Sinh(double x)
- {
- return x*calc(x,1,abs(x));
- }
- double exp2(double x, int e1, int e2, int &i)
- {
- if(e1 == i || e2 == i) return 1 + x * x / e1 * e2;
- return 1 + x * x / (e1 * e2) * exp2(x, e1 + 2, e2 + 2, i);
- }
- void recurs_gorner(double x, int &i)
- {
- clock_t t0 = clock();
- cout << "x = " << x << "ty = " << 2 * x + exp2(x,2,3,i) << endl;
- for (int i = 0; i < 50000000; i++);
- clock_t t1 = clock();
- cout << "Время (рекурсия): " << (double)(t1 - t0) / CLOCKS_PER_SEC << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- double x = 3.0;
- int i = 1;
- recurs_gorner(x, i);
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment