Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
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? –  Ymareth Jan 21 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. –  Frits Jan 21 at 10:59
    
Your aH1 argument on LHS is not used on the RHS. The RHS references the global symbol aH. –  Ymareth Jan 21 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 –  Frits Jan 21 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. –  rasher Jan 21 at 11:05
show 1 more comment

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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