1
$\begingroup$

I'm trying to solve a linear ODE with Laplace transformation.

Here is my code :

EqDiff = m*D[x[t], {t, 2}] + c*D[x[t], t] + k*x[t] == f[t]
f[t_] := HeavisideTheta[t] - HeavisideTheta[t - \[Tau]]
(EqLaplace = LaplaceTransform[EqDiff, t, s] /. {x[0] -> 0, 
 x'[0] -> 0}) // TraditionalForm
SolLapX = Solve[EqLaplace, LaplaceTransform[x[t], t, s]]
SolTemx =  InverseLaplaceTransform[SolLapX[[1, 1, 2]], s, t] /. {m -> 1, c -> 2, k -> 3, \[Tau] -> 1}
x[t_] := SolTemx
Plot[x, {t, 0, 10}]

I didn't obtain a plot with Plot function. I suppose that it is due to the fact that the result from the InversLaplaceTransform function is not simplifier and can be analysed as a complex.

Do you have some ideas so as to simplify the result obtained with the InversLaplaceTransform so that i can obtain the plot.

I tried FullSimplify but it didn't work.

$\endgroup$
4
  • $\begingroup$ Try plotting x[t], since that is what you have defined, or Re[x[t]] if necessary $\endgroup$
    – Bill Watts
    Dec 14, 2017 at 8:38
  • $\begingroup$ perfect it works. The only issue is that the plot has some blanks... Some parts of the plot are not plotted, it is like i have some display problems. Do you have an ideas of the cause ? $\endgroup$
    – Bendesarts
    Dec 14, 2017 at 8:59
  • $\begingroup$ but, with the real part the plot is perfect, it may come from numerical approximations $\endgroup$
    – Bendesarts
    Dec 14, 2017 at 9:00
  • $\begingroup$ See my answer. With the ComplexExpand and FullSimplify, you don't even need the Re. The blanks go away also $\endgroup$
    – Bill Watts
    Dec 14, 2017 at 9:09

1 Answer 1

1
$\begingroup$
EqDiff = m*D[x[t], {t, 2}] + c*D[x[t], t] + k*x[t] == f[t];
f[t_] := HeavisideTheta[t] - HeavisideTheta[t - \[Tau]];
(EqLaplace = LaplaceTransform[EqDiff, t, s] /. {x[0] -> 0, x'[0] -> 0});
SolLapX = Solve[EqLaplace, LaplaceTransform[x[t], t, s]];
SolTemx = InverseLaplaceTransform[SolLapX[[1, 1, 2]], s, t] /. {m -> 1, c -> 2, k -> 3, \[Tau] -> 1};
x[t_] = SolTemx // ComplexExpand // FullSimplify;
Plot[Evaluate[x[t]], {t, 0, 10}]

enter image description here

$\endgroup$
2
  • $\begingroup$ great, thank you ! the only point that i didn't understant is why have you used the Evaluate function since you define x[t_]= and not x[t_]:= and consequently the function has already been evaluated $\endgroup$
    – Bendesarts
    Dec 14, 2017 at 9:18
  • $\begingroup$ Evaluate often speeds up plotting, but in this case the plot is simple enough to not notice the difference. $\endgroup$
    – Bill Watts
    Dec 14, 2017 at 9:54

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.