Mathematica: Speed up NIntegrate

  • #1
2
0
I have simplified my problem here, in my actual problem the matrix is much bigger which makes it impossible to find eigenvalues analytically. So, I chose standard BCS problem (2x2 matrix) to demonstrate my problem with Mathematica. But, with even this simple case, it takes forever to integrate. My code is the following:

hamiltonian[k_,mu_,delta_]:={{k^2- mu, delta},{delta,-k^2+ mu}}
eigens[k_,mu_,delta_]:=Eigenvalues[hamiltonian[k, mu, delta]]
fermitotal[beta_,k_,mu_,delta_]:=Block[{ee = eigens[k, mu, delta]},1/(1+Exp[beta ee[[1]]])+1/(1+Exp[beta ee[[2]]])]
nTotal[beta_,mu_,delta_]:=NIntegrate[fermitotal[beta, k, mu, delta] k^2,{k,0,20},Method->{"LocalAdaptive","SymbolicProcessing"->False},AccuracyGoal->4,PrecisionGoal->4,MinRecursion->10,MaxRecursion->300,WorkingPrecision->13]
nTotal[50,1,1/10]//AbsoluteTiming

Any idea how to speed up the calculation?

I have tried, using Compile for the hamiltonian matrix. Specifying the precision for the numbers,

nTotal[N[50,30],N[1,30],N[1/10,30]]//AbsoluteTiming

Did not help. This calculation is supposed to be fast, but I am completely stuck here and I don't know what causes this slowness. Any help would be very much appreciated. Thank you.
 

Answers and Replies

  • #2
DrClaude
Mentor
7,548
3,891
It's the WorkingPrecision->13 that is causing a slowdown. If you remove it, you'll get a solution quite fast.
 

Related Threads on Mathematica: Speed up NIntegrate

Replies
2
Views
3K
Replies
2
Views
2K
Replies
13
Views
10K
Replies
1
Views
3K
Replies
1
Views
3K
Replies
5
Views
6K
Replies
5
Views
2K
Replies
8
Views
2K
Top