I tried the technique in this question, but that did not work for the solution given by the MWE:

DSolve[{f'[t] + f[t]*g[t] == h[t], f[0] == f0}, {f[t]}, t]

How to teach Mathematica to simplify the solution to $\int_0^t h(s) \exp \left(-\int_s^t g(\tau ) \, d\tau \right) \, ds+f0\exp \left(-\int_0^t g(s) \, ds\right)$


1 Answer 1


Via TransformationFunctions:

xf[e_] := 
  e /. {Integrate[int_, {x_, a_, b_}] - Integrate[int_, {x_, a_, c_}] :>
          Integrate[int, {x, c, b}],
        coeff_ Integrate[int_, {x_, a_, b_}] :> 
          Integrate[coeff int, {x, a, b}]};

sol = DSolve[{f'[t] + f[t]*g[t] == h[t], f[0] == f0}, {f[t]}, t];
 TransformationFunctions -> {xf, Expand, Collect[#, Power[E, _]] &, Automatic}]
  {{f[t] -> E^Integrate[-g[K[1]], {K[1], 0, t}] * f0 +
             Integrate[E^Integrate[-g[K[1]], {K[1], K[2], t}]*h[K[2]], {K[2], 0, t}]}}

To get the answer in the form requested (it's not "simpler" according to the default ComplexityFunction of Simplify:

% /. {Integrate[int_, {x_, t, b_}] :> -Integrate[int, {x, b, t}]} /.
      {K[1] -> s, K[2] -> τ}

  {{f[t] -> E^Integrate[-g[s], {s, 0, t}] * f0 + 
           Integrate[E^Integrate[-g[s], {s, τ, t}] * h[τ], {τ, 0, t}]}}
  • 1
    $\begingroup$ Using the code in your first block does not give a very good result because strictly speaking E^Integrate[g[K[1]], {K[1], t, K[2]}] includes the integrate index K[2] and should be included in the last Integrate[h[K[2]], {K[2], 0, t}]. Following your idea, the second replace rule in xf function should be coeff_*Integrate[int_,{x_, a_, b_}] :> Integrate[coeff*int,{x, a, b}] $\endgroup$ Mar 10, 2015 at 20:07
  • 1
    $\begingroup$ @egwenesedai Of course -- and thanks! (Fixed now, I hope.) $\endgroup$
    – Michael E2
    Mar 10, 2015 at 22:27

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.