Evaluation order of NIntegrate

F[y_?NumericQ] := Eigenvectors@( {
{1, y},
{y, 1}
} );
G[x_?NumericQ] := NIntegrate[F[y][[1]].F[y][[1]], {y, 0, 2}];
G[4]


The program simply doesn't work in this way. Changing y_?NumericQ to y_ doesn't help since then the Eigenvectors would be evaluated in symbolic method (which I don't want). How can it be solved?

• Your function for G[x] does not have x on the right hand side. I doubt this was intended. Commented Oct 17, 2016 at 4:35
• The point is the following: Sometimes, F is a complicated function that ends with a list of, say, 3 numbers (and that ?NumericQ is a must for some function (say function involving ordering)). Then G evaluate the integral of that function. But the mathematica simply doesn't work for ?NumericQ trick when your function ends with several numbers, so you must do it separately and ends with multiple evaluation times :P Commented Oct 25, 2016 at 4:44

F[y_?NumericQ] := Eigenvectors@({{1, y}, {y, 1}});
H[y_?NumericQ] := F[y][[1]].F[y][[1]];
G[x_?NumericQ] := NIntegrate[H[y], {y, 0, 2}];
G[4]
(*2*)


The problem with your previous code was that NIntegrate tried to evaluate its argument symbolically first. So it tried evaluating:

F[y][[1]].F[y][[1]]
(*y.y*)


This returns y.y because F[y] had no definitions when y is a symbol. So F[y][[1]] evaluates to y (which is the first part of the expression F[y])

(By the way, you should avoid starting your function names with capital letters)

• Just a side note, now ?NumericQ is no longer needed in F :) Commented Oct 17, 2016 at 6:49
• That function isn't really needed :) H[y_?NumericQ] := #.# &@Eigenvectors[{{1, y}, {y, 1}}][[1]] Commented Oct 17, 2016 at 17:08
• ic, thanks for the answer~ Commented Oct 25, 2016 at 9:49