# Speeding up double integration by nested Integrate1D

Sandbo

Mon, 06/11/2018 - 08:12 am

Function/c do2DintForWF(xmin,xmax,ymin,ymax,pWave)

Variable xmin,xmax,ymin,ymax

wave/d pWave

Variable/G globalXmin=xmin

Variable/G globalXmax=xmax

Variable/G globalY

variable/d/c integralT

multithread integralT = Integrate1d(outerInt,ymin,ymax,1,0,pWave) // Romberg integration

return integralT

End

Function/c innerInt(pWave1,inX)

wave/d pWave1

Variable inX

//I chose inX to be lambda_Real, globalY to be lambda_Imaginary

NVAR globalY=globalY

//obtaining parameters from pWave

variable m,n

n=pWave1[2]

m=pWave1[3]

variable x,p

x = pWave1[0]

p = pWave1[1]

//Breaking down the equation into parts

variable/d/c integral1

variable/c/d inB=cmplx(1,0), inC=cmplx(1,0), inH, inI, inJ, inK

variable k,l

if (m==0)

inB = cmplx(1,0)

else

multithread inB = (-cmplx(inX,-globalY))^m

endif

if (n==0)

inC = cmplx(1,0)

else

multithread inC = (cmplx(inX,globalY))^n

endif

inH = exp(-0.5*cmplx(inX,globalY)*cmplx(inX,-globalY)) //tested

inI = exp(cmplx(X,P)*cmplx(inX,-globalY)) //tested

inJ = exp(cmplx(X,-P)*cmplx(inX,globalY)) //tested

integral1 = inB*inC*inH*inI/inJ

return integral1

End

Function/c outerInt(pWave2,inY)

wave/d pWave2

Variable inY

NVAR globalY=globalY

globalY=inY

NVAR globalXmin=globalXmin

NVAR globalXmax=globalXmax

variable/d/c integral2

multithread integral2 = Integrate1D(innerInt,globalXmin,globalXmax,1,0,pWave2) // Romberg integration

return integral2

End

Variable xmin,xmax,ymin,ymax

wave/d pWave

Variable/G globalXmin=xmin

Variable/G globalXmax=xmax

Variable/G globalY

variable/d/c integralT

multithread integralT = Integrate1d(outerInt,ymin,ymax,1,0,pWave) // Romberg integration

return integralT

End

Function/c innerInt(pWave1,inX)

wave/d pWave1

Variable inX

//I chose inX to be lambda_Real, globalY to be lambda_Imaginary

NVAR globalY=globalY

//obtaining parameters from pWave

variable m,n

n=pWave1[2]

m=pWave1[3]

variable x,p

x = pWave1[0]

p = pWave1[1]

//Breaking down the equation into parts

variable/d/c integral1

variable/c/d inB=cmplx(1,0), inC=cmplx(1,0), inH, inI, inJ, inK

variable k,l

if (m==0)

inB = cmplx(1,0)

else

multithread inB = (-cmplx(inX,-globalY))^m

endif

if (n==0)

inC = cmplx(1,0)

else

multithread inC = (cmplx(inX,globalY))^n

endif

inH = exp(-0.5*cmplx(inX,globalY)*cmplx(inX,-globalY)) //tested

inI = exp(cmplx(X,P)*cmplx(inX,-globalY)) //tested

inJ = exp(cmplx(X,-P)*cmplx(inX,globalY)) //tested

integral1 = inB*inC*inH*inI/inJ

return integral1

End

Function/c outerInt(pWave2,inY)

wave/d pWave2

Variable inY

NVAR globalY=globalY

globalY=inY

NVAR globalXmin=globalXmin

NVAR globalXmax=globalXmax

variable/d/c integral2

multithread integral2 = Integrate1D(innerInt,globalXmin,globalXmax,1,0,pWave2) // Romberg integration

return integral2

End

June 11, 2018 at 10:13 am - Permalink

June 11, 2018 at 11:17 am - Permalink

June 12, 2018 at 01:01 pm - Permalink

June 12, 2018 at 06:41 pm - Permalink