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
2022년 3월 1일
Remove the 'ArrayValued',true - option.
smonos
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
2022년 3월 1일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!