# Mathematica : Numerically Integrate function with undefined variables?

• Mathematica
• Hepth
In summary, the conversation is about a large function that needs to be integrated over two variables, x and y, both ranging from 0 to 1. The function is expressed as a sum of terms, each of which can be separated into a function of x and y. The G functions are complicated and take a long time to integrate algebraically, but can be quickly numerically integrated. The question is whether there is a way to numerically integrate the entire equation without expanding it and dividing out the functions A[q] and B[q] for each term. The suggested solution is to substitute temporary variables Aq and Bq for A[q] and B[q], use CoefficientList to extract the parts of the equation that are multiplied by
Hepth
Gold Member
I have a LARGE function that I must integrate over 2 variables, {x,y} both from 0 to 1.

The Function looks like :

F[x_,y_] = A[q] G[x,y] + B[q] G2[x,y] + (...)

Where (...) MAY be 100's of terms long, if not thousands. But the fact is each term is separable, in SOME way to a function of x and y (and no other units or unknown variables).

Each G function is quite complicated as well, and so far takes over 3 minutes each to integrate algebraically, though can be numerically integrated in under a second or two. They're all well behaved in the integration region.

Is there a way, other than expand F, and dividing out A[q] etc for each, doing the NIntegrate, then multiplying it again, to numerically integrate this equation so it ends up being:

result = (0.14325) A[q] + (-4.5602134) B[q] + (...)

Can I tell NIntegrate to integrate around variables?

I know something like NIntegrate[ a x^2,{x,0,1}] will throw an error due to an undefined "a" inserted.

## 1. How do I numerically integrate a function in Mathematica with undefined variables?

To numerically integrate a function with undefined variables in Mathematica, you need to first assign values to those variables using the "Set" function. For example, if your function is f(x,y) and you want to integrate from x=0 to x=1 and y=2, you would use the command "Set[x,0]; Set[y,2]; NIntegrate[f[x,y],{x,0,1}]. This will evaluate the integral numerically with the given values for x and y.

## 2. Can I use functions with undefined variables in Mathematica's numerical integration?

Yes, you can use functions with undefined variables in Mathematica's numerical integration. However, you will need to assign values to those variables before integrating, as mentioned in the previous answer. If you do not assign values, Mathematica will not be able to evaluate the integral.

## 3. How accurate is Mathematica's numerical integration with undefined variables?

The accuracy of Mathematica's numerical integration with undefined variables will depend on the accuracy of the assigned values for those variables. If the values are precise, the integration will be accurate. However, if the values are only approximate, the integration may also be approximate.

## 4. Can I use symbolic variables in Mathematica's numerical integration?

Yes, you can use symbolic variables in Mathematica's numerical integration. However, you will need to use the "Set" function to assign values to those variables before integrating, as mentioned in the first answer. You can also use the "Assuming" function to specify assumptions about the symbolic variables.

## 5. How can I check the accuracy of the numerical integration in Mathematica?

To check the accuracy of the numerical integration in Mathematica, you can use the "AccuracyGoal" and "PrecisionGoal" options in the "NIntegrate" function. These options allow you to specify the desired level of accuracy for the integration and can be adjusted to achieve a more accurate result.

Replies
13
Views
2K
Replies
9
Views
3K
Replies
12
Views
1K
Replies
1
Views
540
Replies
1
Views
2K
Replies
3
Views
3K
Replies
1
Views
1K
Replies
2
Views
2K
Replies
9
Views
3K
Replies
4
Views
3K