# How do I use the besselj function?

3 views (last 30 days)
Nathan Falkner on 6 Mar 2022
I've been given a row vector v and column vector z:
v = unique(randi(12, [1,4])-1);
z = linspace(0,10*(1+rand(1)),2e2).';
I'm supposed to produce an array M=Jv(z), where the columns of M(z) correspond to each value of v.
This is what I've made so far:
for i = [1:length(v)]
M(i)=besselj(v(i),z(i))
end
I had thought I made a correct array of M, with it being a 1x4 function, like v. However this doesn't allow me to make M a function of z, and I have a feeling I've completely misunderstood the documentation of the besselj function altogether.

Abolfazl Chaman Motlagh on 6 Mar 2022
The function besselj(nu,x) is in fact two variable function as . you put v(i) and z(i) simultaneously with same index in argument of it. means M(i) is which make it one dimensional array. you should consider some v as you already created and a linespace for spatial variable.
v = unique(randi(12, [1,4])-1);
z = linspace(0,10*(1+rand(1)),2e2).';
for i = 1:numel(v)
M(i,:)=besselj(v(i),z);
end
plot(z,M,'LineWidth',2);grid on;
legend(['J_{' num2str(v(1)) '}'],['J_{' num2str(v(2)) '}'],['J_{' num2str(v(3)) '}'],['J_{' num2str(v(4)) '}']) if size of v be less than 4 the line legends leads to an array.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!