function y=besJ0(x) %----------------------------------------------------------------------- % Approximate the Bessel's function of the first kind of order zero % via 10-term Taylor's series expansion. % J0(x) = sum(sign*x^i/i!) for i=even integers % J0(x) = 1 - (x/2)**2/(1!)**2 + (x/2)**4/(2!)**2 - (x/2)**6/(3!)**2 + ... % Method used: iterate on the following relationship based on Taylor's series: % delta = -delta*(x/2)**2/i**2 % bessel = bessel + delta % Programming Note: % Because Taylor's series is alternating in sign, there is subtractive % cancellation. Nevertheless, convergence is quick enough for a small x. % For large values of x, apply the asymptotic approximation formula. % J0(x)=sqrt(2/pi/x)*cos(x-pi/4), for x>25 % Instructor: Nam Sun Wang %----------------------------------------------------------------------- % Calculate the Taylor's series expansion % Initialize (The first term is contained in the initialization step.) delta = 1. ; y = 1. ; for i=1 : 99999 delta = -delta*(x/2.)*(x/2.)/i/i ; y = y + delta ; % Converge to 5 digits. % Since J0 is O(1), this is almost identical to 5 significant digits. if(abs(delta) < 1.E-5) break; end end