Mathematica: Speed up NIntegrate

Click For Summary
SUMMARY

The discussion focuses on optimizing the performance of the NIntegrate function in Mathematica when dealing with a Hamiltonian matrix for a standard BCS problem. The user experiences significant slowdowns due to the WorkingPrecision option set to 13. By removing this option, the integration process becomes substantially faster, allowing for quicker calculations of eigenvalues and fermionic totals. The user also attempted to use Compile for the Hamiltonian matrix and adjusted numerical precision, but these changes did not yield improvements.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of eigenvalue problems in quantum mechanics
  • Knowledge of numerical integration techniques
  • Experience with performance optimization in computational tasks
NEXT STEPS
  • Explore Mathematica's Compile function for performance enhancements
  • Research optimization techniques for NIntegrate in Mathematica
  • Learn about the impact of WorkingPrecision on computational speed
  • Investigate alternative numerical methods for eigenvalue calculations
USEFUL FOR

Researchers, physicists, and computational scientists working with Mathematica who need to optimize numerical integration and eigenvalue calculations in complex systems.

sirenayka
Messages
2
Reaction score
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.
 
Physics news on Phys.org
It's the WorkingPrecision->13 that is causing a slowdown. If you remove it, you'll get a solution quite fast.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K