Computer Code
Laboratory Programming Exercise 05 Computer Engineering 160 Fall 2018 C. Paolini In Laboratory Programming Exercise 04 we saw the coefficients of the Maclaurin series expansion for cos(x) form the alternating series
22 4 6 1 1, , , , ,
2! 4! 6! 2 !
k k xx x x
k
A similar alternating series can be derived from the Bessel function J0(x), which describes
electromagnetic waves in a cylindrical waveguide
22 4 6
22 2 2 2 2 2 2
1 1, , , , ,
2 2 4 2 4 6 2 !
k k
k
xx x x
k
Let n = 2k. Then, the denominator of a cos(x) function series coefficient has an n! term, while the denominator of a Bessel function series coefficient has a 2242∙∙∙n2 term. This latter product can be expressed as
2
2 ! 2
n n
Within an iterative structure, compute the ratio of the kth cos(x) coefficient to the kth Bessel
coefficient, i.e.,
2
1
!
1
2 ! 2
k n
k n
n
x
n
x
n
for 10 iterations. In your output, show that the ratio approaches / 2n . There is no need to
prompt for input. During each iteration, output the value of the iteration index k, the kth ratio, and the
kth approximation error
error ratio / 2 k
n
Once you have this part working, modify your program to use Stirling’s formula to approximate n!
! 2 n n
n nn e
to avoid a nested loop to compute a factorial. Verify your program works using Stirling’s approximation. Generate a screen capture of your Eclipse IDE workspace, showing your code and the output of your program in the terminal. Please name your Eclipse IDE project Lastname_REDID_Lab_05. Create a ZIP file of your project folder and submit the ZIP file
through Blackboard.