0
$\begingroup$

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?

$\endgroup$

closed as off-topic by bbgodfrey, m_goldberg, yohbs, happy fish, J. M. is away May 12 '17 at 6:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – bbgodfrey, m_goldberg, yohbs, happy fish, J. M. is away
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    $\begingroup$ All built-in functions start with a capital letter. Change cos to Cos $\endgroup$ – Bob Hanlon May 12 '17 at 0:15
  • $\begingroup$ j should probably be I, and try PlotRange->All. $\endgroup$ – bill s May 12 '17 at 0:26
1
$\begingroup$
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}.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.