Filter löschen
Filter löschen

can anyone help me ? i keep getting this error

2 Ansichten (letzte 30 Tage)
Mohamed
Mohamed am 25 Sep. 2022
Kommentiert: Torsten am 26 Sep. 2022
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 ?

Akzeptierte Antwort

Chunru
Chunru am 26 Sep. 2022
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 Kommentare
Mohamed
Mohamed am 26 Sep. 2022
thank you so much
you are a lifesaver
Torsten
Torsten am 26 Sep. 2022
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:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Bessel functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by