Thank you, Mr. Strider for your quick answer. Is it possible to use inline to create a function and integrate it because my MatLab version does not have quadv command yet? Otherwise, I have to update my version. Anyway, thank you for your instruction. BR Donyau
how to use quadl function to integrate a function of combination Bessel function and a vector
2 views (last 30 days)
Show older comments
Hello, I tried to use quadl command to build up a function of Bessel function multiply with a vector and integrate it from 0 to 1. My coding is below:
u=0.:0.01:1.0; nu=1.5; u=u.^1.5;
w=@(u) u.*besselj(nu,u);
quadl(w, 0, 1)
and it turns out as "identifier" expected, "(" found.
and then I modify my code using inline command and hope to create a function. the coding is below:
u=0.:0.01:1.0; nu=1.5; z=u.^1.5;
g=inline('besselj(nu,u).*z','u','nu','z');
quadl(g, 0, 1)
and it turns out as
Error using ==> inline/feval
Not enough inputs to inline function.
Could someone please to help me? Your prompt answer will be deeply appreciated. BR Donyau
Accepted Answer
John BG
on 13 May 2016
Donyau
1.- In MATLAB R2016 your initial code works just fine:
format long
u=0.:0.01:1.0; nu=1.5; u=u.^1.5;
w=@(u) u.*besselj(nu,u);
quadl(w, 0, 1)
ans =
0.071277937291592
No such error message you mention in the question.
2.- There is not need to compess (chirp) the time reference with u=u.^1.5 because the result is the same:
u=0.:0.01:1.0; nu=1.5; % u=u.^1.5
w=@(u) u.*besselj(nu,u);
quadl(w, 0, 1)
ans =
0.071277937291592
that command inline is going to be discontinued
4.- The function you want to integrate is the thicker line, Bessel 1st kind index 1.5 :

plot obtained with
X = 0:0.1:20;
J = zeros(9,201);
for i = 0:.5:9
J(i*2+1,:) = besselj(i,X);
end
plot(X,J,'LineWidth',1.5)
axis([0 20 -.5 1])
grid on
L1=legend('J_0','J_{0.5}','J_1','J_{1.5}','J_2','J_{2.5}','J_3','J_{3.5}','J_4','Location','bestoutside')
% L1.Position=[12 .25 8 .65]
title('Bessel Functions of the First Kind for v = 0:0.5:4')
xlabel('X')
ylabel('J_v(X)')
hold on;
plot(X,J(4,:),'LineWidth',4,'Color',[.8 .8 0])
Since you only want to integrate within [0 1], and you are already multiplying besselj with the reference u*besselj(1.5,u) wouldn't you agree that it's quite a fair approximation to replace x*besselj(1) with a parabolic function?

5.- Perhaps what you considered replacing the integral with a Bessel function of higher order, from http://mathworld.wolfram.com/BesselFunctionoftheFirstKind.html

since m=1.5, the conditions z<<1 and z>>abs(m^2-.25) are not met, from the zoomed graph, the marker on besselj(1.5,u=1)=0.049 that is not quite the 0.07 from the integration.
6.- upgrade to R2016 and do not pick by line, do not use inline.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John
More Answers (1)
Star Strider
on 13 May 2016
You’re integrating an array-valued funciton, so you need to use the quadv funciton:
u=0.:0.01:1.0; nu=1.5; u=u.^1.5;
w=@(u) u.*besselj(nu,u);
int_w = quadv(w, 0, 1);
If you have R2012a or later, a better choice is the integral function using the 'ArrayValued' argument:
int_w = integral(w, 0, 1, 'ArrayValued',true);
8 Comments
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!