Double integral with one integral having limits as a function of other variable

13 ビュー (過去 30 日間)
Shan  Chu
Shan Chu 2017 年 8 月 3 日
コメント済み: Shan Chu 2017 年 8 月 3 日
Dear all, I have the problem below:
l1=3e-3;
l2=4e-3;
r1=11e-3;
r2=12e-3;
fun_Z0=@(x) x^(-5)* A^2 *((l2-l1)+(exp(-x*(l2-l1))-1)*x^(-1));
where
A=integral(y*besselj(1,y), x*r1, x*r2)
I would like to calculate
Z=integral(fun_Z0, 0, Inf)
Could you please suggest a function that could handle this problem?
Thanks

採用された回答

Teja Muppirala
Teja Muppirala 2017 年 8 月 3 日
編集済み: Teja Muppirala 2017 年 8 月 3 日
You can put functions inside of functions
%%Embed A into fun_Z0, and tell INTEGRAL to only accept scalar inputs
l1=3e-3;
l2=4e-3;
r1=11e-3;
r2=12e-3;
A=@(z) integral(@(y) y.*besselj(1,y), z*r1, z*r2)
fun_Z0=@(x) x^(-5)* A(x)^2 *((l2-l1)+(exp(-x*(l2-l1))-1)*x^(-1));
% This seems to be a hard integral. You'll get some warnings here, but it works
Z=integral(fun_Z0, 0, Inf, 'ArrayValued', true,'AbsTol',0)
Z =
6.0922e-15
%%If you really want to make sure, break it up into pieces
intValue = 0;
tol = 1e-6;
for n = 0:100
prevValue = intValue;
Z=integral(fun_Z0, 5000*n, 5000*(n+1), 'ArrayValued', true,'AbsTol',0);
intValue = intValue + Z;
if abs(1 - intValue/prevValue) < tol
break
end
end
intValue
intValue =
6.0922e-15
  1 件のコメント
Shan  Chu
Shan Chu 2017 年 8 月 3 日
Thank you so much sir, It is what I am looking for. I didn't know it is possible to put functions inside functions.

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

その他の回答 (1 件)

Torsten
Torsten 2017 年 8 月 3 日
  1 件のコメント
Shan  Chu
Shan Chu 2017 年 8 月 3 日
Thank you so much for your time. But it is rather complicated. Thanks

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

Community Treasure Hunt

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

Start Hunting!

Translated by