Help solving an integral numerically

I am trying to solve an integral where there is only an integration variable (kx in the code below) but it has to be solved in a 2D space defined by x and y coordinates. It corresponds to a Green's function in 2D.
The following is my approach defining it as a handle function, but it seems to take for ever to run.
clc; clear all;
f = 8500;
c0 = 343;
rho = 1.225;
omega = 2*pi*f;
k = omega/c0;
Z = -426;
lx = 0.1;
ly = 0.1;
x0 = 0;
y0 = ly/1000;
nx = 50;
ny = nx/2;
x = linspace(-lx,lx,nx);
y = linspace(0,ly,ny);
G = zeros(length(x),length(y));
integrand = @(x,y,kx) ((exp(1i*(kx*x + sqrt(k.^2 - kx.^2).*abs(y))))./sqrt(k.^2 - kx.^2));
Gz = @(x,y) integral(@(kx)integrand(x,y,kx), 0, 200, 'ArrayValued', true);
for ii = 1:length(x)
for jj = 1:length(y)
G(ii,jj) = (1j/4/pi)*Gz(x(ii),y(jj));
end
end
Any help will be appreciated.

댓글 수: 4

Torsten
Torsten 2022년 3월 1일
Remove the 'ArrayValued',true - option.
smonos
smonos 2022년 3월 1일
If I remove it I get the following error:
Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued'
option to true.
Torsten
Torsten 2022년 3월 1일
편집: Torsten 2022년 3월 1일
Then use
integrand1 = @(x,y,kx) real(((exp(1i*(kx*x + sqrt(k.^2 - kx.^2).*abs(y))))./sqrt(k.^2 - kx.^2)));
integrand2 = @(x,y,kx) imag(((exp(1i*(kx*x + sqrt(k.^2 - kx.^2).*abs(y))))./sqrt(k.^2 - kx.^2)));
Gz = @(x,y) integral(@(kx)integrand1(x,y,kx), 0, 200) + 1i*...
integral(@(kx)integrand2(x,y,kx), 0, 200);
smonos
smonos 2022년 3월 1일
Many thanks!

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

답변 (0개)

카테고리

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

제품

릴리스

R2021b

질문:

2022년 3월 1일

댓글:

2022년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by