The following function can be plotted without any issues, say with ContourPlot, but NIntegrate fails because it tries to diagonalise the matrix with generic values x,y, instead of using numerical values.
del1 = {1, 0}; del2 = {1, Sqrt[3]}/2; del3 = del2 - del1;
matrix[k_] := {{1, Cos[k.del3/2],Cos[k.del1/2]},
{Cos[k.del3/2],1,Cos[k.del2/2]}, {Cos[k.del1/2], Cos[k.del2/2], 1}};
fun[k_] := Block[{d = 0, abc, esys, UU},
esys = Eigensystem[N[matrix[k]]];
UU = Transpose[Normalize /@ esys[[2]]];
abc = ConjugateTranspose[UU].DiagonalMatrix[{.1, 5, 0}].UU;
abc[[1, 1]]]
NIntegrate[fun[{x, y}], {x, .3, .4}, {y, .3, .4}]
I have tried putting Evaluate and ?NumericQ in a few places, to no avail.
How can I perform the desired integral?
ClearAll[fun];before definingfunto erase all previous defs. Thenfun[k_?(VectorQ[#, NumericQ] &)] := ...seems to work for me. – Michael E2 Jan 15 '18 at 15:53NIntegrateneeds this butContourPlotdoesn't? – Daniel Jan 15 '18 at 16:02solver[f[x], domain], where solver might beNIntegrate,ContourPlot, etc. Thesolverholds the codef(it does not evaluate immediately). Now, sometimes you want the solver to evaluatefand analyze the result (e.g., for method selection, to handle singularities); sometimes not. The other choice is whether the solver uses the evaluated codefor uses the original code for numeric evaluation. I think this choice is the difference, but I can't explain whyContourPlotchooses a different way fromNIntegrate. – Michael E2 Jan 15 '18 at 16:49