Double integral over array

1 visualización (últimos 30 días)
steve solomon
steve solomon el 1 de Feb. de 2020
Comentada: steve solomon el 2 de Feb. de 2020
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

Respuestas (1)

David Hill
David Hill el 1 de Feb. de 2020
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 comentarios
David Hill
David Hill el 1 de Feb. de 2020
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
steve solomon
steve solomon el 2 de Feb. de 2020
thanks David. That looks like it should be faster but it's not, about an hour of run time.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by