Actually the condition of the problem:

"Create a program that will consider the function sin (x) with accuracy ε using the following form of expansion in a row. Compare the result with the value obtained by the standard function sin (x) decomposition form

The problem needs to be solved with the help of a cycle with an unknown number of repetitions. I can not understand what the "accuracy ε" and what to use as a condition in the case of while

upd

Yes, I wrote something, the problem is only with factorial, namely when compiling it writes "identifier not found"

int main() { int x; // Градус cin >> x; double e; // Точность cin >> e; double sinx = sin(x); // значение обычной функции sin(x) int calcx = x; // начальное значение функции разложенной в ряд int n = 0; // счётчик while (sinx - calcx > e) { n++; calcx += pow(-1,n)*(pow(x, 3) / faktorial(2 * n + 1)); } system("pause"); } int faktorial(int numb) { int result = 1; for (int i = 1; i <= numb; i++) result *= i; return result; } 

Closed due to the fact that the essence of the question is incomprehensible by the participants Harry , pavel , HamSter , αλεχολυτ , aleksandr barakin 11 Nov '16 at 10:37 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Actually, asking, you have to show your skills, and not ask to do everything from and to ... - Harry
  • Understood, I just use this resource for the first time, do not hit hard) - Nether
  • See the amended solution. And the advice: when you add it this way - write a comment for who you answered. Because I came here a second time, in general, by chance. And so I would see a notification of the comment, and I would have looked much earlier ... - Harry

2 answers 2

In the series alternating with monotonously decreasing members, the error of the sum of the series does not exceed the last member dropped. It is about accuracy.

Next, consider the relationship of neighboring members of the series. Next - a cycle with summation: from the last added member we calculate a new one, add to the sum, and check if it is not less than the specified accuracy.

Write to. When you write at least something besides the assignment, let's talk about your decision ...

PS Great, once written - now you can fix it. Each member does not need to be looked for from scratch - I wrote: consider the relation of neighboring members of the series . The next term is obtained simply by multiplying the previous by -x^2 and dividing by (n+1)(n+2) . So much easier and faster.

And that's what happens (I set the error right in the program, and just find the table of different values, and compare it with the "real" sine:

 #include <iostream> #include <iomanip> #include <cmath> using namespace std; double series(double x, double eps) { double sum = x, term = x; int n = 1; while(abs(term) > eps) { term *= -x*x/(n+1)/(n+2); n += 2; sum += term; } return sum; } const double eps = 1e-8; int main() { for(double x = 0.0; x < 6.3; x += 0.2) { cout << setw(8) << x << " " << setw(10) << series(x,eps) << " " << setw(10) << sin(x) << endl; } } 

    It is necessary to calculate the value, using each time one element of the series more, and each time comparing the resulting value with what was obtained in the previous step.

    Repeat until the difference is less than the predetermined ε, which is entered by the user before the start of the cycle.