Why does quad work when integral does not?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Walter Roberson
el 4 de Oct. de 2016
My testing in Maple suggests approximately 17.503850498058055284389205052946 -37.416687039385925796084425375631*i which is slightly different than the quad value, possibly just numeric roundoff.
Respuestas (1)
David Goodmanson
el 5 de Oct. de 2016
Editada: David Goodmanson
el 5 de Oct. de 2016
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 comentario
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!