I am using the integralN function to do a 4 dimensional integral of a complicated function (if you're interested I put it at the end of the post).
I am doing the integration starting at (r1, r2) = (1.8, 1.8)
. Analytically, this function is defined at r1 = r2
however, numerically Matlab treats everything with matching coordinates as NaN
.
Is there any way I can avoid this behavior? As an FYI adding eps
to one to the lower bounds doesn't work.
f1 =@(r) 5*r.^2 + 2;
f2 =@(r) 2*r.^2 + 12;
f1p = der(f1);
f2p = der(f2);
dF = @(r1,t1,r2,t2)((r1.*r2.*(f1(r1)-f2(r2)+(-r1+r2.*cos(t1-t2)).*f1p(r1)).*(f1(r1)-f2(r2)+(r2-r1.*cos(t1-t2)).*f2p(r2)))./(pi.*(r1.^2+r2.^2-2.*r1.*r2.*cos(t1-t2)+(f1(r1)-f2(r2)).^2).^2))
function df = der(f)
syms x
df = matlabFunction(diff(f(x)));
end
I figured out a wrap around function that will force the correct output, where
funMatch
andfunNoMatch
are 4d functions and my limits were stored inLimit
.