The accuracy of the recurrence formula?

Need to compute the function using the recurrence relation of the members of the series.
36713a1e09924ccf81bd6d94f3663fb9.png

Here is my recursive formula:
e652fb6e97ba4029acbcd4f52a5f6cf8.jpg

Program code:
#include <cmath>
#include <iostream>
#include <conio.h>
using namespace std;

int main() {
 const double pi = 3.14159265358979323846;
 double x = pi / 2;
 double s = 0,
 eps = 1e-06;
 int k = 1;
 double elem = x * x;
 s = elem;
 while(fabs(elem) >= eps) {
 cout << k << " : "<< elem << " : "<< s << endl;
k++;
 elem *= (-4 * x * x) / ((2 * k + 1) * (2 * k + 2));
 s += elem;
}
 cout << "S:" << s << endl;
 cout << "MATH:" << sin(x) * sin(x);
_getch();
 return 0;
}</conio.h></iostream></cmath>


Actually the problem is that the result of my formula varies wildly with the result of functions from the library. It is suspected that the formula is not true, but some times copied.

053144f3ef1c4b0c89d974f78780598c.png
July 2nd 19 at 17:16
3 answers
July 2nd 19 at 17:18
Solution
Try 2 options:
1. a(k) / a(k-1)
2. a(k+2) / a(k+1)

And anyway, your loop in the first iteration, k=2, and then computes a new member. Check that the second term that must be in the original formula
The first formula implies that I know how many number of members? - kallie.Luettge commented on July 2nd 19 at 17:21
No. Simply substitute.
When k=1. The member will be x^2
When k=2. In the above formula, the member is -1/3 * x^4. And your program -4x^4 / 30.
Try those 2 cases that I have suggested - Mandy62 commented on July 2nd 19 at 17:24
July 2nd 19 at 17:20
Solution
You have a formula retrieve the k+1 element of the k-th, and use it to obtain the k-th element of the k-1. This is a different formula.
July 2nd 19 at 17:22
There is only the ratio displayed correctly. Next you need to choose the correct initial values and correct the test to stop.

Find more questions by tags Higher mathematicsMathematicsCC++