Solve integral including Bessel function numerically in matlab

1.5k Views Asked by At

enter image description here

How can I write a code in matlab that solve this equation numerically, r & t are inputs and we can put every value.

1

There are 1 best solutions below

5
On BEST ANSWER

I can't really test this, but using Matlab's integral (documentation) to perform numeric quadrature, here's an anonymous function to calculate $\theta(\tilde{r},\tilde{t})$:

f = @(b,r,t)exp(-t.*b.^2).*(besselj(0,b.*r).*bessely(0,b)- ...
                            bessely(0,b.*r).*besselj(0,b)) ...
                         ./(b.*(besselj(0,b).^2+bessely(0,b).^2));
th = @(r,t)(-2/pi)*integral(@(b)f(b,r,t),0,Inf);

Just call th(r,t) for scalar or array values of r and t.

In older versions of Matlab you may need to use quadgk (documentation) instead of the newer integral. If performance is an issue, you may want to turn the anonymous function f into a regular function and only calculate besselj(0,b) and bessely(0,b) once per call. Additionally, if there are numeric issues/errors/warnings, you might try doing the math to convert to the three input argument scaled form of these Bessel functions: see my answer here for further details.