2
$\begingroup$

I want to get the real part of the function n3[t] (see below) which is the solution to a differential equation.

Solve the differential equation. (Suppose m, k, f, and t are real)

Clear["Global`*"]

eqns = {m*n1''[t] + k*n1[t] - k*n2[t] == f*E^(I*w*t), 
   m*n2''[t] - k*n1[t] + 2*k*n2[t] - k*n3[t] == 0, 
   m*n3''[t] - k*n2[t] + k*n3[t] == 0, n1[0] == 0, n2[0] == 0, 
   n3[0] == 0, n1'[0] == 0, n2'[0] == 0, n3'[0] == 0};

(sol = DSolve[eqns, {n1, n2, n3}, t]) // Short[#, 5] &

Simplify the solution

solt = {n1[t], n2[t], n3[t]} /. sol // FullSimplify

I got enter image description here

Then I tried to get the real part of n3[t] with ComplexExpand[], but I failed. It seems that m and k are also regarded as complex numbers. (The output is actually very long, I omit the rest of it) enter image description here

I failed to get the real part of n3[t] directly with Re[] either.

$\endgroup$

1 Answer 1

6
$\begingroup$

First, try this:

expr = ExpandAll[solt][[1]];

And then the following:

Refine[ComplexExpand[Re[expr]], Assumptions -> {f > 0, k > 0, m > 0, t > 0, w > 0}] // Simplify

enter image description here

$\endgroup$
4
  • $\begingroup$ Thank you! I ran your codes and it works. But could you explain why your codes succeed by using ComplexExpand and Re together, while I failed when I used either ComplexExpand or Re alone? $\endgroup$ Commented Jan 21, 2023 at 23:00
  • $\begingroup$ I also tried ComplexExpand[Re[expr]] // Simplify but it took my computer too much time to run this code. But why does Refine make such a big difference that it doesn't take the computer a lot of time to run Refine[ComplexExpand[Re[expr]], Assumptions -> {f > 0, k > 0, m > 0, t > 0, w > 0}] // Simplify? $\endgroup$ Commented Jan 21, 2023 at 23:05
  • $\begingroup$ Besides, I am sorry for my late reply. I was really busy with other things in the past few weeks. $\endgroup$ Commented Jan 21, 2023 at 23:07
  • 1
    $\begingroup$ Sorry, I forgot to accept your answer half a year ago because I didn't know how to use stack exchange at that time. $\endgroup$ Commented Jul 15, 2023 at 1:22

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.