MATLAB Answers

Integral inside integral is taking too much time

22 ビュー (過去 30 日間)
Waseem Akhtar
Waseem Akhtar 2021 年 7 月 20 日
コメント済み: Walter Roberson 2021 年 8 月 14 日
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 件のコメント
Waseem Akhtar
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 日
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 件)




Community Treasure Hunt

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

Start Hunting!

Translated by