Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
I do not think DSolve uses/accepts user assumptions. This was my understanding all along. Unless something changed in newer version of M. –  Nasser Oct 20 '14 at 8:22
@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. –  Michael E2 Oct 20 '14 at 20:21

3 Answers 3

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}]}]
share|improve this answer
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. –  bbgodfrey Nov 19 '14 at 14:24
@bbgodfrey yes, thank you! This is fixed now. –  Chip Hurst Nov 19 '14 at 17:53
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. –  bbgodfrey Nov 19 '14 at 19:29

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]);


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
share|improve this answer
You might be interested in my answer. –  Michael E2 Nov 20 '14 at 16:58

For what it's worth, using the same substitution as Chip Hurst in his Apr 22 answer, and after some coaxing, I 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 solution. Maybe it will occur to me, but the darn crashing and long times to simplify are discouraging. Sorry.

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];

(* missing step fubar = h[Cos[x]] /. solu // ??? *)

solx = Function @@ {x, fubar /. Abs[m] -> Sqrt[m^2]}
(* same as above *)


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

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.

share|improve this answer
Very nice! I have no idea why my ODE didn't solve with DSolve since it works for me in V9 and V10 today. –  Chip Hurst Nov 20 '14 at 20:50
@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. –  Michael E2 Nov 21 '14 at 1:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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