How to integrate 3-dimensional numerical array into one dimension using Parallel Computing Toolbox?

I have a 3-dimensional array X to be numerically integrated with trapz function. The size of array is
size(X) = p,q,r
and the third dimension (size r) is to be integrated with an integral variable given by a vactor vx whose length is r. The result Y will be 2-dimensional matrix as
size(Y) = p,q
Then, how to calculate this numerical integration using GPU with Parallel Computing Toolbox?
Thank you.

 채택된 답변

Xd= distributed(X, 3) % distributed along 3rd dim
Y = trapz(Xd, 3); % trapz support parallel processing for distributed input array
It might be better to use the 1st dimension as the integration dimension.

댓글 수: 3

Thank you for the answer.
Then, is distributed array applicable to every 3-dimensional numerical array? What is the reason if I get the following error?
>Error using distributed (line 300)
>The distributed array constructor should be called with 0 or 1 arguments.
In my test program, X is given as complex double array with the size of 512*512*65 (with the 1st dimension to be integrated in the next step), and distributed(X, 1) is used.
% Try the following along the 1st dim
% The syntax with dim is for the so-called 'Composite array', see doc
% distributed
xd = distributed(rand(20,8,6));
y = squeeze(trapz(xd))
y = 8.2293 9.7236 8.1337 7.3964 8.8491 8.7905 11.4429 8.1487 10.3092 7.6098 9.9407 9.9593 8.4093 9.6940 9.1529 8.2184 8.9330 10.8494 11.1636 10.2440 9.0015 9.0076 11.0077 9.1387 10.8180 8.4163 11.0037 9.4596 10.3310 11.7726 9.3094 10.5408 8.0568 10.5597 8.5339 10.8676 12.5096 8.2943 11.0609 9.3801 9.5628 9.5251 8.4620 11.0499 8.9461 8.4494 10.8111 10.9607
@Chunru Thank you. It was enough to delete the argument of dimension.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 8월 9일

댓글:

2021년 8월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by