-
Notifications
You must be signed in to change notification settings - Fork 16
/
MyMath.h
125 lines (113 loc) · 3.37 KB
/
MyMath.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <locale.h>
#include <math.h>
#include <string.h>
#include "Header.h"
#include "omp.h"
#include <time.h>
static long long factorial(int x)
{
long long f;
for (f = 1; x > 1; f *= (x--))
;
return f;
}
void sinus(double x, double pog, int n, int mode)
{
double a = 0;
int count = 0;
do
{
a += pow((-1), count) * ((pow(x, 2 * count + 1)) / factorial(2 * count + 1));
count++;
} while ((fabs(sin(x) - a) > pog) && (count < n));
if (mode == 1)
printf("Ýòàëîííîå çíà÷åíèå: %lf\nÐàññ÷èòàííîå çíà÷åíèå: %lf\nÏîãðåøíîñòü: %lf\nÊîëè÷åñòâî ñëàãàåìûõ: %d\n", sin(x), a, sin(x) - a, count);
else if (mode == 2)
printf("%16lf%24lf%26lf\n", sin(x), a, fabs(sin(x) - a));
}
void cosinus(double x, double pog, int n, int mode)
{
double a = 0;
int count = 0;
do
{
a += pow((-1), count) * ((pow(x, 2 * count)) / factorial(2 * count));
count++;
} while ((fabs(cos(x) - a) > pog) && (count < n));
if (mode == 1)
printf("Ýòàëîííîå çíà÷åíèå: %lf\nÐàññ÷èòàííîå çíà÷åíèå: %lf\nÏîãðåøíîñòü: %lf\nÊîëè÷åñòâî ñëàãàåìûõ: %d\n", cos(x), a, fabs(cos(x) - a), count);
else
printf("%16lf%24lf%26lf\n", cos(x), a, fabs(cos(x) - a));
}
void exponenta(double x, double pog, int n, int mode)
{
double a = 0;
int count = 0;
do
{
a += pow(x, count) / factorial(count);
count++;
} while ((fabs(exp(x) - a) > pog) && (count < n));
if (mode == 1)
printf("Ýòàëîííîå çíà÷åíèå: %lf\nÐàññ÷èòàííîå çíà÷åíèå: %lf\nÏîãðåøíîñòü: %lf\nÊîëè÷åñòâî ñëàãàåìûõ: %d\n", exp(x), a, fabs(exp(x) - a), count);
else
printf("%16lf%24lf%26lf\n", exp(x), a, fabs(exp(x) - a));
}
double num_eiler(int n)
{
double E = 0;
int count = 0;
do
{
E += 1 / factorial(count);
count++;
} while (count < n);
}
void secans(double x, double pog, int n, int mode)
{
double a = 0;
int count = 0, last = 1;
do
{
if (count % 2 == 0)
a += (num_eiler(2 * count) * pow(x, 2 * count)) / factorial(2 * count);
else
a += ((-1) * num_eiler(2 * count) * pow(x, 2 * count)) / factorial(2 * count);
count++;
} while ((fabs((1 / cos(x)) - a) > pog) && (count < n));
if (mode == 1)
printf("Ýòàëîííîå çíà÷åíèå: %lf\nÐàññ÷èòàííîå çíà÷åíèå: %lf\nÏîãðåøíîñòü: %lf\nÊîëè÷åñòâî ñëàãàåìûõ: %d\n", 1 / cos(x), a, fabs((1 / cos(x)) - a), count);
else
printf("%16lf%24lf%26lf\n", 1 / cos(x), a, fabs(1 / cos(x) - a));
}
void sh(double x, double pog, int n, int mode)
{
double a = 0, answer = (exp(x) - exp((-1) * x) / 2);
int count = 0;
do
{
a += pow(x, 2 * count + 1) / factorial(2 * count + 1);
count++;
} while ((fabs(answer - a) > pog) && (count < n));
if (mode == 1)
printf("Ýòàëîííîå çíà÷åíèå: %lf\nÐàññ÷èòàííîå çíà÷åíèå: %lf\nÏîãðåøíîñòü: %lf\nÊîëè÷åñòâî ñëàãàåìûõ: %d\n", answer, a, fabs(answer - a), count);
else
printf("%16lf%24lf%26lf\n", answer, a, fabs(answer - a));
}
void ch(double x, double pog, int n, int mode)
{
double a = 0, answer = (exp(x) + exp((-1) * x) / 2);
int count = 0;
do
{
a += pow(x, 2 * count) / factorial(2 * count);
count++;
} while ((fabs(answer - a) > pog) && (count < n));
if (mode == 1)
printf("Ýòàëîííîå çíà÷åíèå: %lf\nÐàññ÷èòàííîå çíà÷åíèå: %lf\nÏîãðåøíîñòü: %lf\nÊîëè÷åñòâî ñëàãàåìûõ: %d\n", answer, a, fabs(answer - a), count);
else
printf("%16lf%24lf%26lf\n", answer, a, fabs(answer - a));
}