can anyone help me ? i keep getting this error

1 visualización (últimos 30 días)
Mohamed
Mohamed el 25 de Sept. de 2022
Comentada: Torsten el 26 de Sept. de 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 ?

Respuesta aceptada

Chunru
Chunru el 26 de Sept. de 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 comentarios
Mohamed
Mohamed el 26 de Sept. de 2022
thank you so much
you are a lifesaver
Torsten
Torsten el 26 de Sept. de 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:

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Bessel functions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by