Integral inside integral is taking too much time

22 ビュー (過去 30 日間)
Waseem Akhtar
Waseem Akhtar 2021 年 7 月 20 日
コメント済み: Walter Roberson 2021 年 8 月 14 日
Hi,
I am trying to evaluate integral inside integral using the following script but it is taking too much time, is there anyway I can reduce the time of evaluation:
f =@(x,y) x+y; % "x+y is just a simple example, the actual function is way more complicated"
integral(@(y) exp(-integral(@(x) f(x,y),a,b,'RelTol',1e-8,'AbsTol',1e-13),aa,bb,'RelTol',1e-8,'AbsTol',1e-13,'ArrayValued',true)
  5 件のコメント
Walter Roberson
Walter Roberson 2021 年 7 月 20 日
Sometimes it helps to reverse the order of integration.
Waseem Akhtar
Waseem Akhtar 2021 年 7 月 23 日
編集済み: Waseem Akhtar 2021 年 7 月 23 日
@Torsten Thank you for your reply. I tried symbolic integration but it is even taking longer than the numerical integration
Thank you for your help!

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 7 月 20 日
Use worse tolerances to reduce the computation time, at the expense of decreased accuracy.
In some cases, switching to integral2 might help. You are using arrayvalued so that would require multiple calls to integral2.
The fastest approach can depend on what your function is sensitive to. Numeric integration is adaptive, so if part of the range has rapid changes then it can slow down. In some cases, the rapid change only applies for one part of a range, and if you are using arrayvalued you can end up having to do the detailed integration for everything according to the worst part of the range, so sometimes arrayfun of non-arrayvalued can be faster. Sometimes .
  14 件のコメント
Walter Roberson
Walter Roberson 2021 年 8 月 14 日
The outer integral() passes a vector of values into the inner interval. When the inner integral is set to ArrayValued, the inner integral only passes in one trial omega value at a time, and for that omega does the value calculation that is vectorized with respect to the vector of values from the outer integral, l . The inner integral continues to pass in one value at a time until it is satisfied that it has met integration tolerances for all elements corresponding to the positions in l .
When the outer integral is marked as array valued instead, but the inner integral is not, then the outer integral would pass a single value at a time to the inner integral. The inner integral would then construct a vector of values to pass to be calculated with the scalar l from the outer integral.
What is the difference, since either way the inner calculation is going to be evaluate with a vector? Well, there is not necessarily an inherent advantage to one or the other. However... depending on the calculations for each of the variables, it might happen to be the case that numerically one of the two versions happens to have its integral converge faster than the other way.
Walter Roberson
Walter Roberson 2021 年 8 月 14 日
value = int(exp(-(T-L.*(0.97)).*(2e+05)).*(int((exp(-omega-(((2e+05).*sqrt((T-L.*(0.97)).^2+(U+L.*(0.26)).^2)).^2./(4*omega))))./(2*omega),omega,AA,BB)),L,A,B);
valF = matlabFunction(value, 'vars', [AA,BB,A,B,U,T]);
That is going to fail because matlabFunction does not generate integral2() automatically when it sees nested integral(), and matlabFunction() does not know it should generate 'arrayvalued' at any point.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by