2
$\begingroup$

I'm trying to solve a differential equation as in the following code:

FullSimplify[DSolve[x'[t] == a + b E^(g t) + (c + d E^(-g t)) x[t], x[t], t]]

which generates

enter image description here

Now, I would like to plot it with specific parameter values assigned, for example: a = 1; b = 2; c = 3; d = 4; g = 0.1; A = 1 where I replaced the integration constant c_1 with A.

Here is my code for plotting x[t]:

a = 1; b = 2; c = 3; d = 4; g = 0.1; A = 1
x[t_] := E^(-((d E^(-g t))/g) + c t) (A + Integrate[E^((d E^(-g K[1]))/g - c K[1]) (a + b E^(g K[1])), {K[1], 1, t}])
Plot[x[t], {t, 1, 10}]

It runs forever. To check whether Mathematica is doing calculations, I tried

x[1]

and it yielded

3.83926*10^-15

which is nice. But when I tried

x[2]

I got

enter image description here

It seems Mathematica cannot compute the integral unless the integration region is $\int_1^1$. Is this because the integrand is too complicated? Is there any way to let Mathematica compute it? Thanks!

$\endgroup$
7
$\begingroup$

It runs forever, since you used := instead of = so it was trying to integrate it each time for each different range of t.

You need to integrate it once (which will take few seconds), and then use the result instead. Much faster now, since when you change t, it will not integrate it again. And changed g = 0.1 to g=1/10 as it is best to use exact numbers with Integrate

Try

ClearAll[t, x]
a = 1; b = 2; c = 3; d = 4; g = 1/10; A = 1;
x[t_] = E^(-((d E^(-g t))/g) + c t) (A + 
     Integrate[
      E^((d E^(-g K[1]))/g - c K[1]) (a + b E^(g K[1])), {K[1], 1, 
       t}]);

Plot[x[t], {t, 1, 3}]

Mathematica graphics

Mathematica graphics

$\endgroup$
  • $\begingroup$ Many thanks, Nasser! It was very helpful! $\endgroup$ – ppp Jul 23 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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