Can You Integrate a Function of Two Variables in Mathematica?

In summary: I then tried:In[11] = NIntegrate[Exp[-x^2] y, {x, 0, 25 }]I get the error:NIntegrate::inumr: The integrand E^-x^2 y has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],0.}}. >>In[12]:= NIntegrate[Exp[-x^2] y, {x, 0, 25 }]NIntegrate::inumr: The integrand E^-x^2 y has evaluated to non-numerical values for all sampling
  • #1
gaby287
14
0
I have a function of two variables F[x_,y_] and I Would like to integrate over one variable only and get a function G[x] for example and work with it.
I want something like:
G[x_]:=NIntegrate[F[x,y],{y,0,\infty}]

But it doesn't work.
 
Physics news on Phys.org
  • #2
It probably depends on what your F is. NIntegrate is also going to demand that all variables have been assigned constant numeric values.

In[1]:= f[x_, y_] := 3 x^2/(y + 2)^2;
g[x_] := Integrate[f[x, y], {y, 0, Infinity}];
g[x]

Out[3]= (3 x^2)/2
 
  • #3
gaby287 said:
But it doesn't work.
Can you be more specific about what doesn't work. It seems to work for me.

f[x_, y_] := 3 x^2/(y + 2)^2;
G[x_] := NIntegrate[f[x, y], {y, 0, \[Infinity]}];
G[1]

This gives 1.5 as expected.
 
  • #4
Well, my function is something like:
F[x_, y_] := Sum[(Tablev[[ i]] - Sqrt[(4 Pi*(43.040600502)*x* y^(3)/(Tablepc[[i ]]))*(-Tablepc[[i ]] / (Tablepc[[i ]] +y) + Log[((Tablepc[[ i ]] +y)/y)])])^2/(Tableerr[[
i]])^2, {i, 1, 61}]

And I need minimize a function:
G[y_] :=NIntegrate[F[x, y], {x, 0, \[Infinity]}]

NMinimize[{G[y], y>0},y]

Out:
NIntegrate::inumr: The integrand 1.36156 (3.9 -63.1823 Sqrt[Power[<<2>>] x Plus[<<2>>]])^2+0.260308 (9.47 -44.6766 Sqrt[Power[<<2>>] x Plus[<<2>>]])^2+0.179091 (13.62 -36.4783 Sqrt[Power[<<2>>] x Plus[<<2>>]])^2+0.21553 (16.31 -31.5911 Sqrt[Power[<<2>>] x Plus[<<2>>]])^2+<<44>>+0.16391 (46.36 -9.02604 Sqrt[Power[<<2>>] x Plus[<<2>>]])^2+0.158601 (46.89 -8.93532 Sqrt[Power[<<2>>] x Plus[<<2>>]])^2+<<11>>
has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],0.}}. >>

General stop: Further output of NIntegrate::inumr will be suppressed during this calculation. >>

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. >>

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {8.16907*10^224}. NIntegrate obtained 2.916496176313921`15.954589770191005*^55895 and 2.916496176313921`15.954589770191005*^55895 for the integral and error estimates. >>
 
  • #5
Tablev, Tablepc, Tableerr are tables of numbers.
 
  • #6
It looks like the problem is F[x,y], not G[y] per se. Have you plotted F[x,y] for points in your region of interest? Is it well-behaved throughout? Does it oscillate or go to zero in some limit? Is it numerically stable in that region?

Note, if you integrate to infinity then it must be well-behaved for extremely large numbers. In particular, your F[x,y] seems to be losing numerical accuracy in the x > 10^224 range.
 
  • #7
I have my graphic and i know which is the region of interest but when i put this interest region i have the next problem:
G[y_] :=NIntegrate[F[x, y], {x, 0.05, 25 }]
Out:
NIntegrate::inumr: The integrand 43.39404528 E^(1/2 (<<99>>+<<12>>)) has evaluated to non-numerical values for all sampling points in the region with boundaries {{0.05000000000,0.05085937500}}. >>

I've tried changing the interval of integration but doing that i only change the interval {{0.05000000000,0.05085937500}}.
 
  • #8
Look at the complete output for F[x, y] and make sure that it is all numerical (except for x and y).
 
  • #9
DrClaude said:
Look at the complete output for F[x, y] and make sure that it is all numerical (except for x and y).
I Checked and I'm sure that it's all numerical.
 
  • #10
I've looked in more details, and what you are trying to do is impossible with NIntegrate, which can only work with something completely numerical, and for some reason when you ask for
Code:
NMinimize[{G[y], y>0},y]
you would expect that it passes a numerical value y to G, which then can numerically integrate F and return the result, but it appears that this is not what Mathematica does. That said, I found that, at leat for a simple case, the correct result is obtained anyway:
Code:
In[10] = NMinimize[{NIntegrate[Exp[-x^2] y, {x, 0, \[Infinity]}], y > 0}, y]

NIntegrate::inumr: The integrand E^-x^2 y has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],0.}}. >>
NIntegrate::inumr: The integrand E^-x^2 y has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],0.}}. >>
NIntegrate::inumr: The integrand E^-x^2 y has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],0.}}. >>
General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation. >>

Out[10] = {0., {y -> 0.}}
 

1. How can Mathematica be used to integrate mathematical functions?

Mathematica has a built-in function called "Integrate" that can be used to perform definite and indefinite integrals. Simply input the function to be integrated and the variable of integration, and Mathematica will provide the result.

2. Can Mathematica handle complex integrals?

Yes, Mathematica has the capability to handle complex integrals. It has built-in algorithms that can handle a wide range of functions, including those with complex numbers.

3. Are there any limitations to Mathematica's ability to integrate?

While Mathematica has advanced capabilities for integration, there are certain functions that it may not be able to integrate. In such cases, it will return the input expression as the result.

4. Can Mathematica be used to solve differential equations by integration?

Yes, Mathematica has a function called "DSolve" that can be used to solve differential equations by integration. It can handle a variety of differential equations, including those with initial or boundary conditions.

5. Is there a way to check the accuracy of the integration performed by Mathematica?

Yes, Mathematica has a function called "NIntegrate" that can be used to numerically evaluate integrals. This can be used to check the accuracy of the integration performed by Mathematica's "Integrate" function.

Similar threads

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