Integral of two variables divergent function

2 views (last 30 days)
I am new to matlab and I am trying to understand how it works. I managed to integrate some functions of two variables that could diverge
eps=1/100;
A=5;
B=6;
x0=11/2;
for i=1:100000;
passo(i)= i/1000;
end
cts=@(x)coth(pi*(x)/10)/10;
deltaS=(B-A)/10;
for i=1:100000;
deltaS(i)=integral(@(x)exp(-((passo(i)-x-x0).^2)), A, B);
if(passo(i)<(A-eps))
ctqST(i)=-integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), passo(i)-B, passo(i)-A);
elseif(passo(i)>(B+eps))
ctqST(i)=-integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), passo(i)-B, passo(i)-A);
elseif(passo(i)<(B-eps)&passo(i)>(A+eps))
ctqS1= -integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), eps, passo(i)-A);
ctqS2= -integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), passo(i)-B, -eps);
ctqST(i)=ctqS2+ctqS1;
else
ctqST(i)=0;
end
risultato(i)=1-deltaS(i)+ctqST(i);
end
Now I have to integrate something that seems simpler,
cts=@(x)tanh(pi*(x)/10)*(sqrt(5)*0.8526)/(20*2*10);
for i=1:1000;
passo(i)= i/100-0.1;
end
eps=1/100;
A=-1;
B=10;
deltaS=(B-A)/10;
for i=1:1000;
deltaS(i)=integral(@(x)(passo(i)-x).^(-3/8), -Inf, Inf);
ctqST(i)=-integral(@(x)cts(x).*((passo(i)-x).^(-3/8)), -Inf, Inf);
risultato(i)=1-deltaS(i)+ctqST(i);
end
but I have a lot of warnings and the integral does not really work as it should (when it works, it give me a constant function, and sometimes matlab crash!).
What am I doing wrong?
(Maybe there is a simpler way to integrate and plot a function f(x)=int(g(x,y)dy) when g(x, y) diverges for some values... I don't know)
Thanks!
edit: I've also tried to use a simpler function (with no complex values), like
ctqST(i)=-integral(@(x)tanh(pi*(passo(i)-x)/10).*((x).^(-3/8)), 0, Inf);
but I still have problems...

Accepted Answer

Walter Roberson
Walter Roberson on 4 Feb 2017
You have
integral(@(x)(passo(i)-x).^(-3/8), -Inf, Inf);
With an odd power (3) that preserves the sign of x, and passo(i)-x is strictly linear, so the effect is that the passo(i)-x is the same as a linear shift and sign reversal of the whole graph compared to x^(-3/8) . That preserves the existence and behavior of singularities and just moves their position, and since the entire range -inf to +inf is gone over, the movement of their positions does not affect the overall integral. No matter what non-infinite passo() you use, the result will be the same as integral of -(x^(-3/8)) . At 0 (or at passo(i)) that is 0^(-3/8) which is limit( 1/(x^(3/8)), x = 0) which is complex infinity from one side and infinity from the other side and so it is a non-removable singularity that cannot result in a finite value.
As explained above, you should expect the same result for each, to within working precision.
  3 Comments
Walter Roberson
Walter Roberson on 4 Feb 2017
>> integral(@(x)x.^(-3/8), -Inf, Inf)
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.0e+10. The integral may not exist, or it may be difficult to
approximate numerically to the requested accuracy.
> In integralCalc/iterateScalarValued (line 372)
In integralCalc/vadapt (line 132)
In integralCalc (line 103)
In integral (line 88)
ans =
11216723697.9826 - 7494775162.43515i
I would not say that worked. The analytic solution is infinity + infinity*I
For real-valued finite passo, the analytic
int(tanh((1/10)*Pi*(passo-x))/x^(3/8), x = 0 .. infinity)
is -infinity. The expression is positive from 0 to passo(i) and is negative and increases only slowly from passo(i) to infinity, so you have a infinity of negative numbers that more than cancel out the positive portion.
Aethyr
Aethyr on 5 Feb 2017
Oh, that was really a stupid mistake from me... Now I have to understand why a velocity is given by a non converging integral, but I think this is not related to matlab :) Thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!