Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to calculate the change of the refractive index from the change of the absorption coefficient using the Kramers-Kronig relations, in Mathematica.

c = 300000000;

daF[l_] = 500 * 0.28 Exp[-((l - 500)/90)^2];

dnFpoints = Table[
        c/Pi NIntegrate[
            daF[li] / ((2 Pi c 10^9 /li)^2 - (2 Pi c 10^9 / ln)^2),
            {li, 800, 200},
            Method -> {"PrincipalValue"},
            Exclusions -> ((2 Pi c 10^9 /li)^2 - (2 Pi c 10^9 / ln)^2) == 0
    {ln, 300, 600}

Unfortunately, Mathematica displays an error that it does not converge to prescribed accuracy and the output is junk (I would expect a smooth curve with a negative minimum first and then a positive maximum). I am using version 8, if it matters. Any ideas?

share|improve this question
up vote 13 down vote accepted

I think you intended to use {li, 200, 800} instead of {li, 800, 200}.

If you do so, then you could visualize the result :


enter image description here

Moreover I would rather define daF in the following form :

daF[l_]:= 500 * 0.28 Exp[-((l - 500)/90)^2]
c = 3 10^8;


Instead of using Table of dnFpoints I add an alternative method for calculation of dnF function.

dnF[ln_] := 
  1/( 4c Pi^3 10^18 ) NIntegrate[ daF[li] / ( 1/li^2 - 1/ln^2 ), 
                                  { li, -\[Infinity],  ln, \[Infinity] }, 
                                  Method ->  "PrincipalValue", 
                                  Exclusions ->  Automatic  
                                ] // Quiet

In general one should choose appropriate options for NIntegrate like PrecisionGoal and MaxRecursion however in this case it is quite sufficient to use Quiet for evaluating of dnF function without outputting any messages generated.

Now we can plot dnF function increasing appropriately a range of the dependent variable, e.g. :

Plot[dnF[ln], {ln, 30, 900}, AxesOrigin -> {0, 0}, PlotPoints -> 200]

enter image description here

share|improve this answer
When you change ln for li what is ln then? I couldn't find a definition for it in the above code and get a non-numerical values error. – Matariki Feb 14 '12 at 18:43
@Matariki mcandril integrates numerically daF[li]/(f1(li)-f2(ln)) over li from 200 to 800, and then collects results in Table[{ln, integral(ln)}, {ln, 300, 600}]. Therefore we can't change variables li and ln. – Artes Feb 14 '12 at 18:57
Doh, missed that! Thanks for clarifying. – Matariki Feb 14 '12 at 19:08
...if the integral he needs actually does go from 800 to 200, then it's a simple matter of changing signs, since $\int_a^b=-\int_b^a$. – J. M. Feb 14 '12 at 23:21
Wow, thanks. I indeed meant 800-200, this comes from the substitution $\omega$->$\lambda$. Of course I knew J. M. comment, but I thought Mathematica does, too ... Is that a bug, or is there more behind the problem? – mcandril Feb 15 '12 at 7:58

protected by R. M. Feb 25 '12 at 10:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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