Integration using GPU computing

9 ビュー (過去 30 日間)
Geoffrey
Geoffrey 2016 年 5 月 18 日
コメント済み: Joss Knight 2016 年 5 月 20 日
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.
  1 件のコメント
Joss Knight
Joss Knight 2016 年 5 月 20 日
Please write your code so I can run it. At the moment certain essential variables are missing such as mu0 and N_drive, and certain functions are missing such as StruveH.
The error message means that you can't index into arrays inside a GPU arrayfun function because of its special behaviour. The only circumstance under which indexing is allowed is if the indexing is into an upvalue, and if it returns a scalar.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by