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 need to define a function $k(t,c_1,\alpha_1,c_2,\alpha_2)$ in the following manner:

Clear[c1, c2, a1, a2, p1, p2, q, Q] (*clearing symbol assertions - just in case*)
p1[t_, c1_, a1_] := c1 (1 - E^(-a1*t)) 
p2[t_, c2_, a2_] := c2 (1 - E^(-a2*t)) 
q[t_, c1_, a1_, c2_, a2_] := p1[t, c1, a1] + p2[t, c2, a2]
Q[s_, c1_, a1_, c2_, a2_] := 
  FullSimplify[ LaplaceTransform[ q[t, c1, a1, c2, a2], t, s]]
k[t_, c1_, a1_, c2_, a2_] := 
  FullSimplify[ 
    InverseLaplaceTransform[ 2s^2 Q[s, c1, a1, c2, a2]/(1 - 2s Q[s, c1, a1, c2, a2]),
                              s, t]]

Now, if I execute the following code:

cmax := 1
amax := 1
tmax := 10
Manipulate[ k[t, c1, a1, c2, a2], 
            {t, 0, tmax}, {c1, 0, cmax}, {a1, 0, amax}, 
            {c2, 0, cmax}, {a2, 0, amax}]

Mathematica produces proper output, in a way that a concrete numerical value is returned. However, if I execute

 Manipulate[ Plot[k[t, c1, a1, c2, a2], {t, 0, tmax}], 
             {c1, 0, cmax}, {a1, 0, amax}, {c2, 0, cmax}, {a2, 0, amax}]

then I get no result - only plot axes are printed, regardless of the parameters or plot range. Interestingly, if in the last expression explicit form of $k$ is inserted, everything works perfectly. What do I do wrong?

share|improve this question

closed as off-topic by rasher, Artes, m_goldberg, Michael E2, belisarius Apr 6 at 20:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – rasher, Artes, m_goldberg, Michael E2, belisarius
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Try Evaluate@k –  esprit Apr 6 at 9:45
    
I wouldn't use := in the definition of k. This causes the simplification and invers Laplace transform to be calculated for every call of k. Use = instead. –  Sjoerd C. de Vries Apr 6 at 11:53

1 Answer 1

up vote 0 down vote accepted

putting all comments together

p1[t_, c1_, a1_] := c1 (1 - E^(-a1*t))
p2[t_, c2_, a2_] := c2 (1 - E^(-a2*t))
q[t_, c1_, a1_, c2_, a2_] := p1[t, c1, a1] + p2[t, c2, a2]
Q[s_, c1_, a1_, c2_, a2_] := 
  FullSimplify[LaplaceTransform[q[t, c1, a1, c2, a2], t, s]]
k[t_, c1_, a1_, c2_, a2_] = 
FullSimplify[InverseLaplaceTransform[
2 s^2 Q[s, c1, a1, c2, a2]/(1 - 2 s Q[s, c1, a1, c2, a2]), s, t]]

and then

cmax = 1;amax = 1;tmax = 10
Manipulate[Plot[k[t, c1, a1, c2, a2], {t, 0, tmax}], {c1, 0, cmax}, {a1, 0, amax},
{c2, 0, cmax}, {a2, 0, amax}]

yields

image

share|improve this answer

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