5 views (last 30 days)

Hi

I am integrating some complex equations using vpaintegral in matlab. it is triple integration and the equations are too complex, so the calculation time is too high

when the reltol and abstol is set to 1e-1, it takes about 3-4 hours to compute the result, but I need more accuracy.

when I set reltol and abstol to 1e-2 it takes about 12 hours!! and yet I need more accuracy!!

The questions is that is it necessary to give both reltol and abstol values to get accurate result?? or one of them are enough in my work? and does it make any difference in calculation time to set only one of them (or it doesn't affect)? if so, which one should I use?

(the value of my final result is between 990 to 1001)

thank you

Walter Roberson
on 4 Aug 2020

Edited: Walter Roberson
on 5 Aug 2020

Internally, vpaintegral() always works with tolerances. It has default values that it uses. It is not the case that providing a tolerance as an option results in the code proceeding differently -- no

if relative_tolerance_was_specified

do some extra work

end

So you should not worry about only providing one instead of the other to have it do less work: it is always going to be doing the work, just with default values if you did not specify the option.

Typically reltol is more important in figuring out when to stop. Typically abstol is there as a fall-back for places where the relative values get small. You know that your final result is roughly 1000, but there could still be ranges of your integral where the values are (say) near 1e-15, and over that stretch vpaintegral() might be doing a lot of fine work to try to be more precise about the small numbers, but you in your knowledge of the overall range of results might say that it is pointless to be precise down below 1e-15 about a value that is effectively going to contribute nothing to the overall result, so you might want to put in an absolute tolerance of (say) 1e-5.

Absolute tolerance of 1e-5 does not mean that it will persue the integration until it is certain that the result over the entire integration is within 1e-5 of the "correct" value: instead it means that values less than 1e-5 would more or less filtered out.

There are some cases where the absolute values might get quite small, and yet the contribution could be very important. For example the integral of 1/x, as x goes to infinity, is infinite, ln(infinity), and yet the contributions up around realmax are only about 5e-309 each, with the total contribution by realmax only being about 709 -- the contributions beyond realmax are all negligibly small from the perspective of IEEE 754 double precision, and yet in theory they contribute an infinite amount out to infinity.

Therefore, it is not always appropriate to use an absolute tolerance: you have to know enough about the function to be able to establish that the integral of the missed values will not matter to your accuracy.

In the meantime, I recommand that you use matlabFunction() to turn the vpaintegral() with symbolic upper bound into an anonymous function that calls integral()

I was about to suggest you consider using the matlabFunction() options 'File' and 'optimize', but then I remembered that I have open cases against bugs in the optimization function that can result in the optimized function being quite wrong. It might still be worth using the 'File' option, but if you do, then explicitly set 'optimize' to false.

Opportunities for recent engineering grads.

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

Start Hunting!
## 0 Comments

Sign in to comment.