Condition based integration in MatLab

I have an integration : Int(rp.^2.*G(r,rp)*drp) where the integration is with respect to rp and the limit is on rp : 0->inf and G(r,rp) = 1/r for r>rp and G(r,rp)=1/rp for r<rp How to implement this integral in MatLab.

2 件のコメント

David Goodmanson
David Goodmanson 2024 年 1 月 7 日
Hi pritha,
For large rp the integral goes like
Int G(r,p) rp^2 drp = Int (1/rp) rp^2 drp = Int rp drp
and unfortunately, since the upper limit for rp is infinity, this integral diverges.
pritha
pritha 2024 年 1 月 7 日
Hi David,
Thank you for your reply. If i consider the upper limit as 15-20? How will it be constructed in MatLab?

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

 採用された回答

Torsten
Torsten 2024 年 1 月 7 日
移動済み: Torsten 2024 年 1 月 7 日

1 投票

syms r R rp real positive
G(r,rp) = piecewise(r<rp,1/rp,r>=rp,1/r);
int(rp^2*G(r,rp),rp,0,R)
ans = 

5 件のコメント

pritha
pritha 2024 年 1 月 7 日
Thank you so much for your response. It helps me a lot.
Torsten
Torsten 2024 年 1 月 7 日
The extra distiction for R = r is not necessary since r^2/2 - r^2/6 = r^2/3, thus the formula for r < R will still be valid for r <= R.
pritha
pritha 2024 年 1 月 10 日
Hi Torsten,
I have a doubt regarding the limit in this problem. Here the limit is given as (0,Inf). Is it possible to handle this limit in this problem?
Torsten
Torsten 2024 年 1 月 10 日
編集済み: Torsten 2024 年 1 月 10 日
If r is fixed and R -> Inf, you see from the integration result that the second case (r<R) is the relevant one, and the result is - as already answered by @David Goodmanson - lim(R->Inf) (R^2/2-r^2/6) = Inf
syms r rp real positive
G(r,rp) = piecewise(r<rp,1/rp,r>=rp,1/r);
int(rp^2*G(r,rp),rp,0,Inf)
ans = 
pritha
pritha 2024 年 1 月 10 日
Thanks a lot.

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2024 年 1 月 7 日

コメント済み:

2024 年 1 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by