can anyone help me ? i keep getting this error
3 views (last 30 days)
Show older comments
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 ?
Accepted Answer
Chunru
on 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')
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
2 Comments
Torsten
on 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:
More Answers (0)
See Also
Categories
Find more on Bessel functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!