can anyone help me ? i keep getting this error

조회 수: 3 (최근 30일)
Mohamed
Mohamed 2022년 9월 25일
댓글: Torsten 2022년 9월 26일
Here is the code:
num_roots=5; num_functions=6;
%initial guess for roots (from Wolfram MathWorld)
zeros_guess=[2.4,3.8,5.1,6,7.5,8.7;...
5.5,7,8.4,9.7,11,12;...
8.6 10,11.6,13,14,16;...
11.8,13,15,16,18,19;...
15,16.4,18,19.4,21,22];
%Compute first five roots of first six Bessel functions
%Put in variable bzeros with size(bzeros) = [5, 6]
integrand = @(theta,x,n) cos(x.*sin(theta)-n*theta);
J_n = @(x) integral(@(theta)integrand(theta,x,n),0,pi);
for n=0:num_functions-1
J_n = @(x) integral(@(theta)integrand(theta,x,n),0,pi);
for k=1:num_roots
bzeros(k,n+1)=fzero(J_n,bzeros_guess(k,n+1));
end
end
%print table
fprintf('k J0(x) J1(x) J2(x) J3(x) J4(x) J5(x)\n')
for k=1:num_roots
fprintf('%i',k)
for n=0:num_functions-1
fprintf('%10.4f',bzeros(k,n+1));
end
fprintf('\n');
end
this is the output that keeps popping out:
Undefined function 'bzeros_guess' for input arguments of type 'double'.
Error in solution (line 15)
bzeros(k,n+1)=fzero(J_n,bzeros_guess(k,n+1));
what does this mean and is there a way i can rewrite the white section so that it works ?

채택된 답변

Chunru
Chunru 2022년 9월 26일
num_roots=5; num_functions=6;
%initial guess for roots (from Wolfram MathWorld)
zeros_guess=[2.4,3.8,5.1,6,7.5,8.7;...
5.5,7,8.4,9.7,11,12;...
8.6 10,11.6,13,14,16;...
11.8,13,15,16,18,19;...
15,16.4,18,19.4,21,22];
%Compute first five roots of first six Bessel functions
%Put in variable bzeros with size(bzeros) = [5, 6]
integrand = @(theta,x,n) cos(x.*sin(theta)-n*theta);
J_n = @(x) integral(@(theta)integrand(theta,x,n),0,pi);
for n=0:num_functions-1
J_n = @(x) integral(@(theta)integrand(theta,x,n),0,pi);
for k=1:num_roots
%bzeros(k,n+1)=fzero(J_n,bzeros_guess(k,n+1));
bzeros(k,n+1)=fzero(J_n, zeros_guess(k,n+1)); % initial guess at the right hand side
end
end
%print table
fprintf('k J0(x) J1(x) J2(x) J3(x) J4(x) J5(x)\n')
k J0(x) J1(x) J2(x) J3(x) J4(x) J5(x)
for k=1:num_roots
fprintf('%i',k)
for n=0:num_functions-1
fprintf('%10.4f',bzeros(k,n+1));
end
fprintf('\n');
end
1
2.4048 3.8317 5.1356 6.3802 7.5883 8.7715
2
5.5201 7.0156 8.4172 9.7610 11.0647 12.3386
3
8.6537 10.1735 11.6198 13.0152 14.3725 15.7002
4
11.7915 13.3237 14.7960 16.2235 17.6160 18.9801
5
14.9309 16.4706 17.9598 19.4094 20.8269 22.2178
  댓글 수: 2
Mohamed
Mohamed 2022년 9월 26일
thank you so much
you are a lifesaver
Torsten
Torsten 2022년 9월 26일
The Bessel functions are predefined in MATLAB. If it's not explicitly stated in your assignment, you don't need to evaluate them using the integral representation:

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Bessel functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by