Double integral over array
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
Evaluating a double integral over a large number of pixels takes an hour, even with the parallel toolbox. I can't figure out how to vectoirze this calculation to speed it up...suggestions welcome!
parfor iRow = 1:nRows
for iCol = 1:nCols
X = pitch_mm * (iRow - nRows/2 - 0.5);
Y = pitch_mm * (iCol - nCols/2 - 0.5);
% projected solid angle differential
dOmega = @(Xap,Yap) (apDist_mm ./ ((apDist_mm)^2 + (X-Xap).^2 + (Y-Yap).^2)).^2;
% convert to polar & integrate
dOmegaPolar = @(theta,r) dOmega(r.*cos(theta),r.*sin(theta)).*r;
cos4(iRow,iCol) = integral2(dOmegaPolar,0,2*pi,0,apDiam_mm/2);
end
end
댓글 수: 0
답변 (1개)
David Hill
2020년 2월 1일
X=pitch_mm*([1:nRows]-nRows/2-.5);
Y=pitch_mm*([1:nCols]-nCols/2-.5);
dOmegaPolar = @(theta,r) dOmega(r.*cos(theta),r.*sin(theta)).*r;
dOmega = @(Xap,Yap) (apDist_mm ./ ((apDist_mm)^2 + (x-Xap).^2 + (y-Yap).^2)).^2;
cos4=zeros(nRows,nCols);%preallocate
parfor iRow = 1:nRows
x=X(iRow);
for iCol = 1:nCols
y=Y(iCol);
cos4(iRow,iCol) = integral2(dOmegaPolar,0,2*pi,0,apDiam_mm/2);
end
end
Above should speed things up some.
댓글 수: 2
David Hill
2020년 2월 1일
X=pitch_mm*([1:nRows]-nRows/2-.5);
Y=pitch_mm*([1:nCols]-nCols/2-.5);
dOmegaPolar = @(theta,r) dOmega(r.*cos(theta),r.*sin(theta)).*r;
cos4=zeros(nRows,nCols);%preallocate
parfor iRow = 1:nRows
for iCol = 1:nCols
dOmega = @(Xap,Yap) (apDist_mm ./ ((apDist_mm)^2 + (X(iRow)-Xap).^2 + (Y(iCol)-Yap).^2)).^2;%this needs to move inside loop
cos4(iRow,iCol) = integral2(dOmegaPolar,0,2*pi,0,apDiam_mm/2);
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!