The integrand includes ku, Sin[x], and Tuu. ku is constant, x is one of the variables, and Tuu is functions of x. I have tested that when x and y are given, Tuu can be carried out. But why NIntegrate[ku*Sin[x]Tuu, {x, 0, Pi/2}, {y, 0, Pi/4}] give a result of itself (i.e. NIntegrate[kuSin[x]*Tuu, {x, 0, Pi/2}, {y, 0, Pi/4}])? How to solve the problem? Many thanks!
According to the suggestion of Michael E2, I have rewrite the codes. But there still appear a lot of errors.
The codes are as following:
Clear["`*"]
m = 4;
vh = 4;
mu = 11;
delta = 8;
HBAR = SetPrecision[1.05457266*10^(-34), 50];
ME = SetPrecision[9.1093897*10^(-31), 50];
ELEC = SetPrecision[1.60217733*10^(-19), 50];
Kh = SetPrecision[0.211, 50];
vKh[1] = {0, 0, 0};
vKh[2] = {Kh, 0, 0};
kc = Sqrt[2*ME*ELEC/HBAR^2]*10^(-11);
ku = kc*Sqrt[mu + delta];
kd = kc*Sqrt[mu - delta];
a3 = {Pi/Kh, Pi/Kh, Sqrt[2]*Pi/Kh};
k[x_, y_] := {-ku*Sin[x]*Cos[y], -ku*Sin[x]*Sin[y], kz};
f11[x_, y_] := Total[(k[x, y] + vKh[1])^2] - ku^2;
f22[x_, y_] := Total[(k[x, y] + vKh[2])^2] - ku^2;
f12[x_, y_] :=
kc^2*vh*Total[
Table[Exp[I*n*Total[(vKh[2] - vKh[1])*a3]], {n, 0, m}]];
f21[x_, y_] :=
kc^2*vh*Total[
Table[Exp[I*n*Total[(vKh[1] - vKh[2])*a3]], {n, 0, m}]];
t[x_, y_] := {{f11[x, y], f12[x, y]}, {f21[x, y], f22[x, y]}};
slu[x_, y_] :=
Select[kz /. NSolve[Det[t[x, y]] == 0, kz],
Re[#] >= 0 && Im[#] >= 0 &];
td1[x_, y_] := t[x, y] /. kz -> slu[x, y][[1]];
td2[x_, y_] := t[x, y] /. kz -> slu[x, y][[2]]
nu1[x_, y_] := Flatten[NullSpace[td1[x, y]]];
nu2[x_, y_] := Flatten[NullSpace[td2[x, y]]];
pi[x_, y_] := Transpose[{nu1[x, y], nu2[x, y]}];
pei := Table[If[q == 1, 1, 0], {q, 2}];
Tuu[x_, y_] :=
Im[Conjugate[(LinearSolve[pi[x, y], pei][[1]]*nu1[x, y][[1]]*
Exp[I*slu[x, y][[1]]*d] +
LinearSolve[pi[x, y], pei][[2]]*nu2[x, y][[1]]*
Exp[I*slu[x, y][[2]]*d])]*(Dt[
LinearSolve[pi[x, y], pei][[1]]*nu1[x, y][[1]]*
Exp[I*slu[x, y][[1]]*d] +
LinearSolve[pi[x, y], pei][[2]]*nu2[x, y][[1]]*
Exp[I*slu[x, y][[2]]*d], d]) +
Conjugate[(LinearSolve[pi[x, y], pei][[1]]*nu1[x, y][[2]]*
Exp[I*slu[x, y][[1]]*d] +
LinearSolve[pi[x, y], pei][[2]]*nu2[x, y][[2]]*
Exp[I*slu[x, y][[2]]*d])]*(Dt[
LinearSolve[pi[x, y], pei][[1]]*nu1[x, y][[2]]*
Exp[I*slu[x, y][[1]]*d] +
LinearSolve[pi[x, y], pei][[2]]*nu2[x, y][[2]]*
Exp[I*slu[x, y][[2]]*d], d]) /. d -> 2*10^(-9)];
Guu := NIntegrate[ku*Sin[x]*Tuu[x, y], {x, 0, Pi/2}, {y, 0, Pi/4}];
Guu



LinearSolveshould probably not be evaluated until the matrix-vector arguments are completely numeric. But you cannot control that with the way your code is written. – Michael E2 Aug 12 '18 at 14:27NumericQ: TryTuu[x_?NumericQ, y_?NumericQ] := ...-- You may want to add it to any other function that might get called at the "top level" (likeTuugets called byNIntegrate) and which requiresxandyto be numbers for them to work without errors. – Michael E2 Aug 13 '18 at 11:05