All All: For For For End
All All: For For For End
close all
lim = 100; % initialize variables
J=0;
i = 1;
for n = 0:3; % values of n to loop over
j = 1;
for x = 0:0.1:3*pi; % range over x
for s=0:lim
J=J+((-1)^s)/(factorial(s)*factorial(s+n))*(x/2)^(2*s+n); %actual fcn
end
a(j,i)=J;
j = j+1;
J=0;
end
i = i+1;
end
plot(a) % plotting and formatting results
grid on
legend('J_0','J_1','J_2','Location','Best')
title('Bessel Functions of the First Kind for n = 0,1,2')
xlabel('x')
ylabel('J_n(x)')
clear all clean all and prepare
close all
lim = 100; % initialize variables
J=0;
i = 1;
for n = -1/2:1/2; % values of n to loop over
j = 1;
for x = 0:0.1:3*pi; % range over x
for s=0:lim
J=J+((-1)^s)/(factorial(s)*gamma(s+n+1))*(x/2)^(2*s+n); %actual fcn
end
a(j,i)=J;
j = j+1;
J=0;
end
i = i+1;
end
plot(a) % plotting and formatting results
grid on
legend('J_-_1_/_2','J_1_/_2','Location','Best')
title('Bessel Functions of the First Kind for n = -1/2,1/2')
xlabel('x')
ylabel('J_n(x)')