# How to Double integrate a function Separately?

I have function f[x,y] where i need to integrate f[x,y] with x first and then later i need to integrate that f[x,y]dx with y.
I will be getting f[x,y]dx from another notebook after using Get["ffile"] function.
Is there a way to Integrate this function separately. I tried Direct double integration it worked properly.I'm able to get plot but unable to integrate separately .

ClearAll[Evaluate[StringJoin[
Context[], "*"]]]
Needs["UtilitiesCleanSlate"];
CleanSlate[];
ClearInOut[];

f[x_, (y_)?NumericQ] :=
Sin[x*y]*Cos[x + y];

g[y_] := NIntegrate[f[x, y],
{x, 0, Pi}]

avggy = NIntegrate[g[y], {y, 0, Pi}]

Plot[g[y], {y, 0, 2*Pi}]


I'm getting this error
"The integrand f[x,y] has evaluated to non-numerical values for all \ sampling points in the region with boundaries".
Is there a way to Integrate this? any suggests are highly appreciated.
Thanking you.

I'm Sorry for editing after getting response to above doubt.

This is what i'm trying to do

f123[(y_)?NumericQ,
(z_)?NumericQ] :=
NIntegrate[
Sin[x*y]*Cos[x + y] + z,
{x, 0, Pi}]

Save["ffucntion",
testFfunction]


I will call this function from another notebook

ClearAll[Evaluate[StringJoin[
Context[], "*"]]]
Needs[
"UtilitiesCleanSlate"];
CleanSlate[];
ClearInOut[];

Get["ffucntion"];
g[(y_)?NumericQ] :=
f123[y, y^2]

avgg = NIntegrate[g[y],
{y, 0, 2*Pi}]


I'm getting this error ."The integrand g[y] has evaluated to non-numerical values for all \ sampling points in the region with boundaries"

EDIT 1:

Looking at the code from your edit, I think the problem is that you are saving the wrong function (testFfunction instead of f123). Try:

Save["ffucntion", f123]


in your first notebook. And then run

Get["ffucntion"];
g[(y_)?NumericQ] := f123[y, y^2]

avgg = NIntegrate[g[y], {y, 0, 2*Pi}]


in your other notebook. It seems to work for me without any errors and yields 257.566.

Original:

Your ?NumericQ is in the wrong spot.

f[x_, y_] := Sin[x*y]*Cos[x + y];

g[y_?NumericQ] := NIntegrate[f[x, y], {x, 0, Pi}]

avggy = NIntegrate[g[y], {y, 0, Pi}]

Plot[g[y], {y, 0, 2*Pi}]


We want to prevent NIntegrate from doing any symbolic manipulation, so we check to make sure that g[y] only evaluates once y has taken on a numeric value.

• Hi, thanks for the solution. I'm extremely sorry for asking again. I edited my code . Would you help me out. Thanking you. – Gummala Navneeth Dec 3 '19 at 7:53
• @GummalaNavneeth I've edited my answer. Hopefully this will work for you. – MassDefect Dec 3 '19 at 19:59
• Thanks a lot for your help – Gummala Navneeth Dec 4 '19 at 3:16