Calculating Integral in Mathematica

In summary, when integrating the MultinormalDistribution, you need to use the function f(x) = NIntegrate[PDF[MultinormalDistribution[{5, 6}, {{1, 1}, {1, 2}}], {x1,x2}], {x1,x,c}, {x2,x,c}] to numerically evaluate the expression. For any particular value of x and c (c is a known constant), you can numerically evaluate the expression, however, you need to evaluate the expression for all possible values of x, where x is a countinous number. You could use a table to do this.
  • #1
jimmy1
61
0
I have a function f(x) which is defined as

[tex]f(x) = \int_{x}^{c} \int_{x}^{c} f(x_1,x_2) dx_1 dx_2 [/tex]

where c is a known constant and f(x1,x2) is a multivariate Gaussian. Unfortunetaly there is no closed form solution for f(x).
My problem is I want to numerically calculate

[tex] \int_{c_1}^{c} f(x) dx [/tex]

where again c_1, and c are known constants.
How do I numerically evaluate such an integral in Mathematica? I get errors every time saying "x is not a valid limit of integration".
Any ideas, how I would input the above into Mathematica to get a numerical solution?
 
Physics news on Phys.org
  • #2
NIntegrate[ f[x], {x, c1, c} ]
where c1 and c are numerical values or constants (like Pi, 2*E, 33.401 etc).
 
  • #3
Unfortunately f(x) has no closed form solution (so the expression for f(x) still has the symbols x1, x2) and thus evaluating "NIntegrate[ f[x], {x, c1, c} ]" just gives the error the "Integrand ... is not numerical at...".

I've also tried "NIntegrate[ f[x], {x1, x, c}, {x2, x, c}, {x, c1, c} ]", but this gives the error "x1 = x is not a valid limit of integration. "

I'm sure there's some way to do it, but just can't figure it out?
 
  • #4
Can you post some code, in particular be a little more specific about f(x1, x2) ?
 
  • #5
Basically, f(x1,x2) is a http://en.wikipedia.org/wiki/Multivariate_normal_distribution" . An example in Mathematica code would be:

f(x) = "Integrate[PDF[MultinormalDistribution[{5,6}, {{1,1}, {1,2}}], {x1,x2}], {x1,x,c},{x2,x,c}]"

For any particular value of x and c (c is a known constant) I can numerically evaluate the above expression, however, I want to evaluate the above expression for all possible values of x, where x is a countinous number, and hence I need to integrate the above expression for all possible values of x (say, x ranges from 0-10 in the above example)
 
Last edited by a moderator:
  • #6
You are right that
Code:
NIntegrate[ f[x], {x1, x, c}, {x2, x, c}, {x, c1, c} ]
doesn't work, but I think that
Code:
NIntegrate[ f[x], {x, c1, c}, {x1, x, c}, {x2, x, c} ]
does. At least it gives an answer... apparently the integration is in a different order than you'd expect.

E.g.
Code:
NIntegrate[PDF[MultinormalDistribution[{5, 6}, {{1, 1}, {1, 2}}], {x1, x2}], {x, 5, 10}, {x1, x, 10}, {x2, x, 10}]

0.365427
 
  • #7
jimmy1 said:
Basically, f(x1,x2) is a http://en.wikipedia.org/wiki/Multivariate_normal_distribution" . An example in Mathematica code would be:

f(x) = "Integrate[PDF[MultinormalDistribution[{5,6}, {{1,1}, {1,2}}], {x1,x2}], {x1,x,c},{x2,x,c}]"

For any particular value of x and c (c is a known constant) I can numerically evaluate the above expression, however, I want to evaluate the above expression for all possible values of x, where x is a countinous number, and hence I need to integrate the above expression for all possible values of x (say, x ranges from 0-10 in the above example)

Of course, make sure you load the package with the MultinormalDistribution:
Code:
Needs["MultivariateStatistics`"]

Then turn your code into a function:

Code:
f[x_, c_] :=  NIntegrate[PDF[MultinormalDistribution[{5, 6}, {{1, 1}, {1, 2}}], {x1, 
    x2}], {x1, x, c}, {x2, x, c}]

Now you say that you want to evaluate this repeatedly for different values of x, you could use a table:

Code:
Table[f[x,20],{x,1,10,0.1}]
 
Last edited by a moderator:
  • #8
Cool, thanks guys! I've used your suggestions and I think I've got it now, just need to test the result a bit more. Anyway, cheers for the help!
 

Related to Calculating Integral in Mathematica

What is an integral in Mathematica?

An integral in Mathematica is a mathematical concept that represents the area under a curve in a graph. It is used to find the total value or quantity of a function, and is an important tool in many areas of science and engineering.

How do I calculate an integral in Mathematica?

To calculate an integral in Mathematica, you can use the built-in function "Integrate". Simply input the function or expression you want to integrate, and specify the variable of integration. Mathematica will then provide the result of the integral in both symbolic and numerical form.

Can Mathematica handle complex integrals?

Yes, Mathematica has the ability to calculate complex integrals. It has a powerful symbolic engine that can handle a wide range of mathematical functions and expressions, making it suitable for even the most complex integrals.

Are there any limitations to calculating integrals in Mathematica?

While Mathematica is a powerful tool for calculating integrals, it is not able to solve every integral. Some integrals may require specialized techniques or may not have a closed-form solution, in which case Mathematica will provide the integral in its symbolic form.

Can Mathematica show the steps involved in calculating an integral?

Yes, Mathematica has a feature called "Step-by-step solution" that allows you to see the individual steps involved in calculating an integral. This can be helpful for understanding the process and checking for any errors in your input.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
251
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Back
Top