Evaluating an integral in Mathematica, analytical form

In summary: It looks like just about all the instances of Pi got changed to n! I have no idea what is going on but it seems to be a bug in the forum software.
  • #1
fluidistic
Gold Member
3,923
261
So I've several huge integrals to solve by hands and I would like to check my result with Mathematica. However I don't really know how to do so.
Here is one of the several integrals I must solve:
[tex]\int \frac{1}{2\pi \sigma _x \sigma _y \sqrt{1-\rho ^2 }} \exp \{ \frac{-1}{2(1-\rho ^2)} \left ( \left ( \frac{x-\mu _x}{\sigma _x} \right ) ^2 +\left ( \frac{y-\mu _y}{\sigma _y} \right ) ^2 -\frac{2\rho (x-\mu _x)(y-\mu _y)}{\sigma _x \sigma _y} \right ] \} dx[/tex].
Solving by hands I reached [tex]\frac{1}{\sqrt{2\pi}\sigma _y} \exp \{ \left [ -\frac{1}{2 (1-\rho ^2)} \right ] \left [ \left ( \frac{y-\mu _y }{\sigma _y} \right ) ^2 +\left ( \frac{\mu _x }{\sigma _x} \right ) ^2 + \frac{2 \rho \mu _x y}{\sigma _x \sigma _y} +\frac{\mu _x}{2} +\frac{\rho \sigma _x (y-\mu _y)}{\sigma _y} \right ] \}[/tex].
I want to confirm this result via mathematica, I've tried the following command:
Code:
f[x_,y_]:=1/(2*\[Pi]*sigma_X*sigma_Y*Sqrt[1-rho^2])*E^(-1/(2(1-rho^2))*(((x-mu_X)/sigma_X)^2+((y-mu_Y)/sigma_Y)^2-(2*rho*(x-mu_X)*(y-mu_Y))/(sigma_X*sigma_Y)))
which produced no error.
Then
Code:
\[Integral]f[x,y]\[DifferentialD]x
returned [tex]\int \frac{e^{-\frac{\frac{(x-\text{mu$\_$X}){}^2}{\text{sigma$\_$X}{}^2}+\frac{(y-\text{mu$\_$Y}){}^2}{\text{sigma$\_$Y}{}^2}-\frac{2 \text{rho} (x-\text{mu$\_$X}) (y-\text{mu$\_$Y})}{\text{sigma$\_$X} \text{sigma$\_$Y}}}{2 \left(1-\text{rho}^2\right)}}}{2 \pi \sqrt{1-\text{rho}^2} \text{sigma$\_$X} \text{sigma$\_$Y}} \, dx[/tex]
I've tried "Simplify", "FullSimplify" but the integral is never calculated.
Do you have any idea how to do so? Thanks!
 
Physics news on Phys.org
  • #2
Does this verify your manual calculation?

In[1]:= Integrate[1/(2*π*sigmaX*sigmaY*Sqrt[1-rho^2])*E^(-1/(2(1-rho^2))*(((x-muX)/sigmaX)^2+((y-muY)/sigmaY)^2-(2*rho*(x-muX)*(y-muY))/(sigmaX*sigmaY))),x]

Out[1]= (Sqrt[-1 + rho^2]*Erfi[(muY*rho*sigmaX - muX*sigmaY + sigmaY*x - rho*sigmaX*y)/(Sqrt[2]*Sqrt[-1 + rho^2]*sigmaX*sigmaY)])/ (2*E^((muY - y)^2/(2*sigmaY^2))*Sqrt[2*Pi]*Sqrt[1 - rho^2]*sigmaY)
 
  • #3
Bill Simpson said:
Does this verify your manual calculation?

In[1]:= Integrate[1/(2*π*sigmaX*sigmaY*Sqrt[1-rho^2])*E^(-1/(2(1-rho^2))*(((x-muX)/sigmaX)^2+((y-muY)/sigmaY)^2-(2*rho*(x-muX)*(y-muY))/(sigmaX*sigmaY))),x]

Out[1]= (Sqrt[-1 + rho^2]*Erfi[(muY*rho*sigmaX - muX*sigmaY + sigmaY*x - rho*sigmaX*y)/(Sqrt[2]*Sqrt[-1 + rho^2]*sigmaX*sigmaY)])/ (2*E^((muY - y)^2/(2*sigmaY^2))*Sqrt[2*Pi]*Sqrt[1 - rho^2]*sigmaY)
Hmm nice thank you, that's a way to integrate that works. I forgot to mention I did the integral from [itex]-\infty[/itex] to [itex]\infty[/itex].
So I tried
Code:
Integrate[
 1/(2*\[Pi]*sigmaX*sigmaY*Sqrt[1 - rho^2])*
  E^(-1/(2 (1 - rho^2))*(((x - muX)/sigmaX)^2 + ((y - muY)/
          sigmaY)^2 - (2*rho*(x - muX)*(y - muY))/(sigmaX*
          sigmaY))), {x, -\[Infinity], \[Infinity]}]
which, after a long time, returned
Code:
If[Re[1/((-1 + rho^2) sigmaX^2)] < 0 && 
   Re[(-1 + rho^2) sigmaX^2] <= 0, 
  E^(-((muY - y)^2/(2 sigmaY^2))) Sqrt[2 \[Pi]]
    Sqrt[-(-1 + rho^2) sigmaX^2], 
  Integrate[
   E^(-(((muX - x)^2/sigmaX^2 - (2 rho (muX - x) (muY - y))/(
     sigmaX sigmaY) + (muY - y)^2/sigmaY^2)/(
    2 (1 - rho^2)))), {x, -\[Infinity], \[Infinity]}, 
   Assumptions -> 
    Re[1/((-1 + rho^2) sigmaX^2)] >= 0 || 
     Re[sigmaX^2 - rho^2 sigmaX^2] < 0]]/(2 \[Pi] Sqrt[1 - rho^2]
    sigmaX sigmaY)
. In all cases I don't think it confirms my result by hands so I guess I have made some errors.
 
  • #4
If I make some hopefully reasonable assumptions, that you should verify, I get

In[1]:= Assuming[Element[rho,Reals]&& Element[sigmaX,Reals]&& -1<rho<1&&sigmaX≠0,
Integrate[1/(2*Pi*sigmaX*sigmaY*Sqrt[1-rho^2])*E^(-1/(2 (1-rho^2))*(((x-muX)/sigmaX)^2+((y-muY)/sigmaY)^2-(2*rho*(x-muX)*(y-muY))/(sigmaX*sigmaY))),{x,-Infinity,Infinity}]]

Out[1]= Abs[sigmaX]/(E^((muY - y)^2/(2*sigmaY^2))*Sqrt[2*Pi]*sigmaX*sigmaY)

Warning: If you look carefully at my previous post you will notice there is "Integrate[1/(2*π" and you might wonder where in the world I came up with "n"?? That is a scrape-n-paste error where the desktop published Greek Pi got mangled into an n in the process of going from the forum screen to the clipboard to Mathematica to the clipboard to the forum screen. This leads me to my next sentence.

One bit of general advice for using Mathematica, the more of the "I absolutely must desktop publish my every keystroke" Koolaid(tm) you have drunk, just like befor your first post, the more difficulties you will tend to have with Mathematica. In the beginning Mathematica was a calculation engine. Only much later did they try to glue on a veneer of desktop publishing and that almost never works. Again and again here we see posts "Why doesn't this work?" and the answer is often that they are confusing making the expression look like a textbook with making the expression something they can get a correct answer from. There are long lists of things that look like a textbook but don't work to get answers.

My apologies for not catching that. Hopefully there are no more errors in this. Damn. There was another of exactly the same error in this post which I have now manually fixed.
 
Last edited:
  • #5


I understand the importance of verifying results and using tools like Mathematica to aid in solving complex integrals. In order to evaluate this integral in Mathematica, you can use the "Integrate" function with the appropriate limits of integration. It is important to note that the function you have defined, f[x,y], is not a valid mathematical expression as it contains undefined variables such as sigma_X, sigma_Y, mu_X, mu_Y, and rho. You will need to define these variables with numerical values before evaluating the integral. Additionally, you may need to specify assumptions for the variables in order for Mathematica to simplify the integral. For example, if you know that sigma_X and sigma_Y are positive, you can use the assumption "Assumptions -> {sigma_X > 0, sigma_Y > 0}" in the "Integrate" function. I would also suggest consulting the Mathematica documentation or seeking assistance from a Mathematica expert for further guidance on how to evaluate this integral.
 

1. How do I evaluate an integral in Mathematica in analytical form?

To evaluate an integral in Mathematica in analytical form, you can use the Integrate command. Simply type Integrate[f[x], x] where f[x] is the function you want to integrate. If you have specific limits of integration, you can add them as arguments, such as Integrate[f[x], {x, a, b}] where a and b are the lower and upper limits respectively.

2. Can Mathematica solve all types of integrals?

No, Mathematica may not be able to solve all types of integrals. Some integrals may be too complex for Mathematica to handle, or require specialized techniques. If Mathematica is unable to evaluate an integral, it will return the integral in its original form.

3. How do I check if the result of an integral in Mathematica is correct?

To check the result of an integral in Mathematica, you can use the NIntegrate command. This will give you a numerical approximation of the integral, which you can compare to the result of the Integrate command. If the values are close, then it is likely that the result of the integral is correct. You can also use other methods, such as hand calculation or checking with a different software.

4. Can I integrate a multivariable function in Mathematica?

Yes, you can integrate multivariable functions in Mathematica. You can use the Integrate command with multiple variables, such as Integrate[f[x,y], {x, a, b}, {y, c, d}] where a, b, c, and d are the limits of integration for each variable.

5. How do I plot the result of an integral in Mathematica?

To plot the result of an integral in Mathematica, you can use the Plot command. Simply type Plot[f[x], {x, a, b}] where f[x] is the result of the integral and a and b are the limits of integration. You can also add options to customize the plot, such as changing the range or adding labels.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
228
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Special and General Relativity
Replies
10
Views
718
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
14
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • Special and General Relativity
Replies
15
Views
1K
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top