Skip to content

Instantly share code, notes, and snippets.

@xTCry
Created November 16, 2018 21:27
Show Gist options
  • Save xTCry/4ef3ca59a090dd73513e051eb414b32d to your computer and use it in GitHub Desktop.
Save xTCry/4ef3ca59a090dd73513e051eb414b32d to your computer and use it in GitHub Desktop.
Глава 3. Раздел 2. Задание 11
// ...
int main7() {
/*
Глава 3. Раздел 2. Задание 11
Для x, изменяющегося в интервале от x0 до xk с шагом h,
вычислить значения бесконечной суммы S(x) с точностью e=0.00001 и функции y(x).
*/
clearConsole();
const float e = 0.0001;
float x0, xk, h;
float a, s;
int n;
cout << "Enter x0: ";
cin >> x0;
cout << "Enter xk: ";
cin >> xk;
cout << "Enter h: ";
cin >> h;
clearConsole();
if (x0 > xk || h <= 0) {
cout << "arg x0 or xk or h WRONG!" << endl << endl;
int type;
cout << "Enter smthng num";
cin >> type;
cout << endl;
return main7();
}
cout << " ============ " << endl;
cout << "* S(x) = ...;\ty(x) = ..." << endl;
cout << " ====== CALC ====== " << endl;
for (float x = x0; x < xk; x += h) {
a = 1;
s = a;
n = 0;
while (abs(a) > e) {
a *= -2*x / ( (2 * n+2) * (2 * n + 1) );
s += a;
n++;
}
float y = 0;
if (x >= 0)
y = cos(sqrt(2 * x));
cout << " S(" << x << ") = " << s << ";\ty(" << x << ") = " << y << endl;
}
cout << " ================== " << endl << endl << endl << endl;
catchExit(main7, 7);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment