Sei sulla pagina 1di 2

Sine Function Computation Algorithms

Sine series is given ;



sin(x) = (x/1!)-((x^3)/3!)+((x^5)/5!) -((x^7)/7!)+..........

Algorithm development:

Studying the expression for sin(x) we see the powers and factorials of following sequences

1,3,5,7..................

are required. We can easily generate this odd sequence by starting with 1 and successively
adding 2. Our other problem is to compute the general term (x^i)/i! which can expressed as

(x^i)/i! = (x/1)*(x/2)*(x/3)*.......*(x/i) for i>=1

and it can done following loop

fp := 1;
j := 0;
while j<i do
begin
j := j +1;
fp := fp*(x/j);
end

The program can be completed by implementing the additions and subtraction and
appropriate termination. With this approach each term (x^i)/i! is computed by smallest j value
and working upward . To calculating n! we used the efficient approach of calculating each term
from its predecessors .
To determine algorithm we examine specific series for example,

(x^3)/3! = (x*x*x)/(3*2*1) = (x^2)/(3*2) * (x^1)/1! i =3
(x^3)/3! = (x*x*x*x*x)/(5*4*3*2*1) = (x^2)/(5*4) * (x^3)/3! i =5
(x^3)/3! = (x*x*x)/(7*6*5*4*3*2*1) = (x^2)/(7*6) * (x^5)/5! i =7

In each term (x^2)/(3*2) , (x^2)/(5*4) ,(x^2)/(7*6) has a general term :

(x^2)/i(i - 1) for i= 3,5,7,....

i.e. generalized form of each term is:

current ith term = [ (x^2)/i(i - 1) ] * (previous term)
To get the terms to alternate in sign we can use
sign := -sign

algorithm description
1. setup initial conditions for the first term that cannot be computed iterativley .
2. while the absolute value of current term is greater than the acceptable error do
(a). identify the current ith term,
(b). generate current term from its predecessor,
(c). add current term with appropriate sign to the accumulated sum for sine function.

Potrebbero piacerti anche