From: Josh on
Hi everyone,

I've been comparing numerical integration results between Matlab and Mathematica (quadgk and NIntegrate options). I have given both the same symbolic expression that has variables t and tau and is highly oscillatory. So far only Mathematica has been able to produce the correct result. However Matlab's result is just noticeably there but is much noiser. Unfortunately I can't post plots of the two results.

The integration is performed by picking a t value and evaluating "FullFunction" using feval(FullFunction, t=t_numer(j), tau) where "tau" is kept symbolic. This result is re-cast as an anonymous function in tau as "FullFunction_tStep = @(tau) feval(FullFunction,t_numer(j),tau)". Then this result, "FullFunction_tStep" is passed to quadgk using quadgk(FullFunction_tStep,a,b).

The problem originates from one of three possible sources: (1) the partial numerical and symbolic feval step, (2) re-cast the result of #1 into anonymous function in tau and/or (3) the quadgk() function.

Is there another way to handle the feval and re-casting steps to carry out the integration?

Thank you very much in advance.

MATLAB CODE:

a = 0;
b = Inf;
N2 = 4096
t_numer = linspace(-pi,pi,N2);
AbsTols = 1e-4; %1e-6;
RelTols = 1e-4; %1e-12;
MaxIntervals = 60000;

% long function
FullFunction = @(t,tau) (i.*((pi./(tau/2)).^(3/2)).*(i*((1/(p))^(3/4))*(((E0*c./(w0*tau)).*(cos(w0*t).........

%pick t-step, eval t as t_numer, leave tau symbolic, then integrate over full tau
for j=1:length(t_numer)
FullFunction_tStep = @(tau) feval(FullFunction,t_numer(j),tau);
F =quadgk(FullFunction_tStep,a,b,'RelTol',RelTols,...
'AbsTol',AbsTols,'MaxIntervalCount',MaxIntervals);

result(j) = F + conj(F);
fprintf('Completed t step # %u out of %u\n',j,N2);
end