function [] = chap_1_prob_2(nIter) % CHAP_1_PROB_1 - % % Written by: % -- % John L. Weatherwax 2005-06-02 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- xA = [ 0:0.5:10.0 ]; % Taylor series (small x): % disp( 'Taylor series...' ); tic; for xi=1:length(xA) x = xA(xi); tmp = (x^2)/4; trth = besselj(0,x); aJ0 = 0; for n=0:nIter-1, aJ0 = aJ0 + ((-1)^n)*(tmp^n)/(factorial(n)^2); end fprintf( 'x = %f; J0 = %f; aJ0 = %f; abs acc = %f; rel acc = %f\n', xA(xi), ... trth, aJ0, ... abs(aJ0-trth), abs(aJ0-trth)/abs(trth+eps) ); end tm = toc; fprintf( 'Approx. computation time = %f\n', tm/length(xA) ); disp( '------------------------------------------------------------------------' ); % Asymptotic series (large x): %