I need to numerically differentiate a function that takes a list as an argument and that uses NIntegrate in its definition. A simple example is
Needs["NumericalCalculus`"] f[x_] := NIntegrate[Cos[(x[[1]] + x[[2]]) y], {y, 0, 1}]; ND[f[{1, 0} x], x, 1] which returns the non-numerical value warning. I tried
f[x_?NUmericQ] := NIntegrate[Cos[(x[[1]] + x[[2]]) y], {y, 0, 1}]; but this does not evaluate either. Any ideas?
EDIT IN RESPONSE TO ANSWER
What if f is redefined as
f[x_, u_] := NIntegrate[Cos[(x[[1]] + x[[2]] + u) y], {y, 0, 1}]; where u is a scalar and we wish to evaluate expressions like
ND[f[{1, 0} x, 3], x, 1] and
ND[f[{1, 1}, u], u, 1] I tried:
f[x_, u_] /; VectorQ[x, NumericQ] && NumericQ[u] := NIntegrate[Cos[(x[[1]] + x[[2]] + u) y], {y, 0, 1}]
f[x_?(VectorQ[#, NumericQ]&), u?NumericQ] := ...if you want $x$ to be a vector of numerical quantities, and $u$ a numerical scalar. But then if everything is numerical,fwill simply return a scalar, so what shouldNDdo with that then? $\endgroup$