# Errors from NIntegrate when integrating Green's function [closed]

I have the code used to calculate density of states using integral of the Green's function. Unfortunately, the code does not work. I am supposed to get a plot of a gausian like curve with a dimple in the middle:

integral[j_, s_, nn_, oo_] :=
Module[{},
ListPlot[
Table[
{e, -1/Pi*
Im[NIntegrate[1/(e + I*s - 2*j*cos[kl]), {kl, -Pi, Pi}]]}, {e, -20, 20, nn}],
Joined -> True,
AxesLabel -> {"E", "DOS"},
PlotRange -> oo]]

integral[1, 1, 30, 30]


I am getting the following error messages:

NIntegrate::inumr: The integrand 1/((-20.+0.02 I)-2 cos[kl]) has evaluated to non-numerical values for all sampling points in the region with boundaries {{-3.14159,3.14159}}. >>
NIntegrate::inumr: The integrand 1/((20. +0.02 I)-2 cos[kl]) has evaluated to non-numerical values for all sampling points in the region with boundaries {{-3.14159,3.14159}}. >>
NIntegrate::inumr: The integrand 1/((0. +0.02 I)+e-2 cos[kl]) has evaluated to non-numerical values for all sampling points in the region with boundaries {{-3.14159,3.14159}}. >>
General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation. >> Flatten::normal:

Any suggestions?

• All built-in functions start with a capital letter. Change cos to Cos – Bob Hanlon May 12 '17 at 0:15
• j should probably be I, and try PlotRange->All. – bill s May 12 '17 at 0:26

## 1 Answer

myintegral[j_, s_, nn_, oo_List] :=
Module[{},
ListPlot[Table[{e, -π Im[NIntegrate[
1/(e + I s - 2 I Cos[kl]), {kl, -π, π}]]},
{e, -20, 20, nn}],
Joined -> True,
AxesLabel -> {"E", "DOS"},
PlotRange -> oo]]

myintegral[2, 4, 1, {0, 4}]


works fine. Note that PlotRange takes a List {ymin, ymax}.