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,


  • $\begingroup$ 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? $\endgroup$
    – Ymareth
    Commented Jan 21, 2014 at 10:41
  • $\begingroup$ 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. $\endgroup$
    – Frits
    Commented Jan 21, 2014 at 10:59
  • $\begingroup$ Your aH1 argument on LHS is not used on the RHS. The RHS references the global symbol aH. $\endgroup$
    – Ymareth
    Commented Jan 21, 2014 at 11:02
  • $\begingroup$ 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 $\endgroup$
    – Frits
    Commented Jan 21, 2014 at 11:05
  • $\begingroup$ 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. $\endgroup$
    – ciao
    Commented Jan 21, 2014 at 11:05

1 Answer 1


Just create a function whith NIntegrate, and paramters as arguments of the function

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.