Why does quad work when integral does not?

4 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by