Borrar filtros
Borrar filtros

Evaluating Principal Value Integral

29 visualizaciones (últimos 30 días)
fredo ferdian
fredo ferdian el 16 de Ag. de 2017
Comentada: David Goodmanson el 6 de Sept. de 2017
Dear All,
I have a problem to do numerical integration of improper integral. I need to calculate the principal value of integral below, from zero to infinity. My final aim is to evaluate this integral for any values of alpha, H, c, and z. So, the singular point(s) are always changing and it means I can’t just do trial and error to find the limit of the integration to avoid the pole(s), right? The function is depicted below
fun =@(S) (2*(S+alpha).*exp(-S.*H).*cosh(S.*(H+c)).*cosh(S.*(H+z)))./((S.*sinh(S.*H))-(alpha*cosh(S.*H)))
integral(fun,0,inf)
Note: alpha, H, are real positive whereas c, and z are real negative with abs(c) and abs(z) < H
Any idea will be highly appreciated.
Thank you very much before. Regards,
Fredo Ferdian
  3 comentarios
Torsten
Torsten el 17 de Ag. de 2017
I did not consider your problem in greater depth, but what makes you think that the principal value of your integral exists and is finite ?
And does the denominator have only one zero ?
Best wishes
Torsten.
fredo ferdian
fredo ferdian el 21 de Ag. de 2017
Hi Torsten,
Actually, it is a well defined problem that already solved before. It is clearly stated that I need to take the principal value of that integral. I just want to try my self. About the denominator, actually there is only one real root and infinitely many imaginary roots. The denominator is a dispersion equation of wave if you might already hear before. So I guess, I only need to consider the one real root for the pole right(?). Initially, I just make some upperbound limit where the (S) can capture the maximum floating point before it goes to infinity/NaN. But, apparently after I tried with a lot of different inputs, you are right, after some evaluation, now I hesitate whether the integral is really finite. But I guess this question does not really related with MATLAB it self. Thanks for your sharp reminder anyway.

Iniciar sesión para comentar.

Respuestas (1)

David Goodmanson
David Goodmanson el 23 de Ag. de 2017
Editada: David Goodmanson el 23 de Ag. de 2017
Hello fredo,
It makes sense to rescale the independent variable using
s = y/H ds = dy/H
which leads to
integrand = ((2/H)*(y+aH).*exp(-y).*cosh(y*(1+cH)).*cosh(y*(1+zH))./((y.*sinh(y))-(aH*cosh(y))
where
aH = alpha*H cH = = c/H zH = z/H
This effectively reduces the problem from four variables to three since H only enters in as a constant in front. For y somewhat larger than 700 the expression gives NaNs as you mentioned, because the exponentials overflow before division of numerator by denominator. However, multiplying both numerator and denominator by exp(-y) leads to
integrand = (1/H)*(y+aH).*exp(y*(cH+zH)).*(1+exp(-2*y*(1+cH))).*(1+exp(-2*y*(1+zH))) ...
./(y.*(1-exp(-2*y))-aH*(1+exp(-2*y)));
This has only decreasing exponentials and takes care of the 'second problem'.
To integrate, here are a couple of methods. Method 1 finds the zero in the denominator and integrates up to a distance y1 on each side. You can vary y1 to see how close you have to get to y0 for the answer to settle down. Method 2 goes around y0 (the pole) with a path in the complex plane, so you don’t need to find the y0 location. The path goes vertically from the origin to (in this case) .1i, and then horizontally from that point out to (inf + .1i). I don’t know for a fact that this path always works but it seems to agree in the cases I tried. (The principal value is the average of two paths: this path which goes above y0 to +inf, and a second path that goes below y0 to +inf. But for a real function these paths are complex conjugates of each other so you end up with the real part of the first path).
In both case the (1/H) factor was ignored in the function and inserted at the end.
H = 100; alpha = .1019; c = -1; z = -1;
% method 1
fun0 = @(y,aH) y.*(1-exp(-2*y))-aH*(1+exp(-2*y));
y0 = fzero(@(x) fun0(x,aH),aH)
y1 = 1e-6;
Ia = integral(@(y) fun(y,aH,cH,zH),0,y0-y1);
Ib = integral(@(y) fun(y,aH,cH,zH),y0+y1,inf);
I1 = (1/H)*(Ia+Ib)
I1 = 0.6296
% method 2
const = .1i;
Ic = integral(@(y) fun(y,aH,cH,zH),0,const);
Id = integral(@(y) fun(y+const,aH,cH,zH),0,inf);
I2 = (1/H)*real(Ic+Id)
I2 = 0.6296
I1-I2
ans = -1.0878e-08
function A = fun(y,aH,cH,zH)
A = (y+aH).*exp(y*(cH+zH)).*(1+exp(-2*y*(1+cH))).*(1+exp(-2*y*(1+zH))) ...
./(y.*(1-exp(-2*y))-aH*(1+exp(-2*y)));
end
  5 comentarios
fredo ferdian
fredo ferdian el 2 de Sept. de 2017
Dear David Goodmanson,
Thank you very much for your suggestion. Yes, I think I will use the method2. I dont think it is possible to provide the code details for Solution1 and Solution2 here, since the formula are quite complicated. Yeah, in the end I use the method 2 as your suggestion. However, I slighly modified the path. I have one last question maybe. Since I know exactly my pole location (k), I made the path just around the pole. For example like this
%
tol = 10^-8;
const1 = k-tol;
const2 = k+tol*i;
const3 = k+tol;
const4 = k-tol*i;
Ic = integral(@(S) fun(S),0,const1);
Id = integral(@(S) fun(S),const1,const2);
Ie = integral(@(S) fun(S),const2,const3);
If = integral(@(S) fun(S),const4,const3);
Ig = integral(@(S) fun(S),const1,const4);
Ih = integral(@(S) fun(S),const3,inf);
I2 = real(Ic+Id+Ie+If+Ig+Ih);
However, the direction of the path does effects the results. I'm sorry for my lackness understanding in evaluating PV integral, but for If and Ig, if I put the integration limit the other way around (eg: If from const3 and const4 and Ig from const4 to const1),the one which compensate each other is the real part instead. Is this correct? I feel weird because I thought I only need to define close boundary around the pole.
Regards,
Fredo Ferdian
David Goodmanson
David Goodmanson el 6 de Sept. de 2017
Hello Fredo,
You have a reasonable approach except that you don’t have to have tol anywhere near as small as 1e-8. In fact that might be counterproductive.
Before, I used y as the variable of integration. Pictorially it makes more sense to use x, so that's done here.
For the p.v. you integrate on one path that goes over the pole and on another path that goes under, and take the average. You have been looking at 'rectangular' paths that would look like
d------e
path1 a=0------b x0 f-------g=inf pole is at x0 (called k before)
.
path2 a=0------b x0 f-------g=inf
m------n
Paths ab and fg on the x axis give real integrals, and the 'curved' paths bdef and bmnf give complex integrals.
As I mentioned you don't have to actually average the two paths, since taking the real part of either path by itself gives the same answer.
For the points on either side of x0, let b = x0-r, f = x0+r, where notation r is used instead of tol. If r is really small like 1e-8, then the integrand takes on huge values near the pole, on the order of 1e8. That's not a real bad problem with an adaptive integration routine like 'integral', but the highly varying integrand affects the accuracy and also takes more time. And there is no reason to do that, because after including the curve integrals the answer is just as exact when, for example r = .1 .
Instead of a three-part rectangular path it's easier to integrate along a semicircular path of radius r, centered at x0, going from b to f. It's an integral in variable theta, with
z = x0 + r*exp(i*theta)
dz = (dz/dtheta)*dtheta where
dz/dtheta = i*r*exp(i*theta) note the important factor of i.
Theta is measured counterclockwise from the x axis as usual and goes from pi to 0 for the upper curve and -pi to 0 for the lower curve.
The code below is similar to before, except the bessel function factor is included. Method 3 is the path discussed above, and method 2 is as before with the path
d-----------------------d+inf
a=0 x0
You can independently adjust r in method 3, and d in method 2, to see how the answer is affected. Over a wide range from 1e-1 to 1e-8 or less for each of them, the two methods agree pretty well and the computations for the larger values of r are faster.
H = 100; alpha = .1019; c = -1; z = -1; R = 10;
aH = alpha*H; cH = c/H; zH = z/H; RH = R/H;
% find pole
fun0 = @(x,aH) x.*(1-exp(-2*x))-aH*(1+exp(-2*x)); % the denominator
x0 = fzero(@(x) fun0(x,aH),aH);
% method 2 (from before) path in complex plane does not need pole location
d = 1e-1;
% integrate straight up from 0, then across to the right
Iup = integral(@(x) funJ(x,aH,cH,zH,RH),0,i*d);
Iright = integral(@(x) funJ(x+i*d,aH,cH,zH,RH),0,inf);
I2 = (1/H)*real(Iup+Iright);
% method 3 (integrate to each side of pole, then around the top in a semicircle
r = 1e-1;
Iab = integral(@(x) funJ(x,aH,cH,zH,RH), 0, x0-r);
Ieh = integral(@(x) funJ(x,aH,cH,zH,RH), x0+r, inf);
Iabove = integral(@(theta) funJarc(theta,r,x0,aH,cH,zH,RH), pi, 0);
I3 = (1/H)*(Iab + Ieh + real(Iabove));
I2and3 = [I2 I3]
diff23 = I2-I3
function A = funJ(x,aH,cH,zH,RH)
A = (x+aH).*besselj(0,x*RH).*exp(x*(cH+zH)) ...
.*(1+exp(-2*x*(1+cH))).*(1+exp(-2*x*(1+zH))) ...
./(x.*(1-exp(-2*x))-aH*(1+exp(-2*x)));
end
function A = funJarc(theta,r,x0,aH,cH,zH,RH)
zcirc = x0 + r*exp(i*theta);
% dz/dtheta = i*r*exp(i*theta);
A = (i*r*exp(i*theta)).*funJ(zcirc,aH,cH,zH,RH);
end

Iniciar sesión para comentar.

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by