# How to use NIntegrate in a function using parameters from a list

I would like to use NIntegrate in a function with some parameters from a list. I simplified my problem for this forum. The list of parameters is as follows:

aH = {aH1, aH2};
pars = {aH1 -> 2., aH2 -> 3.};


Normal integration works fine. The next function gives numerical output for numerical values of t and T.

f[t_, T_, k_Integer]:=Exp[-Integrate[aH[[k]],{u,t,T}]]


Now I would like to define the function using NIntegrate

f[t_?NumericQ, T_?NumericQ, k_Integer, aH1_?NumericQ] := Exp[-NIntegrate[aH[[k]], {u, t, T}]]


Unfortunately, this does not give numerical output when trying to evaluate by:

f[0., 1., 1, 2.]


Does anyone know how to solve this? Your help is much appreciated.

Best regards,

Frits

• In your last definition there is aH1 (which must be a NumericQ not a list) on the LHS and aH (which is by implication a list) on the RHS? What is u in this context? Jan 21, 2014 at 10:41
• Well, actually I meant to write it this way. The reason being that in my actual problem there are summations over multiple indices of k. Jan 21, 2014 at 10:59
• Your aH1 argument on LHS is not used on the RHS. The RHS references the global symbol aH. Jan 21, 2014 at 11:02
• When I enter Evaluate at two places, I do get a correct answer: f[t_?NumericQ, T_?NumericQ, k_Integer, aH1_?NumericQ] := Exp[-NIntegrate[aH[[k]] // Evaluate, {u, t, T}]] // Evaluate Jan 21, 2014 at 11:05
• I too am puzzled by the example, perhaps something got lost in translation to 'simplified'. e.g., where does pars come into play? OP, is aH supposed to be some index into a set of functions on u? If so, just make a list assigned to aH and index into it as required.
– ciao
Jan 21, 2014 at 11:05

f[t_?NumericQ, T_?NumericQ, aH1_?NumericQ] := Exp[-NIntegrate[aH1, {u, t, T}]]