The computation of the Cosine Series
can be done based on the SineSeries.java program in the post below with some minor changes (still assuming that CosineSeries.java is also in the same package where SineSeries.java 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: