How can I evaluate a bessel function inside an integral?

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!

답변 (1개)

John D'Errico
John D'Errico 2018년 2월 11일
편집: John D'Errico 2018년 2월 11일
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

Excellent answer. Just a minor point that you may prefer
doc vpaintegral
instead of
help vpaintegral
John D'Errico
John D'Errico 2018년 2월 12일
편집: John D'Errico 2018년 2월 12일
Thanks. I admit that I come from the old days of MATLAB, when the software arrived on a 3.5 inch floppy, and doc simply did not exist. It is just automatic for me to use help, not doc - a habit I have never managed to kick.
"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
And as a doc writer, I can't help but point out the doc :) As Stephen says, thanks for all the help around here.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Bessel functions에 대해 자세히 알아보기

질문:

2018년 2월 11일

댓글:

2018년 2월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by