Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to write Mathematica code to use Kramers-Kronig on a csv file with 2 columns. Column 1 is h(eV). It goes from 0 to 6, in increments of 0.1. Column 2 is alpha (cm^-1). For some reason, my code just outputs a blank graph. Can someone please tell me what's wrong with it? This is the equation I'm trying to implement (thanks J.M. for doing the latex) $$n_r(\hbar\omega)-1=\frac{c\cdot h}{2\pi^2}P\int_0^\infty \frac{\alpha(\hbar\omega^\prime)}{(\hbar\omega^\prime)^2-(\hbar\omega)^2}d(\hbar\omega^\prime)$$

The reason I posted on this forum is that my code is based on the code from another topic on this site (Update: wrong link, see comments below)

c = 300000000;
data = Import["kk.csv", "CSV"];
column1 = data[[All, 1]];
column2 = data[[All, 2]];
Delete[column1, 1];
Delete[column2, 1];

output := 
  1 + (c PlanckConstant)/(2 pi^2) 
    NIntegrate[column2/(column1^2 - omega^2), {omega, (column1)^2, 0, infinity}, 
      Method -> "PrincipalValue", Exclusions -> Automatic]

Plot[output, {column1, 0, 6}, AxesOrigin -> {0, 0}]
share|improve this question
Since you mention in the comments on your Physics post that you took the code from that site instead of this one, did you take a look at the solution on this site? –  rm -rf Apr 15 '13 at 2:06
Without access to your data, it is hard to experiment with your code. However, I wonder if it wouldn't help to use column1 = data[[2 ;; -1, 1]]; column2 = data[[2 ;; -1, 2]]; in place of the last four lines in the first code group. –  m_goldberg Apr 15 '13 at 2:19
@rm -rf: On the Physics post, my last comment had been that I made a mistake, and actually I was in error, therefore the post should be migrated. That comment seems to have been eaten during migration. Actually, I got the code from mathematica.stackexchange.com/questions/1750/… –  o_0 Apr 15 '13 at 2:26
@m_goldberg: Here's a link to the data: 4shared.com/file/YSfGsekq/kk_online.html I will try your commands. If you don't mind me asking, what do they do? –  o_0 Apr 15 '13 at 2:34
OK, I tried the commands. When I used an upper integration limit of 800 instead of infinity, I got errors like "NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small." I tried infinity, and I'll let you know what happens when it finishes. –  o_0 Apr 15 '13 at 2:41
show 16 more comments

migrated from physics.stackexchange.com Apr 15 '13 at 0:45

This question came from our site for active researchers, academics and students of physics.

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.