フィルターのクリア

Symbolic integration inside numerical integration

3 ビュー (過去 30 日間)
Gunnar
Gunnar 2018 年 3 月 17 日
コメント済み: Star Strider 2018 年 3 月 20 日
I would like to solve the following integral numerically:
As far as I can tell, the built-in function integral2 is not applicable here due to the nature of the expression. Instead, from Evaluating Double Integrals, I arrive at the following solution which takes forever to compute due to the third line:
syms x r
firstint=int(1./(1+x.^2.5),x,r,Inf)
answer=int(r.*exp(-r.^2).*firstint,r,0,Inf),
double(answer)
The last line is just to get a numerical answer out of the symbolic integration. To speed up things, I am inclined to replace the third line with the built-in function integral, but it requires me to make firstint into a handle first, for example by using another built-in function called matlabFunction. Unfortunately, I get an error when doing the following:
syms x r
firstint=int(1./(1+x.^2.5),x,r,Inf),
firstintHandle = matlabFunction(firstint),
answer=integral(r.*exp(-r.^2).*firstintHandle,0,Inf),
Any ideas on what to do? Please be very specific. Your help is greatly appreciated.

採用された回答

Star Strider
Star Strider 2018 年 3 月 17 日
See if this does what you want:
firstint = @(r) integral(@(x) 1./(1+x.^2.5), r, Inf, 'ArrayValued',1);
secondint = @(r) r.*exp(-r.^2).*exp(-firstint(r));
answer = integral(secondint, 0, Inf, 'ArrayValued',1)
answer =
0.274214226644371
The code appears to me to be correct. I defer to you to be certain it is.
  6 件のコメント
Gunnar
Gunnar 2018 年 3 月 20 日
編集済み: Gunnar 2018 年 3 月 20 日
Thanks for your replies, Star Strider. I also managed to get a numeric answer based on the first approach, but the error message indicates that it might not be accurate. In comparison, your second solution takes much longer to compute due to the need to do symbolic integration, but on the other hand there is no error message. It is a tradeoff, and it is difficult to know what is the best course of action. Indeed, MATLAB seems to offer multiple ways to numerically evaluate integrals (see for example function 'trapz'), and some integrals may work with one method but not the other. With that said, many thanks for the help so far.
Star Strider
Star Strider 2018 年 3 月 20 日
Again, my pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by