2
$\begingroup$

I am trying to solve a linear second order ODE using DSolve which involves an arbitrary integer m. DSolve gives me a solution when I set m to a particular integer (I have tried several, including negative/positive, even/odd, and 0). When I try to use the assumption m ∈ Integers and ask DSolve to solve this ODE for an arbitrary integer m, it does not work. Here is the input:

$Assumptions = m ∈ Integers
testk = 
  0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3x]) k'[x] 
       + Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m) + 4 c k''[x])

DSolve[ testk, k[x], x]
DSolve[ 0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3 x]) k'[x] 
              + Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m)
              + 4 c k''[x], k[x], x]

Update: I have realized that the problem is that DSolve does not apply any of the global assumptions. Does anyone know how I can make DSolve apply the assumption that m ∈ Integers? I have tried using Assuming[,] to set the assumptions locally but that did not work either.

$\endgroup$
2
  • $\begingroup$ I do not think DSolve uses/accepts user assumptions. This was my understanding all along. Unless something changed in newer version of M. $\endgroup$
    – Nasser
    Commented Oct 20, 2014 at 8:22
  • $\begingroup$ @Nasser Functions called by DSolve use $Assumptions (Simplify, Refine, Integrate etc.), but otherwise I don't think DSolve uses it. I think DSolve gets stuck trying to figure out how to reduce the problem to integrals. $\endgroup$
    – Michael E2
    Commented Oct 20, 2014 at 20:21

4 Answers 4

2
$\begingroup$

I think I have solved this ODE (I didn't verify the solution). The problem with DSolve is Integrate was not terminating for this inhomogeneous equation.

So what I did was solve the homogeneous equation, then applied variation of parameters described here:

homode = -16c*m^2Cos[x]k[x] - c(Sin[3x] - 7Sin[x])k'[x] + 4c*Cos[x]Sin[x]^2k''[x] == 0;

homsol = First[k[x] /. DSolve[homode, k[x], x]];

u1 = homsol /. {C[1] -> 1, C[2] -> 0};
u2 = homsol /. {C[1] -> 0, C[2] -> 1};

f = m^2(3 + 4m Cos[x] + Cos[2x])Tan[x/2]^(2m)Cos[x]Sin[x]^2/(4c*Cos[x] Sin[x]^2);

W = Wronskian[homode, k, x];

A = -HoldForm[Integrate[#, x]]&[u2*f/W];
B = HoldForm[Integrate[#, x]]&[u1*f/W];

TraditionalForm[k[x] == u1 C[1] + u2 C[2] + A u1 + B u2]

enter image description here

--- Edit ---

I have verified this solution is correct and I thought I'd share because this is the first time I've found a real use for Inactive over Hold... exciting!

So instead of using HoldForm to hold A and B, I use Inactivate:

A = Inactivate[-Integrate[u2*f/W, x], Integrate];
B = Inactivate[Integrate[u1*f/W, x], Integrate];

final = u1 C[1] + u2 C[2] + A u1 + B u2;

FullSimplify[testk /. {k[x] -> final, k'[x] -> D[final, x], k''[x] -> D[final, {x, 2}]}]
True
$\endgroup$
3
  • 1
    $\begingroup$ By substitution, I have verified that this solution by @Chip Hurst is formally correct, although I believe that t should be replaced by x in the definitions of A and B. $\endgroup$
    – bbgodfrey
    Commented Nov 19, 2014 at 14:24
  • $\begingroup$ @bbgodfrey yes, thank you! This is fixed now. $\endgroup$
    – Greg Hurst
    Commented Nov 19, 2014 at 17:53
  • $\begingroup$ very nice use of Inactivate, which I had not seen before. Allows a much simpler method to verify correctness of solution than the method I used. By the way, assuming m>0 and running Simplify on the solution gives a somewhat simpler answer. $\endgroup$
    – bbgodfrey
    Commented Nov 19, 2014 at 19:29
2
$\begingroup$

Update: I thought I would check this out in V10.1. I found no difference in DSolve, but I was able to an answer relatively quickly (compare with my original attempt). It's in a different form than the original, but it's equivalent.

Using the same substitution as Chip Hurst in his Apr 22 answer, and after some coaxing, I got to this solution:

testk = 0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3 x]) k'[x] + 
    Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m) + 
       4 c k''[x]);
ode = testk /. x -> x[u] /. 
       First@Solve[{h'[u] == D[k[x[u]], u], 
          h''[u] == D[k[x[u]], u, u]}, {k'[x[u]], k''[x[u]]}] /. 
      k[x[u]] -> h[u] /. x -> ArcCos /. 
    Tan[ArcCos[u]/2]^a_ :> ((1 - u)/(1 + u))^(a/2) // FullSimplify;

solu = DSolve[ode, h, u];

Assuming[m ∈ Integers && m >= 0,
  fubar = Simplify[h[Cos[x]] /. First@solu] /. 
     Exp[A__*ArcTanh[Cos[x]]] :>
       Simplify[ExpToTrig[Simplify[TrigToExp[E^(A ArcTanh[Cos[x]])]]]] // 
    Simplify
  ];

solx = Function @@ {x, fubar}
(*
  Function[x, (1/(8 c m (-1 + 4 m^2))) * 
   (m^3 (-((-1 + Cos[x])^2/(1 + Cos[x])))^m *
      (1 + 4 m^2 + 4 m Cos[x] + (-1 + 4 m^2) Cos[2 x]) + 
    4 c (-1 + Cos[x])^m * 
      ((-1 + 4 m^2) C[1] - m C[2] + 2 m ((-1 + 4 m^2) C[1] + m C[2]) Cos[x]) * 
      Cosh[m (Log[1 + Cos[x]] - Log[2 Sin[x/2]^2])] - 
    4 c (-1 + Cos[x])^m * 
      ((-1 + 4 m^2) * C[1] + m C[2] + 2 m ((-1 + 4 m^2) C[1] - m C[2]) Cos[x]) * 
      Sinh[m (Log[1 + Cos[x]] - Log[2 Sin[x/2]^2])])]
*)

Check:

Assuming[m ∈ Integers,
 testk /. k -> solx // FullSimplify
 ]
(*  True  *)

Original solution found

For what it's worth, using the same substitution as Chip Hurst in his Apr 22 answer, and after some coaxing, I originally got to this solution:

solx = Function[x, 
  1/(4 Sqrt[
    m^2]) (2 C[1] (1 + 2 Sqrt[m^2] Cos[x]) Cot[x/2]^(-2 Sqrt[m^2]) - (
     2 C[2] (Sqrt[m^2] - 2 m^2 Cos[x]) Cot[x/2]^(2 Sqrt[m^2]))/(-1 + 
      4 m^2) + ((m^2)^(
      3/2) (1 + 2 m Cos[x] + (-1 + 4 m^2) Cos[x]^2) Tan[x/2]^(2 m))/(
     c (-1 + 4 m^2)))]

Unfortunately, crashes, trying different things, memory leaks or something messing up Simplify and FullSimplify or other confusing behavior, plus stupidly copying and saving the wrong step means there is one step missing in the path to the solution.

Check:

testk /. k -> solx // Simplify
(*  True  *)

[It is arguably a simpler solution, but I did not discover a way to transform the new solution to this one.]

One of the problems is that applying the assumption that m is an integer causes different things to happen under the hood in simplification. But some simplifications are valid whether m is an integer or not. The following example shows that an early application of the assumption slows things down quite a bit. Simplifications are usually done under time constraints, which may lead to failure.

ode /. First@solu // 
  Simplify[#, m ∈ Integers && u ∈ Reals] & // AbsoluteTiming
(*  {17.843582, True} *)

ode /. First@solu // Simplify // 
  Simplify[#, m ∈ Integers && u ∈ Reals] & // AbsoluteTiming
(*  {7.273103, True}  *)

It is a sheer guess that this has something to do with the problem.

$\endgroup$
3
  • $\begingroup$ Very nice! I have no idea why my ODE didn't solve with DSolve since it works for me in V9 and V10 today. $\endgroup$
    – Greg Hurst
    Commented Nov 20, 2014 at 20:50
  • 1
    $\begingroup$ @ChipHurst If you throw in the assumption Element[m, Integers] with DSolve (with Assuming, say), DSolve runs longer than I'm willing to wait. That may be the difference between now and before. $\endgroup$
    – Michael E2
    Commented Nov 21, 2014 at 1:04
  • $\begingroup$ Hello, in version 14.0, the code runs for a long time without producing any results. I'm not sure what the reason is. $\endgroup$
    – lotus2019
    Commented Aug 14 at 0:40
1
$\begingroup$

Not sure if this will help, but you can transform your ODE to have rational coefficients by subbing $t = \cos x$, which gives

$k'(x)=-\sqrt{1-t^2} k'(t), \quad k''(x)=(1-t^2)k''(t)-t k'(t), \;\; \text{ and } \;\; x=\cos ^{-1}(t)$:

testk=-16 c m^2 Cos[x] k[x]-c (-7 Sin[x]+Sin[3x]) k'[x]+Cos[x] Sin[x]^2 (m^2 (3+4 m Cos[x]+Cos[2 x]) Tan[x/2]^(2 m)+4 c k''[x]);

$fromTrig={k'[x]:>(-Sqrt[1-t^2])*k'[t],k[x]->k[t],k''[x]->-t*k'[t]+k''[t]-t^2*k''[t],x->ArcCos[t]};

simped = Simplify[FunctionExpand[testk/.$fromTrig],-1<t<1&&m\[Element]Integers];

Collect[(1+t)^m PowerExpand[simped], {k[t],k'[t],k''[t]}]==0
-2 m^2 (1-t)^m t (-1+t^2) (1+2 m t+t^2)-16 c m^2 t (1+t)^m k[t] + 
  8 c (1+t)^m (-1+t^2) k'[t]+4 c t (1+t)^m (-1+t^2)^2 k''[t] == 0
$\endgroup$
1
  • $\begingroup$ You might be interested in my answer. $\endgroup$
    – Michael E2
    Commented Nov 20, 2014 at 16:58
1
$\begingroup$

Update for V13.1

I thought @Steven_Huang was using V13, but apparently not or not interested in posting this V13 solution. Now DSolve[testk, k[x], x] returns a somewhat long answer without assumptions. Here's what DSolve[] gives now with assumptions and simplifying:

testk = 0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3 x]) k'[x] + 
    Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m) + 
       4 c k''[x]);

Assuming[
 m ∈ Integers && m > 0 && -Pi < x < Pi,
 sol = DSolve[testk, k[x], x] // FullSimplify
 ]
(*
{{k[x] -> (E^(I x) (-1 + E^(I x))^(-4 m) (4 (64^
            m m^2 (1 + m Cos[x]) (-1 + 
              2 m Cos[x]) ((I + Cot[x]) Sin[x/2]^4)^(2 m) Sin[x]^2 + 
           4 c Cos[x] ((1 + E^(I x))^(4 m) m C[2] (-1 + 2 m Cos[x]) + 
              2 (-1 + E^(I x))^(4 m) (-1 + 4 m^2) C[1] *
               (1 + 2 m Cos[x])) (I Tan[x/2])^(2 m)) +
         (-1 + E^(I x))^(4 m) m^2 (1 + 2 m Cos[x]) (2 + 8 m^2 + 
           2 (-1 + 4 m^2 + m Cos[x]) Cos[2 x]) Tan[x/2]^(2 m))) /
            (16 c (1 + E^(2 I x)) m (-1 + 4 m^2))}}
*)

Since the ODE and the generic solution returned by DSolve[testk, k[x], x] are both periodic of period 2 Pi, restricting the domain to -Pi < x < Pi yields a general solution valid over its domain by periodicity.

$\endgroup$

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.