2
$\begingroup$

enter image description here

I have no idea how to speed this up. Does maple do a better job at solving this?

$\endgroup$
  • 1
    $\begingroup$ The code in the question runs immediately if you add Assumptions -> k/m > 0 to DSolve $\endgroup$ – Coolwater Nov 25 '17 at 20:56
  • $\begingroup$ @Coolwater nice observation. M was stuck integrating this, since it was under sqrt and by saying k/m>0 bypasses possibility of complex numbers. $\endgroup$ – Nasser Nov 25 '17 at 21:01
5
$\begingroup$

I do not know what you mean here. When I run (with $\omega=\sqrt{k/m}$):

DSolve[{y''[t] + \[Omega]^2 y[t] == 1/m Sin[\[Omega] t], 
y'[0] == 1, y[0] == 0}, y, t]

MMA (ver 11.2, macOS 10.13.1) provides this quite fast:

$\text{Function}\left[\{t\},\frac{4 m \omega \sin (t \omega )+2 \sin (t \omega )-2 t \omega \cos (t \omega )-2 \sin (t \omega ) \cos ^2(t \omega )+\sin (2 t \omega ) \cos (t \omega )}{4 m \omega ^2}\right]$

am I missing something?

$\endgroup$
  • 2
    $\begingroup$ You are not missing anything. It is the sqrt which makes M not able to integrate it. Mathematica does not know vibration theory, so it did not know that natural frequency is sqrt(k/m). It is stuck trying to evaluate the integral with sqrt in it. Using w^2=k/m bypass this whole issue. Good workaround btw. $\endgroup$ – Nasser Nov 25 '17 at 20:58
3
$\begingroup$

It seems the problem is that Mathematica is having hard time doing the integration when finding the particular solution. Using answer here, you can see those integrals in the particular solution.

odeH = m*y''[t] + k y[t];
rhs = Sin[Sqrt[k/m] t];
{yh, yp} = hAndp[odeH, rhs, y, t];
solution = yh + yp

Mathematica graphics

You can see these integrals are not evaluated, and I think this is where Mathematica is stuck.

Rubi can solve these, giving

int1=Int[Cos[(Sqrt[k] t)/Sqrt[m]] Sin[Sqrt[k/m] t],t];
int1E=(Limit[int1,t->z]-Limit[int1,t->0]);
int1E=int1E/.z->t

Mathematica graphics

int2=Int[Sin[Sqrt[k/m] t] Sin[(Sqrt[k] t)/Sqrt[m]],t];
int2E=(Limit[int2,t->z]-Limit[int2,t->0]);
int2E=int2E/.z->t

Mathematica graphics

Now you have the full solution after plugging the above

C[1]*Cos[(Sqrt[k]*t)/Sqrt[m]] + C[2]*Sin[(Sqrt[k]*t)/Sqrt[m]] + 
  ((-Cos[(Sqrt[k]*t)/Sqrt[m]])*(Sin[(Sqrt[k/m] - Sqrt[k]/Sqrt[m])*t]/(2*(Sqrt[k/m] - Sqrt[k]/Sqrt[m])) - 
      Sin[(Sqrt[k/m] + Sqrt[k]/Sqrt[m])*t]/(2*(Sqrt[k/m] + Sqrt[k]/Sqrt[m]))) + 
    (1/(2*(Sqrt[k/m] - Sqrt[k]/Sqrt[m])) + 1/(2*(Sqrt[k/m] + Sqrt[k]/Sqrt[m])) - Cos[(Sqrt[k/m] - Sqrt[k]/Sqrt[m])*t]/
       (2*(Sqrt[k/m] - Sqrt[k]/Sqrt[m])) - Cos[(Sqrt[k/m] + Sqrt[k]/Sqrt[m])*t]/(2*(Sqrt[k/m] + Sqrt[k]/Sqrt[m])))*
     Sin[(Sqrt[k]*t)/Sqrt[m]])/(Sqrt[k]*Sqrt[m])

Now you can find C[1] and C[2] from initial conditions.

Btw, Here is Maple solution, which matches what I have above

Mathematica graphics

Update

To see where DSolve was stuck, one can use this trace method (thanks to Michael E2) shown here how-does-mathematica-solve-a-certain-differential-equation

ClearAll[y,t,m,k]
ode=m y''[t]+ k y[t]==Sin[Sqrt[k/m] t];
ic={y[0]==0,y'[0]==1};
Block[{DSolve`print=Print},
Trace[DSolve[{ode,ic},y[t],t],_Integrate,
TraceInternal->True]
]

This shows it is stuck at this line

Mathematica graphics

Here is full output

Mathematica graphics

$\endgroup$

Your Answer

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