Wednesday, 8 December 2010

Cosine Series

The computation of the Cosine Series 

can be done based on the program in the post below with some minor changes (still assuming that is also in the same package where is). Here we compute the value of the series at x = 45°, which is π/4 in radian measure.

We first define a class called CosineSeriesSummation for summing the series upto a specified number of terms as below:

Next we invoke the method defined above in the CosineSeries class which contains the main() method as:

The output of the program is as:

  The sum of the Cosine Series at x = 0.7853981633974483 upto the    
  first 20 terms is 0.7071067811865475
  Using the cos() method of the java.lang.Math class, the value 
  of the Cosine Function at x = 0.7853981633974483 is 0.7071067811865476

1 comment: