I have a problem that requires nesting integrals and I cannot use double or triple integrals as it is extremely difficult with the math. To speed the process, I am doing the integrals on the GPU using trapz. But, when I run it, I consistently get the error:
Error using gpuArray/arrayfun Indexing is not supported.
I am not entirely sure what to do.
Here is the section of code I am having the problems with
function val_L1=L1_int(g)
val_L1= 1./4.*mu0.*pi.^2.*N_drive.^2.*(-StruveH(1,OR_drive.*g).*besselj(0,OR_drive.*g).*OR_drive+besselj(1,OR_drive.*g).*StruveH(0,OR_drive.*g).*OR_drive-besselj(1,IR_drive.*g).*StruveH(0,IR_drive.*g).*IR_drive+besselj(0,IR_drive.*g).*StruveH(1,IR_drive.*g).*IR_drive).^2 .*(g.*H_drive.*exp(g.*H_drive)-exp(g.*H_drive)+1).*exp(-g.*H_drive)./H_drive.^2./g.^4./(IR_drive-OR_drive).^2;
function Z=StruveH(p,z)
int_arr= gpuArray.linspace(0, pi/2, N);
intVecSpacing = (pi/2 - 0)/N;
F = arrayfun(@StruveIntegrand, int_arr);
Z = trapz(F) * intVecSpacing;
function integrand=StruveIntegrand(t)
integrand=(2.*(z./2).^p)./(sqrt(pi).*gamma(p+0.5)).*sin(z.*cos(t)).*(sin(t)).^(2.*p);
end
end
end
Ld=2*pi*trapz1(@L1_int,1e-8,2.5e3,N)
The integration being used in simple trapz:
function Z = trapz1(func, xmin, xmax, N)
xvals = gpuArray.linspace(xmin, xmax, N);
xspacing = (xmax - xmin)/N;
F=arrayfun(func,xvals);
Z=trapz(F)*xspacing;
end
I am using Matlab 2014b to do these computations.