4
$\begingroup$

I am trying to solve for integral

But it is returning the same. I need this to complete my research. Please help.

The expression used by me in mathematica is:

Integrate[Log2[1+x^2]*(PDF[NormalDistribution[\[Mu], \[Sigma]], x]),{x,-Infinity,Infinity}]
$\endgroup$
5
  • 1
    $\begingroup$ If it is returning the same, then Mathematica does not want to compute it. Try doing it numerically. Also, if there's a next time, can you, please, consider posting your question appropriately? Thanks in advance! $\endgroup$
    – bmf
    Mar 3, 2023 at 4:13
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. Please load Mathematica code (not an image) so that respondents can copy the same to their notebooks and experiment with it. How do you know that a closed-form solution exists for this integral? $\endgroup$
    – Syed
    Mar 3, 2023 at 4:14
  • $\begingroup$ While I have upvoted the answer by @BobHanlon as I find it useful, I am befuddled -to say the least- by the upvote in the question. Would the person who upvoted care to elaborate on the rationale? $\endgroup$
    – bmf
    Mar 3, 2023 at 5:50
  • $\begingroup$ The basic problem that I have to solve is: Find the expected value of log2(1+b*(x^2)) where x is a non-standard normal random variable and b is a constant $\endgroup$ Mar 3, 2023 at 7:29
  • $\begingroup$ If b is close to zero we get: b Sqrt[2 \[Pi]] \[Sigma] (\[Mu]^2 + \[Sigma]^2). See: AsymptoticIntegrate[ E^(-((x - \[Mu])^2/(2 \[Sigma]^2))) Log[1 + b x^2], {x, -Infinity, Infinity}, {b, 0, 1}] $\endgroup$ Mar 3, 2023 at 10:54

3 Answers 3

6
$\begingroup$

It is obvious to consider a numerical solution

int[\[Mu]_?NumericQ, \[Sigma]_?NumericQ] := 
NIntegrate[E^(-((x - \[Mu])^2/(2 \[Sigma]^2))) Log[1 + x^2]/(2 Pi \[Sigma] Log[2]), {x, -Infinity, \[Mu] - \[Sigma], \[Mu], \[Mu] + \[Sigma], Infinity} ] 

Show[Table[ LogLogPlot[int[\[Mu], \[Sigma]], {\[Sigma], .05, 10} ], {\[Mu], Range[0, 2, .1]}] ]

enter image description here

addendum

Thanks to@yarchik's comment!

Knowing DiracDelta[x-\[Mu]]=Limit[E^(-((x - \[Mu])^2/(2 \[Sigma]^2)))/(Sqrt[2Pi]\[Sigma]),\[Sigma]->0] it follows

`int[\[Mu],0]==Log[1+\[Mu]^2]/(Sqrt[2Pi] Log[2])` 
$\endgroup$
2
  • $\begingroup$ I have a bit of doubts that your results at $\sigma\rightarrow0$ are accurate. Your graph shows that for $\mu=2$ and $\sigma=0$ the value is $\approx 3$, but it should be $\log(1+\mu^2)/\log(2)=\log(5)/\log(2)=2.3$. Notice that integral is trivial for $\sigma=0$. $\endgroup$
    – yarchik
    Mar 3, 2023 at 15:34
  • $\begingroup$ @yarchik Thanks for the hint , see my modified answer $\endgroup$ Mar 3, 2023 at 16:06
4
$\begingroup$
Clear["Global`*"]

$Assumptions = μ ∈ Reals && σ > 0;

(int = Inactive[Integrate][
  Log2[1 + x^2] PDF[NormalDistribution[μ, σ], x],
  {x, -∞, ∞}])//TraditionalForm

enter image description here

The integral does not evaluate; however, when μ == 0

int0 = int /. μ -> 0 // Activate

(* -(1/(σ^2 Log[
   2]))(HypergeometricPFQ[{1, 1}, {3/2, 2}, 1/(
    2 σ^2)] + σ^2 (EulerGamma - π Erfi[1/(
        Sqrt[2] σ)] + Log[2] - 2 Log[σ])) *)

Block[{$MaxExtraPrecision = 200},
  LogLogPlot[int0, {σ, 10^-4, 10},
   PlotRange -> All,
   PlotPoints -> 100,
   MaxRecursion -> 5,
   WorkingPrecision -> 120,
   AxesLabel -> (Style[#, 14] & /@
      {HoldForm@σ, HoldForm@int0})]] //
 Quiet

enter image description here

$\endgroup$
1
  • $\begingroup$ The condition over μ and σ is very stringent, and we cannot consider it 0. Is there any other approximation that can be used? Thankyou for the help. $\endgroup$ Mar 3, 2023 at 7:26
1
$\begingroup$

For the benefit of cut-and-pasters, there is an alternate form at the bottom.

$\text{expr}=\text{FullSimplify}[\text{PDF}[\text{NormalDistribution}[0,\sigma ],x]]$

$\frac{e^{-\frac{x^2}{2 \sigma ^2}}}{\sqrt{2 \pi } \sigma }$

$\text{Assuming}\left[\sigma \in \mathbb{R}\land \sigma >0,\int_{-\infty }^{\infty } \text{expr} \log \left(x^2+1\right) \, dx\right]$

$-\frac{\, _2F_2\left(1,1;\frac{3}{2},2;\frac{1}{2 \sigma ^2}\right)}{\sigma ^2}+\pi \text{erfi}\left(\frac{1}{\sqrt{2} \sigma }\right)+2 \log (\sigma )-\gamma -\log (2)$

The purpose of expr is to completely remove $\mu$ whixh is known to be 0 in this case.

The purpose of the Assuming first expresson is to inform Mathematica that $\sigma$ is positive real.

Perhaps, I missed something?

For the cut-and-pasters (afterwards, right click on the cell bracket and Convert to Standard Form):

expr = FullSimplify[PDF[NormalDistribution[0, \[Sigma]], x]]

1/(E^(x^2/(2*\[Sigma]^2))*(Sqrt[2*Pi]*\[Sigma]))

Assuming[Element[\[Sigma], Reals] && \[Sigma] > 0,
  Integrate[expr*Log[x^2 + 1], {x, -Infinity, Infinity}]]

-EulerGamma + Pi*Erfi[1/(Sqrt[2]*\[Sigma])] - 
  HypergeometricPFQ[{1, 1}, {3/2, 2}, 1/(2*\[Sigma]^2)]/
  \[Sigma]^2 - Log[2] + 2*Log[\[Sigma]]

This also works:

$\text{Assuming}\left[\mu =0,\int_{-\infty }^{\infty } \log \left(x^2+1\right) \text{PDF}[\text{NormalDistribution}[\mu ,\sigma ],x] \, dx\right]$

Assuming[\[Mu] == 0, Integrate[PDF[NormalDistribution[\[Mu], \[Sigma]], x]*  
Log[x^2 + 1], {x, -Infinity, Infinity}]]
$\endgroup$
2
  • 1
    $\begingroup$ People here generally like users to post code as copyable Mathematica code instead of just images or TeX, so they can copy-paste it. It makes it convenient for them and more likely someone will check your answer or perhaps help if there's an issue. You may find the meta Q&A, How to copy code from Mathematica so it looks good on this site, helpful $\endgroup$
    – Michael E2
    Mar 5, 2023 at 21:11
  • $\begingroup$ I edited my answer to display both TraditionalForm and RawInputForm expressions. I opine that the former is readable and the latter is copy-and-pastable. Both groups get what they want. $\endgroup$
    – anon
    Mar 7, 2023 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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