Explanation Sine series using C language


Let n = 3,
then , x is converted to radian by multiplying it by 3.14159/180 and assigned the value of x in t and sum
. So, after line no 15 and 16, t = x and sum = x
Now lets take a look at the working of for loop with n = 3:
Ex1: t = (t * pow((double) (-1), (double) (2 * i – 1)) * x * x) / (2 * i * (2 * i + 1))
Ex2: sum = sum + t
Iteration 1: i = 1, t = x, sum = x
Putting these values in Ex 1 we get,
t = (x * pow((double) (-1), (double) (2 * 1 – 1)) * x * x) / (2 * 1 * (2 * 1 + 1))
t = x*(-1)*x*x/6 = -x3/3!
Putting value of t in Ex 2 we get,
sum =  x + (-x3/3! ) = x – x3/3!
Iteration 2: i = 2, t = -x3/3!, sum = x – x3/3!
Putting these values in Ex 1 we get,
t = (-x3/3! * pow((double) (-1), (double) (2 * 2 – 1)) * x * x) / (2 * 2 * (2 * 2 + 1))
t = (-x3/3!)*(-1)*x*x/20 = x5/5!
Putting value of t in Ex 2 we get,
sum = x – x3/3! + x5/5!
Iteration 3: i = 3, t = x5/5!, sum = x – x3/3! + x5/5!
Putting these values in Ex 1 we get,
t = (x5/5! * pow((double) (-1), (double) (2 * 3 – 1)) * x * x) / (2 * 3 * (2 * 3 + 1))
t = (x5/5!)*(-1)*x*x/42 = -x7/7!
Putting value of t in Ex 2 we get,
sum = x – x3/3! + x5/5! – x7/7!
After iteration 3, i = 4 so the for loop terminates and output is printed.

 

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s