Please help with the assignment: Develop an algorithm and compile a program for calculating the values ​​of the sum S of a given series for different values ​​of the argument X: in the internal loop for a fixed value of X, alternately sum up the terms of the series as long as their absolute value exceeds the specified accuracy eps. The calculation of the next member of the series is carried out using a recurrent formula. In the outer loop, argument X changes from 0.5 to 0.75 in increments of 0.05.

Row:

x*(3+x)/3! - x^3*(5+x)/5! + ... + (-1)^(n-1)*(x^(2n-1)*(2n+1+x))/((2n+1)!) 

Where did she screw up?

 float Summ(float x, float eps) { float elem,summ; int n=1; summ=elem=(x*(3+x))/6; while (x*(2*n+1+x)*(2*n+2)*(2*n+3)/(2*n+x)<eps) { elem*=-(x*(2*n+1+x)*(2*n+2)*(2*n+3))/(2*n+x); summ+=elem; n++; } return summ; } 
  • 1. Why is accuracy so calculated? 2. How is factorial taken into account when changing n ? Why in elem*= -... in the last bracket x in the denominator? - andrybak
  • 1. Sorry, did not understand the question a little. Is it about what is written for me, or about the formulation of the task? If regarding the <in while, then only now I noticed: "as long as their absolute value exceeds the specified accuracy eps". The result of the program from this closer to the reference did not. 2. It seems that when I tried to deduce a recurrent formula, it turned out like this. If we divide the next term into the previous one, then the factorial seems to be reduced. - Solidera
  • Thank you It’s always like this: I’ll mix up a plus with a minus, then some kind of nonsense ... - Solidera

2 answers 2

x * (2 * n + 1 + x) is wrong! You lost the square.

    You have another loop condition wrong. You compare the ratio of neighboring elements with eps - and you need to compare the value of the next element. In addition, you are not comparing in the wrong direction.

     summ=0; for (elem = (x*(3+x))/6; elem >= eps; elem *= ...) { summ+=elem; }