Why does quad work when integral does not?

조회 수: 7 (최근 30일)
Stephen Ogier
Stephen Ogier 2016년 10월 4일
댓글: Walter Roberson 2016년 10월 5일
I'm working on an antenna array problem, and I've run into a quirk in the MATLAB integration routines. When I integrate using the newer integrate function, I get an incorrect result for certain values. When I use the older quad function, my results are correct. Why is this happening? Is there some way to make integrate more accurate? Decreasing the absolute and relative error tolerances didn't help. This is concerning because quad is being deprecated in favor of integrate.
The function was called with the following parameters Z21(0.5, 0.5, 0.35, 0) quad gives Z21 = 17.4274 -37.3897i integrate gives Z21 = 5.4256 -32.7371i
This just gets worse as d gets smaller.
function [ Z ] = Z21( L1, L2, d, h )
%Z21 Computes mutual impedancee of two parallel dipoles with sinusoidal
%current
% Inputs are normalized to wavelength
eta = 120*pi;
I = 1;
%Inline helper functions for clarity
r = @(z) sqrt(d.^2 + (h+L2./2+z-L1./2).^2);
R1 = @(z) sqrt(d.^2 + (h+L2./2+z-L1).^2);
R2 = @(z) sqrt(d.^2 + (h+L2./2+z).^2);
G_norm = @(R) exp(-1i*2*pi*R)/(4*pi*R);
Integrand = @(z) sin(pi.*L2 - 2.*pi.*abs(z)).*(G_norm(R1(z)) + G_norm(R2(z)) - 2.*cos(pi.*L1).*G_norm(r(z)));
%ezplot(@(z) real(Integrand(z)),[-L2/2,L2/2])
%Z = 1i*eta *I* quad(Integrand,-L2/2,L2/2);
Z = 1i*eta *I* integral(Integrand,-L2/2,L2/2, 'RelTol', 1e-13, 'AbsTol', 1e-17);
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 10월 4일
My testing in Maple suggests approximately 17.503850498058055284389205052946 -37.416687039385925796084425375631*i which is slightly different than the quad value, possibly just numeric roundoff.

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

답변 (1개)

David Goodmanson
David Goodmanson 2016년 10월 5일
편집: David Goodmanson 2016년 10월 5일
Hi Stephen, You are missing a very important dot in your definition of G_norm. If you replace
/ with ./
then both methods agree,without any special tolerance requests for the 'integral' function.
It's interesting that if a,b and c are equal-length row vectors, then
(a/b).*c and (a./b).*c
both produce row vectors, with no error message due to mismatched dimensions, but those vectors are different. However the expressions agree if a,b,c are scalars. So I will speculate that quad works because it accesses its function one point at a time, but integral is more vectorized and so gets it 'wrong'.
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 10월 5일
Good catch, David. And yes, integral() does vectorize.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by