Search code examples
matlabnumerical-integration

MATLAB Error: Contour endpoints and waypoints must be finite


I am trying to evaluate the following code:

% Parameters
theta=0;
v=1;

lamdaA= 0.0001;
ha=170;
pta=1;
etaa=2.8;
maL=1;

lamdaG= 0.001;
hg=60;
ptg=1;
etag=3.5;
maG=1;

Aa=0.3575;
Ag=1-Aa;

%Numerical Evaluation
syms ra rg wi ss xg

Eg=(((pta/ptg)^(2/etaa))*((rg^2+hg^2)^(etag/etaa)))-ha^2;
Egg=matlabFunction(Eg);
Ea=(((ptg/pta)^(2/etag))*((ra^2+ha^2)^(etaa/etag)))-hg^2;
Eaa=matlabFunction(Ea);
sEg=@(xg) sqrt(Egg(xg));

Iaaa=matlabFunction(wi*(1-((1+((pta*ss*(wi^(-etaa)))/maL))^(-maL))));
LIa=@(ss,xg) integral(@(wi)Iaaa(ss,wi),sEg(xg), Inf(1));

sg=@(xg) (theta(v))./(ptg.*((xg.^2+hg.^2).^(-etag./2)));
Pcovg2inh=@(xg) exp(((-2.*pi.*lamdaG.*((xg.^2)+(hg.^2)).*theta(v).*maG)/(etag-2)).*hypergeom([1 1-(2/etag)],2-(2/etag),-theta(v).*maG))...
    .*exp(-2.*pi.*lamdaA.*LIa(sg(xg),xg));

fxg1= @(xg) 2.*pi.*lamdaG.*xg.*exp(-pi.*lamdaG.*xg.^2);
fxg2= @(xg) ((2.*pi.*lamdaG)./Ag).*xg.*exp(-pi.*(lamdaA.*Egg(xg)+lamdaG.*xg.^2));

Pcovg11= @(xg) fxg1(xg).*Pcovg2inh(xg);
Pcovg22= @(xg) fxg2(xg).*Pcovg2inh(xg);

if Eaa(0)<=0
    Pcovg2h(v)=integral(Pcovg22,0,Inf(1),'ArrayValued', true)
else
    Pcovg1(v)=integral(Pcovg11,0,Eaa(0),'ArrayValued', true);
    Pcovg2(v)=integral(Pcovg22,Eaa(0),Inf(1),'ArrayValued', true);
    Pcovg2h(v)=Pcovg1(v)+Pcovg2(v)
end

But I am getting the following Error Message:

Error using integralCalc (line 34)
Contour endpoints and waypoints must be finite.

It seems that the issue is coming from LIa=@(ss,xg) integral(@(wi)Iaaa(ss,wi),sEg(xg), Inf(1));. For some reason MATLAB can not evaluate the last integration because of this. I searched online but couldn't find ways to resolve this. Any help?


Solution

  • Inf is the problem. Replace

    LIa=@(ss,xg) integral(@(wi)Iaaa(ss,wi),sEg(xg), Inf(1));
    

    with

    LIa=@(ss,xg) integral(@(wi)Iaaa(ss,wi),sEg(xg), 9999);
    

    or whatever higher number that is more appropiate for your application.