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!

Respuestas (1)

John D'Errico
John D'Errico el 11 de Feb. de 2018
Editada: John D'Errico el 11 de Feb. de 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 comentarios

Excellent answer. Just a minor point that you may prefer
doc vpaintegral
instead of
help vpaintegral
John D'Errico
John D'Errico el 12 de Feb. de 2018
Editada: John D'Errico el 12 de Feb. de 2018
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.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 11 de Feb. de 2018

Comentada:

el 13 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by