How can I evaluate a bessel function inside an integral?
18 views (last 30 days)
Show older comments
I need to do a definite integral involving a Bessel function but I cannot get it evaluated. I've already tried with eval() and subs() but the result is the same.
This is only a part of a more complex situation related to radiated electric and magnetic fields I'm working on but a simplified version of the problem could be this code:
>> syms x
>> f(x) = cos(x)*besselj(0,x*cos(x)*5);
>> integral = int(f,x,0,pi/2)
integral =
int(cos(x)*besselj(0, 5*x*cos(x)), x, 0, pi/2)
How could I obtain a numeric solution?
Thanks!
0 Comments
Answers (1)
John D'Errico
on 11 Feb 2018
Edited: John D'Errico
on 11 Feb 2018
That MATLAB returns the integral just means that no analytical solution was found. But if you need only find a NUMERICAL result, then vpaintegral will suffice for this.
help vpaintegral
It is fairly new as I recall, so unless you have a recent release, this will fail.
vpaintegral(f,x,0,pi/2)
ans =
0.296334
However, a really bad idea is to use integral as the variable name, since that prevents you from using the function integral.
In fact, there is ABSOLUTELY no good reason to need to use symbolic tools at all. The function integral is fully sufficient to compute this too, HAD you not prevented that by defining a variable named integral.
f = @(x) cos(x).*besselj(0,x.*cos(x)*5);
integral(f,0,pi/2)
ans =
0.296334454079053
Note my use of the .* operator in the computation of f.
4 Comments
Stephen23
on 13 Feb 2018
"I admit that I come from the old days of MATLAB, when the software arrived on a 3.5 inch floppy..."
But still keeping up with new developments! I always enjoy your insights, analyses, and observations, so please keep up the excellent submissions. +1
Karan Gill
on 13 Feb 2018
And as a doc writer, I can't help but point out the doc :) As Stephen says, thanks for all the help around here.
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!