Asked by Nahman
on 16 Aug 2019

Here is the code that I am running

lambda = 40.8382-1i*6.4807e-15;

L0 = 4.5866e-8;

integrand = @(z) airy(0,-z./L0-lambda).*conj(airy(0,-z./L0-lambda));

lowerbound = -1;

C = integral(integrand,lowerbound,0,'ArrayValued',true)

As you can see I am integrating the function "integrand", which is a complex valued airy function times its conjugate, meaning it is strictly positive. C in this case is 9.3364e-08. When changing the bound of lower integration to -0.01, C becomes 1.9183e-08, which is understandably lower. However, setting lowerbound = -0.001 gives 9.3364e-08 again. Now I know most of the weight of this function is between 0 and about 1e-5 so I suspect that 9.3364e-08 is the right answer, but that there are specific points where it does not evaluate properly. Running this loop:

for i = 1:1000

lowerbound = -1/(i);

C(i) = integral(integrand,lowerbound,0,'ArrayValued',true);

end

figure

plot(C)

which produces this

seems to confirm my suspicions. Would anyone know why this would be the case?

Answer by Matt J
on 16 Aug 2019

Edited by Matt J
on 16 Aug 2019

Accepted Answer

A plot of the function reveals highly oscillatory behavior in the interval [-2e-6,0] which then flattens out to zero in [-1,-2e-6].

fplot(integrand,[-2.5e-6,0],'MeshDensity',1e2)

To discretize the integral reliably, you need to narrow the calculation to the sub-interval [-2e-6,0] and ensure a discretization interval that is finer than the oscillations. Below, I compare the result of integral() against trapz() with two levels of discretization fineness,

for i=1:10

lowerbound = -2.5e-6/i;

zs=linspace(lowerbound,0,1e5);

Ctrapz1(i)=trapz(zs,integrand(zs))

zs=linspace(lowerbound,0,1e6);

Ctrapz2(i)=trapz(zs,integrand(zs))

C(i) = integral(integrand,lowerbound,0,'ArrayValued',true)

end

plot([C-Ctrapz1;C-Ctrapz2].'); legend('C-Ctrapz1','C-Ctrapz2')

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Walter Roberson (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/476449-increasing-the-bounds-of-integration-on-a-strictly-positive-function-decreases-the-result#comment_735948

## Nahman (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/476449-increasing-the-bounds-of-integration-on-a-strictly-positive-function-decreases-the-result#comment_735950

## Walter Roberson (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/476449-increasing-the-bounds-of-integration-on-a-strictly-positive-function-decreases-the-result#comment_735959

## Walter Roberson (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/476449-increasing-the-bounds-of-integration-on-a-strictly-positive-function-decreases-the-result#comment_735963

## Nahman (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/476449-increasing-the-bounds-of-integration-on-a-strictly-positive-function-decreases-the-result#comment_735966

Sign in to comment.