Evaluate Infinite Sine Series – C PROGRAM

In the last post I discussed, how to evaluate a Sine series for a given value of x upto a certain number of terms.

In this post, I will show you how to modify that program to evaluate the sine series upto desired accuracy.

To do that, instead of running the loop upto n,(to evaluate and sum the n terms) we would use a do-while loop which will run until the desired accuracy is reached.
That is till, the ratio:
accuracy=\left|\frac{t_i}{sum} \right| becomes less or equal to the desired accuracy.

This will be our terminating condition for the do-while loop.

Therefore, the C program to find the sin(x), correct upto a given accuracy, can be written as shown below.


******INFINITE SERIES SUM**********
Series: sin(x) = x - (x^3/3!) + (x^5/5!) + ..... 
	int i=1;
	double x,t0,t1,R,sum,eps;
	printf("Enter the value of x:\n");
	printf("Enter the desired accuracy: ");
	//Initialize First Term
	//Make sum equal to the first term
		//Find the ratio of the second term to the first term using already known relation
		//Calculate the second term
		//find the new sum
		//keep on summing terms until the required accuracy is reached
	printf("\nThe sum is: %f with %d terms",sum,i);


PhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in computational material science. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT and Machine Learning related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.
[wpedon id="7041" align="center"]

Leave a Reply

Your email address will not be published. Required fields are marked *