0% found this document useful (0 votes)
21 views

All All: For For For End

The document initializes variables to calculate and plot Bessel functions of the first kind for different values of n. It uses nested for loops to calculate J_n(x) for n from 0 to 3 and -1/2 to 1/2, storing the results in a matrix. Finally, it plots the matrices and adds labels and legends to the graphs.

Uploaded by

Rints Advertisin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

All All: For For For End

The document initializes variables to calculate and plot Bessel functions of the first kind for different values of n. It uses nested for loops to calculate J_n(x) for n from 0 to 3 and -1/2 to 1/2, storing the results in a matrix. Finally, it plots the matrices and adds labels and legends to the graphs.

Uploaded by

Rints Advertisin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

clear all % clean all and prepare

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)')

You might also like