%% Problem 1.10. A Bessel Function
%% 1.10(a)

syms x real
f = @(x, k) sum(((-ones(1,k+1)).^(0:k)).* ...
    (x*ones(1,k+1)).^(2*(0:k))./factorial(0:k).^2);
figure; fplot(f(x, 10), [-8,8]), axis([-8,8,-2,2])
hold on
fplot(f(x, 20), [-8,8]), axis([-8,8,-2,2])
fplot(f(x, 40), [-8,8]), axis([-8,8,-2,2])
hold off

%
% We see that f_{10} and f_{20} have almost the same graph over the interval -3.5 < x < 3.5, and that f_{20} and f_{40} have almost the same graph over the interval -8 < x < 8. We can understand this in terms of the alternating series test. For an alternating series whose terms decrease in absolute value, the error due to truncation is bounded by the absolute value of the first term omitted. The term with n = 22 for x = 8 has absolute value

8^44/factorial(22)^2

% This is too small to have much effect on the picture at the scale we are interested in.
%
%% 1.10(b)

syms n
symsum(((-1)^n)*x^(2*n)/factorial(n)^2, n, 0, Inf)

%

figure; fplot(ans, [-8, 8]), axis([-8,8,-2,2])
hold on
fplot(f(x, 40), [-8,8]), axis([-8,8,-2,2])
hold off

% We see that the two plots almost coincide.