While evaluating an integral with expensive computation of the integrand, I tried the adaptive integration provided by the integral function. Unfortunately the function seems not to accept the desired (lower) tolerance argument, if the integral is not improper as in the example from the help file. Instead of taking the desired tolerance, integral seems to work with default tolerance in any case. I give a minimal example for illustration:
if true
% code
f = @(t) log(t);
I_true1 = -1;
I_true2 = 3*log(3)-2*log(2)-1;
for k = 2:2:12
epsi = 10^(-k);
I1 = integral(f,0,1,'RelTol',0,'AbsTol',epsi);
I2 = integral(f,2,3,'RelTol',0,'AbsTol',epsi);
fprintf('%1.1e %1.4e %1.4e\n', epsi, abs(I1-I_true1), abs(I2-I_true2))
end
end
producing the output
1.0e-02 1.7536e-07 1.1102e-16
1.0e-04 1.7536e-07 1.1102e-16
1.0e-06 1.0960e-08 1.1102e-16
1.0e-08 1.7124e-10 1.1102e-16
1.0e-10 6.6880e-13 1.1102e-16
1.0e-12 1.0214e-14 1.1102e-16
Has anyone an idea how to change this behaviour? Thanks in advance for your help!

 채택된 답변

Mario
Mario 2018년 8월 17일

0 개 추천

In the meanwhile I found the answer: integral works initially with 150 evaluations of the integrand. In the example I found problematic, machine precision is reached already in this initial configuration.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2018년 8월 15일

답변:

2018년 8월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by