Integral from a function that has a singularity

Hello I want to take an integral from the function that has a singularity(pole), by quadgk but this common don't give a right answer .for instance an integral of the function 1/(x-1) from(-2,2) anyone can guide me thanks

 採用された回答

Star Strider
Star Strider 2017 年 1 月 29 日

1 投票

The best I can do is to rely on the Symbolic Math Toolbox, that came up with a piecewise result. Perhaps you can use this in your code:
syms x L U
f(x) = 1/(x-1);
intf = int(f,x, L, U)
intf =
piecewise(L <= 1 & 1 <= U, int(1/(x - 1), x, L, U), 1 < L | U < 1, log(U - 1) - log(L - 1))
The ‘L’ and ‘U’ variables are the lower and upper limits of integration, respectively.

6 件のコメント

Kurt Hakan
Kurt Hakan 2017 年 1 月 29 日
thanks for your answer. I would like to ask my question from other point of view. MATLAB Saied in help, the quadgk common can solve the integral of functions that have a singularity but here cant solve the problem.??!!
Star Strider
Star Strider 2017 年 1 月 29 日
My pleasure.
In R2016b, the quadgk function will do the integration without error, but will throw Warnings. The quadgk function will also accept a 'Waypoints' argument, where you can ‘inform’ it about the singularities that exist within the limits of integration, and integrate around them if you wish.
For example:
f = @(x) 1./(x-1);
int1 = quadgk(f, -2, 2)
int2 = quadgk(f, -2, 2, 'Waypoints',[1, 1], 'MaxIntervalCount',1E+7)
int1 =
12.9845608756444
int2 =
-0.926665144495417
They both throw warnings. You can also divide the integral into two regions, from -2 to 1 and 1 to +2 and add them.
I am not certain there are any good ways to deal with such problems, although there are applied mathematicians here who I hope will add to this discussion.
Kurt Hakan
Kurt Hakan 2017 年 1 月 29 日
編集済み: Kurt Hakan 2017 年 1 月 29 日
int2 = -0.926665144495417 is not correct answer and in we divide the(-2,2) to (-2,1)and (1,2) and take an integral the answer is
int3 =
-1.1859
but the correct answer is (-log(3)=-1.09861).
???????
Star Strider
Star Strider 2017 年 1 月 29 日
If you specify the limits of integration to go from -2 to +2 with 'Waypoints' around the singularity (doing complex contour integration), you get exactly that result!
int4 = quadgk(f, -2, 2, 'Waypoints',[1+1i, 1-1i], 'MaxIntervalCount',1E+7)
int4 =
-1.09861228866811
Kurt Hakan
Kurt Hakan 2017 年 1 月 29 日
thanks
Star Strider
Star Strider 2017 年 1 月 29 日
As always, my pleasure.
Wolfram Alpha evaluates it using the Cauchy principal value

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by