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
Abolfazl Chaman Motlagh 2022년 3월 6일

1 개 추천

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.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by